kaban
Topic Author
Posts: 17
Joined: 22 Sep 2013, 09:35

Unity3D click callbacks?

22 Sep 2013, 09:52

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?
 
Mikael Gyth
Posts: 33
Joined: 15 Aug 2013, 12:53

Re: Unity3D click callbacks?

22 Sep 2013, 10:59

Assume you have a button like this:
<Grid>
    <Button Name="ButtonOne"/>
</Grid>
If you then create a C# script on the same object you have the NoesisPanel Attached to (Main Camera)
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
    }
}
That should do it, sorry about the poor code formatting.
Last edited by sfernandez on 23 Sep 2013, 09:43, edited 1 time in total.
Reason: Code formatted for better visualization
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Unity3D click callbacks?

23 Sep 2013, 10:08

It's great to see users helping each others :D

Thanks Mikael for your contribution, it was a simple and perfect example on how to add handlers to UI element events.
 
User avatar
jsantos
Site Admin
Posts: 3907
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity3D click callbacks?

23 Sep 2013, 13:22

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?
Did you read the Unity tutorial? It is the first one, in the Unity section.
 
kaban
Topic Author
Posts: 17
Joined: 22 Sep 2013, 09:35

Re: Unity3D click callbacks?

23 Sep 2013, 14:39

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?
Did you read the Unity tutorial? It is the first one, in the Unity section.
Ah no I didn't see it :oops:

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:
<Button Click="OnClick"/>
With an OnClick function in the code behind representing it?

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.
 
User avatar
jsantos
Site Admin
Posts: 3907
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity3D click callbacks?

24 Sep 2013, 17:15

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?
 
kaban
Topic Author
Posts: 17
Joined: 22 Sep 2013, 09:35

Re: Unity3D click callbacks?

26 Sep 2013, 06:51

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?
done!
 
User avatar
jsantos
Site Admin
Posts: 3907
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity3D click callbacks?

26 Sep 2013, 13:50

Thanks!

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests