FairyGUI和Unity联动(入门篇)
using FairyGUI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FguiTest : MonoBehaviour
{
/// <summary>
/// 普通按钮
/// </summary>
private GButton comBtn1;
private GButton comBtn3;
void Start()
{
GRoot.inst.SetContentScaleFactor(1920,1080); //初始化设置分辨率
UIPackage.AddPackage("Panels/PanelMain"); //加载打包好的项目
GComponent component = UIPackage.CreateObject("PanelMain", "Component1").asCom;
//加载对应的组件 通过.asCom(或as GComponent)类型转换将它转换为GComponent组件类型
GRoot.inst.AddChild(component); //把当前组件实例化到UI Panel(GRoot实际上是UI Panel)的下面
comBtn1 = component.GetChild("n1").asButton;
comBtn1.onClick.Add(() =>
{
Debug.Log("按钮1被点击了!!");
});
comBtn3 = component.GetChild("n3").asButton;
comBtn3.onClick.Add(() =>
{
Debug.Log("普通按钮2被点击!!!");
});
}
}