-
- paevensonKratos
- Posts: 9
- Joined:
Invoke function in custom control from Unity
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:
Thanks!
-Paul
for example:
Code: Select all
[Noesis.Extended]
[Noesis.UserControlSource("Assets/GUI/CameraControl.xaml")]
public class CameraControlGUI : Noesis.UserControl
{
public void CallMeFromUnity() {}
}
Code: Select all
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();
}
}
-Paul
-
-
sfernandez
Site Admin
- Posts: 3222
- Joined:
Re: Invoke function in custom control from Unity
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:
You can then access to the camera control from your mono behavior like this:
Is this what you need?
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:
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
...
<CameraControlGUI x:Name="CameraControl" .../>
...
</Grid>
Code: Select all
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();
}
}
-
- paevensonKratos
- Posts: 9
- Joined:
Re: Invoke function in custom control from Unity
Yes! Perfect! Thanks!Is this what you need?
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest