photo

Gui vs GuiObject

Recommended Posts

Hi,

Using V2.12.0.2 C# Components i am not able to get the same results from GuiObject as from adding object to Gui.Get()

What am i doing wrong? Clean test project is attached.

PS: What where the 2 folders you needed to debug project?

image.thumb.png.3476b42e4465d6055c227a8395d5bd80.png

 

unigine_UI_Test_Project.zip

Share this post


Link to post

Hi Again,

Happy to say that I found the difference. It feels like a bug though or at least missing information.

Step one declare all of the widgets as global variables in the script, did not seem to affect me (for now)

The difference seems to be in setting the Ptr< > to the Gui.

  • To add a widget to a other widget or the display Gui you need to add the child widget. (Ptr<Widget>)
    And not construct it using the Gui.
    Gui.Get().AddChild(GetWidget());    
     In codeblock 2
     
  • To add a widget to a GuiObject you need to add the Gui gui = (node as ObjectGui).GetGui(); on constructing the widget.
    And then still add the child 
    gui.AddChild(CreateWidget(gui));     In codeblock 3
    Widget window = new WidgetWindow(gui, "demo window", 2, 2);       In codeblock 1
using Unigine;

[Component(PropertyGuid = "81bb314c3900bc3bce3b045ea659a0250867d340")]
public class ParentWindow : Component
{
	//Widget window;
	//Widget Button;
	protected Widget GetWidget()
	{
		Widget window = new WidgetWindow("demo window",2,2);
		Widget Button = new WidgetButton("test button");
		window.AddChild(Button);

		return window;
	}

	protected Widget CreateWidget(Gui gui)
	{
		Widget window = new WidgetWindow(gui, "demo window", 2, 2);
		Widget Button = new WidgetButton("test button");
		window.AddChild(Button);

		return window;
	}
}
using Unigine;

[Component(PropertyGuid = "bd991e51d532c37c610248ab2b33c60e66579615")]
public class PlayerWindow : ParentWindow
{
	private void Init()
	{
		Gui.Get().AddChild(GetWidget());
	}
}
using Unigine;

[Component(PropertyGuid = "ddfca6ca7671e7a1413adc8c89f7ee7b510e119e")]
public class GuiObjectWindow : ParentWindow
{
	private void Init()
	{
		node.WorldRotate(00.0f, 00.0f, 180.0f);
		Gui gui = (node as ObjectGui).GetGui();
		gui.AddChild(CreateWidget(gui));
	}
}

I hope this convoluted example makes sense and helps.

PS: don’t ask me why I have to rotate the GuiObject.

Gui vs GuiObject Solved.PNG

Share this post


Link to post

Hi to keep the question short.

Is it possible to change the widget Gui after construction when using C# new Widget...() ?

Share this post


Link to post

Hi David,

Please, check the attached code. It might work incorrect in some cases, however (when you will pass ObjectGui gui to the constructor).

ChangeGuiTest.cs

Share this post


Link to post

Hi Silent,

I'm sorry to hear that truly passing widget between Gui's is not supported.
Despite this i tried and got pretty far trying to rebuild the widgets.
To not have all my effort lost on myself i attache this project.

It has a 99%working Example like the C++ code. Plus Inventory drag and drop example
Only checkbox does not add to menubox.

The code to copy widgets to a new Gui only fails for the List tabs.

unigine_UI_Component_problem.zip

Share this post


Link to post