您可以使用CustomPropertyDrawer特性将 PropertyDrawer 附加到 Serializable 类,然后传入绘制器所对应的 Serializable 类的类型。 usingUnityEditor; using UnityEngine; // IngredientDrawer [CustomPropertyDrawer(typeof(Ingredient))] public class IngredientDrawer :PropertyDrawer{ // Draw the property inside the given ...
首先看public MyClass m1,它的类型是MyClass,属于“没有标记[Serializable]属性的类”,不满足类型规则;它的字段是public,满足字段规则;系统要求两条规则同时满足的对象才能序列化,于是它被跳过了。 接下来看public MyClassSerializable s1,它的类型是MyClassSerializable,属于标记了[Serializable]属性的类,满足类型规则;...
1. 行为类 类(class)是物体导向程序(objected oriented programming,OOP)的关键组成部分。 functionality>classes>fields & methods 2. 自定义类(Custom Classes) 2.1 自定义类 2.2 序列化自定义类RPG物品数据库示例 public class Item:自定义类“Item”,只是对Item的定义,因此可以删掉monobehaviour。在这个类里定义物...
// Recip.cs public enum IngredientUnit { Spoon, Cup, Bowl, Piece } [Serializable] public class Ingredient { public string name; public int amount; public IngredientUnit unit; } public class Recipe : MonoBehaviour { public Ingredient potionResult; } // IngredientDrawer.cs [CustomPropertyDrawer(ty...
If the field type is one that Unity can automatically serialize by value (simple field types, such as int, string,Vector3, etc), or if it is a custom serializable class or structure marked with the[Serializable]attribute, it is serialized as a value. ...
//[Custom("这里是学生", Remark = "123456")]//[Custom(Description = "123456", Remark = "123456")][Custom("这里是学生", Description ="123456", Remark ="123456")]//[Obsolete("请不要使用这个了,请使用什么来代替", true)]//标记过期//[Serializable]//可以序列化和反序列化publicclassStudent...
it will check for any custom types that the user have registered for serialization, after that it will check if it's a built in type, such as a Vector3, float etc. These are handled by default. If not, it will check if the type inheritsINetworkSerializable, if it does, it will cal...
字典不能通过添加Serializable属性进行序列化 如果一个类基类不能被序列化,那它即便添加了序列化特性也无法被序列化 序列化不能保存另一个要反序列化的对象指针,因为反序列化是new一个新的对象,指针指向的内存将不会是原对象 可采用unity编辑器的序列化类ScriptableObject,当我们继承这个基类,我们就可以调用unity给我们...
达到这一步之后,我们可以根据上面的思路,再去自定义编辑People各属性的显示方式。因为,无论是我们自定义的DisplayOnlyAttribute,还是Serializable,他们都继承于Attribute 所以,按上面的套路继续往下写: [CustomPropertyDrawer(typeof(People))] public class PeopleDrawer : PropertyDrawer ...
usingUnityEngine;usingUnityEditor; [System.Serializable]publicclassInspectorGrid{publicintrows;publicintcolumns; [SerializeField]bool[] enabledBools; }// ---//用PropertyDrawer自定义Inspector面板显示外观[CustomPropertyDrawer(typeof(InspectorGrid))]publicclassInspectorGridDrawer:PropertyDrawer{floatgridWidth =15f...