1.官网说明:https://docs.unity3d.com/Manual/script-Serialization.html#ClassSerialized Has the Serializable attribute//必须有Serializable属性 Is not abstract//不是抽象类 Is not static//不是静态类 Is not generic, though it may inherit from a generic class//不是泛型类,尽管这个类可能继承自泛型类 例: [Serializable ] public class TestClass { float t1; string s2; int i3; }
2.类的成员变量也要是可序列化,不可序列化的成员变量值将丢失。一般基本数据类型都可序列化,如string、int、float等,Dictionary、UnityEngine.Rect则不可序列化。
3.类的成员变量类型如果也是可序列化类,则嵌套最多7级。
4.类与类不能交叉引用,如A类中有个B类的b,则B类中不能有A类的成员变量,否则将出错。