1. C#脚本如下:
using UnityEngine; using System.Collections; public class MyTest : MonoBehaviour { public int ta = 0; public int tb = 0; [System.Serializable] public class TestOne { public int a=0; public int b=0; } //在此处实例化之后,才会在Inspector中显示TestOne中的变量 public TestOne tOne; [System.Serializable] public class Equipment { public Texture2D texure; public string tip; public rectangle rec; } [System.Serializable] public class rectangle { public int x; public int y; } public Equipment[] m_Equipment; }
2. 将脚本赋给Hierarchy视图中的物体,例如我新建的一个"_Cube"
注意点:
①需要用 public 设置为公用变量
②需要用 [System.Serializable] 进行序列化
③类中的变量显示时需要进行实例化
3. 将Equipment中Size设为1,观察新增Element0等属性
4. 在Inspector面板中显示类中变量,布布扣,bubuko.com
原文:http://www.cnblogs.com/code1992/p/3607593.html