GComponent组件类似于容器,其他的UI组件至于其中布局显示。这里主要介绍其背景图与组件大小自适配的问题
导出资源
代码实现
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
/*
* Author:W
* 容器组件
*/
public class GComponentTest : MonoBehaviour {
private GComponent root;
/// <summary>
/// 普通容器
/// </summary>
private GComponent comComponent;
/// <summary>
/// 自适应容器
/// </summary>
private GComponent autoComponent;
void Awake()
{
UIPackage.AddPackage("UI/Basics");
}
// Use this for initialization
void Start () {
root = this.GetComponent<UIPanel>().ui;
comComponent = root.GetChild("n13").asCom;
GTextField text1 = comComponent.GetChild("n2").asTextField;
text1.text = "一般容器";
autoComponent = root.GetChild("n20").asCom;
GTextField text2 = autoComponent.GetChild("n2").asTextField;
text2.text = "自适应容器";
}
// Update is called once per frame
void Update () {
}
}
运行结果如下