unity3d學習日記:使用[System.Serializable]在inspector面板內顯示自定義資料型別類例項物件的內部資料
阿新 • • 發佈:2019-01-24
在unity裡,自定義資料型別無法顯示在inspectior面板裡,需要對定義資料型別的類或者結構體使用[System.Serializable]。效果如圖:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test : MonoBehaviour { public A[] AList; public B[] BList; public A a; public B b; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } } [System.Serializable] public struct A { public int a; public GameObject b; public Vector3 c; } public struct B { public int a; public GameObject b; public Vector3 c; }
可以看到,結構體B的資料無法再面板內顯示,而A的則可以顯示。