今天剛剛接觸到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的實例化方法實例化其它組件
有錯誤歡迎指出