今天刚刚接触到FairyGUI的UI导入到Unity中的代码方法,关于其中一段代码的理解如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
public class FairyGUIText : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GRoot.inst.SetContentScaleFactor(400, 400);
UIPackage.AddPackage("FGUI/Package1");
GComponent component = UIPackage.CreateObject("Package1", "Component1").asCom;
GRoot.inst.AddChild(component);
}
// Update is called once per frame
void Update()
{
}
}
GRoot.inst.SetContentScaleFactor(400, 400);
设置屏幕的分辨率,一般与FairyGUI中的设置相同
UIPackage.AddPackage("FGUI/Package1");
导入一个需要的包
GComponent component = UIPackage.CreateObject("Package1", "Component1").asCom;
将导入包中的组件提取出并赋值给component,注意转化为为GComponent类型
GRoot.inst.AddChild(component);
将component设置为GRoot的子对象
关于GRoot.inst我理解的是调用GRoot的实例化方法实例化其它组件
有错误欢迎指出