[Unity] Adding NoesisGUIPanel dynamically
Posted: 12 Feb 2015, 22:14
When trying to add a NoesisGUIPanel dynamically and initialize it with a XAML file I have to force call the private method NoesisGUIPanel.OnEnable via reflection to load the XAML into the panel.
This works but it relies on the internal implementation of NoesisGUIPanel class and may change in future versions. Is there a better way of doing that?
Thanks, Petr
Code: Select all
var cameraGO = Camera.main.gameObject;
var gui = cameraGO.AddComponent<NoesisGUIPanel>();
gui._xamlFile = "Assets/Scripts/Gui/SystemMenu.xaml";
gui.GetType().GetMethod("OnEnable", BindingFlags.NonPublic | BindingFlags.Instance )
.Invoke(gui, new object[] {} );
var root = gui.GetRoot<UserControl>();
...
Thanks, Petr