unity 中,二维以上的数量是不支持序列化的,如:
using System.Collections.Generic;
using UnityEngine;
public class TestArray : MonoBehaviour {
// 不支持序列化(在Inspector面板无法显示)
public Rect[][] rect2Ds;
// 不支持序列化(在Inspector面板无法显示)
//public List<List<Rect>> rect2Ds;
}
可以使用以下方式代替:
using UnityEngine;
public class TestArray : MonoBehaviour {
public RectArray[] rectArrays;
private void Awake() {
var rectArray1 = new RectArray(2);
rectArray1[0] = new Rect(0, 0, 0, 0);
rectArray1[1] = new Rect(1, 1, 1, 1);
rectArrays = new RectArray[1];
rectArrays[0] = rectArray1;
}
}
[System.Serializable]
public class RectArray {
public Rect[] rects;
public RectArray(int length) {
rects = new Rect[length];
}
public Rect this[int index] {
get { return rects[index]; }
set { rects[index] = value; }
}
}
标签:rectArray1,二维,Unity,RectArray,new,序列化,public,Rect
From: https://www.cnblogs.com/kingBook/p/18450740