Unity3D click callbacks?
Hi There,
I've been toying around with Noesis for a bit now but I don't understand how to get it to give Unity3D callbacks when things happen (such as when a button is clicked).
The tutorials which came with noesis seems to focus on C++ and not any sort of unity C# interface? How can I make this work?
I've been toying around with Noesis for a bit now but I don't understand how to get it to give Unity3D callbacks when things happen (such as when a button is clicked).
The tutorials which came with noesis seems to focus on C++ and not any sort of unity C# interface? How can I make this work?
- Mikael Gyth
- Posts: 33
- Joined:
Re: Unity3D click callbacks?
Assume you have a button like this:
If you then create a C# script on the same object you have the NoesisPanel Attached to (Main Camera)
That should do it, sorry about the poor code formatting.
Code: Select all
<Grid>
<Button Name="ButtonOne"/>
</Grid>
Code: Select all
public class CodeBehind : MonoBehaviour
{
private Button _button;
private void Start()
{
// get the Noesis component
var noesisGui = GetComponent<NoesisGUIPanel>();
// get the root object (grid)
var grid = _noesisGui.GetRoot<Grid>();
// get the button
_button = grid.FindName<Button>("ButtonOne");
// attach a delegate method
_button.Click += ButtonOneClick;
}
private void ButtonOneClick(BaseComponent sender, RoutedEventArgs args)
{
// do stuff
}
}
Last edited by sfernandez on 23 Sep 2013, 09:43, edited 1 time in total.
Reason: Code formatted for better visualization
Reason: Code formatted for better visualization
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: Unity3D click callbacks?
It's great to see users helping each others
Thanks Mikael for your contribution, it was a simple and perfect example on how to add handlers to UI element events.
Thanks Mikael for your contribution, it was a simple and perfect example on how to add handlers to UI element events.
Re: Unity3D click callbacks?
Did you read the Unity tutorial? It is the first one, in the Unity section.The tutorials which came with noesis seems to focus on C++ and not any sort of unity C# interface? How can I make this work?
Re: Unity3D click callbacks?
Ah no I didn't see itDid you read the Unity tutorial? It is the first one, in the Unity section.The tutorials which came with noesis seems to focus on C++ and not any sort of unity C# interface? How can I make this work?
Out of curiosity I was wondering, is it at all possible/will there ever be a feature to get click callbacks in codebehind by definining them in XAML? Like:
Code: Select all
<Button Click="OnClick"/>
I ask because I think from a design standpoint this would be ideal, so a designer could create the UI and help the programmer understand what he wants.
Re: Unity3D click callbacks?
Yes, it is planned. Although from a point of view of MVVM philosphy, code-behind classes generate dependencies between xaml and code. But yes, we have that feature working in C++, should be ported to Unity.
Could you please file a bug?
Could you please file a bug?
Re: Unity3D click callbacks?
done!Yes, it is planned. Although from a point of view of MVVM philosphy, code-behind classes generate dependencies between xaml and code. But yes, we have that feature working in C++, should be ported to Unity.
Could you please file a bug?
Re: Unity3D click callbacks?
Thanks!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests