By leaving Game Framework to load a simple UI, everyone should know, so how to use it under the game framework framework?
Game Framework loads UI. To put it plainly, it is to use the UI Component to uniformly load and manage the UI prefab to avoid a large number of UI scattered in the scene and management difficulties.
Let’s build a UI default body first.
Open our previous project and create a new UI first. I renamed the UI as HelloWorld. It just prints on the screenHello,World!
, nothing else.
Then add the UI logic of this UI. Game Framework will report an error if you can’t detect the logical script of the UI.
Create a script, the name I created isUI_HelloWorld
using UnityGameFramework.Runtime;
public class UI_HelloWorld : UIFormLogic
{
}
Because we just call it alone, we don’t need any substantial functions, so we don’t need to write anything in the class.
Then mount this script to the UI we just created, and then save the UI into Prefab.
What we have to do next is where we do
This UI is loaded in theProcedureMainprocess.
We must first create a UI group to store this UI.
Click in the Example sceneGameFramework, found itUIObject.
willUI ComponentUI GroupsSizeChange to 1, and then give it to the new appearanceElement 0NAME just starts with one, here I start hereDefaultGroup。
This way we can adjust the UI to this group in a while.
OpenProcedureMainscript, add a few lines of code to the ** Onener () ** to let it load the UI when entering:
Don’t forget to addUnityGameFramework.Runtime
Probes
using GameFramework;
using GameFramework.Procedure;
using UnityGameFramework.Runtime; // Don't forget this
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
namespace Game
{
public class ProcedureMain : ProcedureBase
{
// execute when the game initializes.
protected override void OnInit(ProcedureOwner procedureOwner)
{
base.OnInit(procedureOwner);
}
// Enter this process every time you enter this process.
protected override void OnEnter(ProcedureOwner procedureOwner)
{
base.OnEnter(procedureOwner);
Log.Debug("Enter ProcedureMain!");
// Load the framework UI component
UIComponent UI = GameEntry.GetComponent<UIComponent>();
// Load UI
UI.OpenUIForm("Assets/Example/HelloWorld.prefab","DefaultGroup");
}
// Each round of inquiry execution.
protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
{
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
}
// execute each time the process is left.
protected override void OnLeave(ProcedureOwner procedureOwner, bool isShutdown)
{
base.OnLeave(procedureOwner, isShutdown);
}
// execute when the game exits.
protected override void OnDestroy(ProcedureOwner procedureOwner)
{
base.OnDestroy(procedureOwner);
}
}
}
After saving, we can see the effect. Back to Unity, click the Play button.
UI was loaded by us.
Open UI Component step by step, we can see that UI is indeed loaded here.
This is here
This section is here, goodbye to the next article.