Inspector视图中的get/set使用
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { public int width { get { Debug.Log("get"); return _width; } set { Debug.Log ("set"); _width = value; } } [SerializeField]//强制Unity去序列化一个私有域 private int _width; }
using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor(typeof(Test))] public class TestEditor:Editor { public override void OnInspectorGUI (){ Test test=target as Test; int w=EditorGUILayout.IntField("Width",test.width); if(test.width!=w)test.width=w; base.OnInspectorGUI (); } }