一、FairyGUI编辑器中
1.新建按钮、新建组件
编辑器中界面简易设计如下

2.文件-发布设置-发布路径:自己unity项目Resources所在的路径

二、Unity 使用代码展示UI

csharp
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被点击!!!");
});
}
}
三、Unity 无代码展示UI
在Hierarchy中创建Stage Camera和 UIPanel



四、备注:场景中Main Camera的属性 Culling Mask 中不勾选UI,否则会出现两个相机画面。
