Jump to content

Per world GUI scripts?


photo

Recommended Posts

Hi,

I understand how to use the internal ui classes to create a UI - but all the examples I've seen do these in the global SystemLogic overridden class.

Is there a way I can do such things per world, or per component within the Editor? Any example/sample someone could link me to?

 

Link to comment

Here's how for anyone else.

 

1 - Create ObjectGUI node in your world.

2 - Add the following script to it.

 

using System;
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "7d31a23c3674186ba481d2cee722bbd527d65b30")]
public class UITitles : Component
{

	private Gui tg;

  	// This is where you'll drag the ObjectGUI to in the editor.
	[ShowInEditor]
	public ObjectGui oui;

	private void Init()
	{
		// write here code to be called on component initialization
//		var ui = Gui.Get();

      	//This is a demo, the output will Not be to the system ui, instead it will be to the ObjectGUI quad.
		Gui ui = oui.GetGui();


		WidgetLabel lab1 = new WidgetLabel(ui,"Testing and work!");
		lab1.SetToolTip("Works!");
		lab1.Arrange();
		lab1.SetPosition(10,10);


		ui.AddChild(lab1,Gui.ALIGN_OVERLAP | Gui.ALIGN_FIXED);



	}
	
	private void Update()
	{
		// write here code to be called before updating each render frame
		
	}
}

3 - Drag the ObjectGui node to the "oui" property defined in the above script.

4 - Run. You'll see your simple label displayed onto the in world UI quad. If you wish to overlay this onto something, click the "Background" check box and you'll only see the label.

If you want this to follow the camera, align it properly, then add the ObjectGUI node as a child of the player/camera, and thus it will follow the player/camera without moving.

 

 

 

 

 

Link to comment
×
×
  • Create New...