paevensonKratos
Topic Author
Posts: 9
Joined: 11 Mar 2014, 20:24

Invoke function in custom control from Unity

26 Mar 2014, 19:16

How would I get the object reference of a custom control from Unity? I was hoping to get it through the NoesisGUIPanel....but I couldn't find it.

for example:
[Noesis.Extended]
[Noesis.UserControlSource("Assets/GUI/CameraControl.xaml")]
public class CameraControlGUI : Noesis.UserControl
{
 public void CallMeFromUnity() {}
}
using UnityEngine;
using System.Collections;
using Noesis;
public class NoesisGuiUpdater : MonoBehaviour {
	NoesisGUIPanel noesisGUI = null;
	// Use this for initialization
	void Awake () 
	{
		// Access to the NoesisGUI component
		noesisGUI = GetComponent<NoesisGUIPanel>();				
	}
	
	// Update is called once per frame
	void Update () {
		//TODO:Call my Function! >_<
		//noesisGUI.CallMeFromUnity();
	}
}
Thanks!

-Paul
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Invoke function in custom control from Unity

27 Mar 2014, 12:09

Hi Paul,

When you want to interact with some elements of the xaml from code, you have to provide a name, so you can find them (every named element gets registered against the NameScope of the root element of the xaml). For example, given the following xaml attached to a NoesisGUIPanel:
<Grid
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    ...
    <CameraControlGUI x:Name="CameraControl" .../>
    ...
</Grid>
You can then access to the camera control from your mono behavior like this:
using UnityEngine;
using System.Collections;
using Noesis;

public class NoesisGuiUpdater : MonoBehaviour {

   CameraControlGUI cameraControl = null;

   void Awake () {
      var gui = GetComponent<NoesisGUIPanel>();
      var root = gui.GetRoot<FrameworkElement>();
      cameraControl = root.FindName<CameraControlGUI>("CameraControl");
   }
   
   void Update () {
      cameraControl.CallMeFromUnity();
   }
}
Is this what you need?
 
paevensonKratos
Topic Author
Posts: 9
Joined: 11 Mar 2014, 20:24

Re: Invoke function in custom control from Unity

27 Mar 2014, 12:31

Is this what you need?
Yes! Perfect! Thanks!

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 25 guests