User avatar
Erio
Topic Author
Posts: 81
Joined: 06 Feb 2013, 17:30
Location: Orléans/France

[Unity] Inheriting NoesisGUIPanel

19 Jan 2016, 00:28

Hey guys,

It's been quite a long time since my last passage on the forum, I've been busy with a lot of other things :x


I am now working on Unity and would like to know if it was possible to inherit the NoesisGUIPanel or anything else to create a script that would be itself a NoesisGUIPanel but a specialized one with the events and its actions already registered in itself.

Currently, if I try to inherit NoesisGUIPanel, in the Editor's Inspector, I can see two fields that do not show up normally in the NoesisGUIPanel, those fields are strings named XamlFile and StyleFile. If I do not enter manually the path to the xaml file, it does not work, even when dragging the xaml file in the Xaml field.

Any idea on that particular question? :)

Noesis and XAML for the win <3

Thanks, Erio
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: [Unity] Inheriting NoesisGUIPanel

19 Jan 2016, 06:20

Welcome back Erio :)

These fields are calculated from the corresponding Xaml and Style fields using a custom inspector editor (NoesisGUIPanelEditor) we provide. If you inherit from NoesisGUIPanel, you should probably create a copy of that custom editor for your class, so inspector can be shown as usual.

Another alternative is to create a base class for all your UserControls that does these automatic event registrations.

Anyway, we have plans for a future release to do something similar to WPF and generate an extra .cs file with the x:Name fields defined and the code-behind connections for events and delegates already done.
 
User avatar
Erio
Topic Author
Posts: 81
Joined: 06 Feb 2013, 17:30
Location: Orléans/France

Re: [Unity] Inheriting NoesisGUIPanel

19 Jan 2016, 18:51

Thanks sfernandez :D

What would be the best way to proceed, to create a private variable of type NoesisGUIPanelEditor in my class?

I think that I will do a base-class that does this automatic inspector setup and then derive from it, it might help :)

I really can't wait for the moment we will be able to use them WPF-like with the x:Name fields and code-behind, that will make the setup of Xamls much easier :)

As of now, the only way I found to make some events that correctly interact with the script that defines the events is to make itself a NoesisGUIPanel, if I made it a MonoBehaviour and tried to get the NoesisGUIPanel from the script, I would get a null reference exception when trying to access it from within my delegates, which did not fit me quite well :P

Thanks for your answer, if you can guide me a little bit more about this inspector setup, I would be thankful.
If I find a solution before that that works, I will post it here, might help some other people :)

Erio
 
User avatar
Erio
Topic Author
Posts: 81
Joined: 06 Feb 2013, 17:30
Location: Orléans/France

Re: [Unity] Inheriting NoesisGUIPanel

19 Jan 2016, 19:15

Hm. In fact, after looking through the classes, I could not find the NoesisGUIPanelEditor.. :P
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Inheriting NoesisGUIPanel

20 Jan 2016, 01:08

Hey guys,
I am now working on Unity and would like to know if it was possible to inherit the NoesisGUIPanel or anything else to create a script that would be itself a NoesisGUIPanel but a specialized one with the events and its actions already registered in itself.
This doesn't seem to be a good idea. Instead of inheriting, why don't you create a new component and do all the needed stuff there?
 
User avatar
Erio
Topic Author
Posts: 81
Joined: 06 Feb 2013, 17:30
Location: Orléans/France

Re: [Unity] Inheriting NoesisGUIPanel

20 Jan 2016, 01:32

So It would be a component that add the NoesisGUIPanel component etc?

I was inheriting it as for some reason I had trouble accessing my class's privates members from the delegate functions (was returning some null exceptions).

I will put the draft of the message I was writing before seing you message.

Thanks for your answer jsantos! :)

DRAFT ------------------------

Hey Guys,

I am sorry for the triple posting but I though that it was more intelligent than editing.

I was wondering, what are the best practise to make UI with NoesisGUI and Unity.
Currently, I am taking the approach of making my specific "GUIs" by inheriting from NoesisGUIPanel, which allows me to have the data-binding and the direct access to the MonoBehaviour particular functions such as start etc.

Is that wrong?

Here is the current example of what my code look for my game's "main menu"
using Noesis;
using UnityEngine;

namespace Assets.BuildAndConquer.HUD.MainMenus
{
	public class MainMenu : NoesisGUIPanel
	{
		private Button m_playButton;
		private Button m_settingsButton;
		private Button m_exitButton;

		// Use this for initialization
		private void Start()
		{
			Xaml = "Assets/BuildAndConquer/HUD/MainMenus/MainMenu.xaml";
			ForceLoadXaml();

			UserControl userControl = (UserControl)GetContent();

			if (userControl == null) return;

			m_playButton = (Button)userControl.FindName("PlayButton");
			m_settingsButton = (Button)userControl.FindName("SettingsButton");
			m_exitButton = (Button)userControl.FindName("ExitButton");

			m_playButton.Click += OnPlayButtonClicked;
			m_settingsButton.Click += OnSettingsButtonClicked;
			m_exitButton.Click += OnExitButtonClicked;
		}

		// Update is called once per frame
		private void Update()
		{
		}

		private void OnPlayButtonClicked(object sender, RoutedEventArgs args)
		{
			enabled = false;
			EnableMouse = false;
			EnableKeyboard = false;
		}

		private void OnSettingsButtonClicked(object sender, RoutedEventArgs args)
		{
		}

		private void OnExitButtonClicked(object sender, RoutedEventArgs args)
		{
			Application.Quit();
		}
	}
}
It works, it displays the xaml without issues and the events work as well. My only question is regarding, is it ok to do something like delete this and create a new NoesisGUIPanel to change from, let's say, this menu to the login menu?

Do you think that this approach works/is correct?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Inheriting NoesisGUIPanel

20 Jan 2016, 03:34

Do you think that this approach works/is correct?
No. Inheriting from our component is not a good idea. You should move all that code to a new component. That is the approach we follow in all our examples.
 
User avatar
Erio
Topic Author
Posts: 81
Joined: 06 Feb 2013, 17:30
Location: Orléans/France

Re: [Unity] Inheriting NoesisGUIPanel

21 Jan 2016, 21:18

Alright, thank you. :)

I will do it this way then

Who is online

Users browsing this forum: No registered users and 2 guests