首页 > 其他 > 详细

Inspector视图中的get/set使用

时间:2017-01-20 00:26:45      阅读:266      评论:0      收藏:0      [点我收藏+]
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 ();
    }
}

 

Inspector视图中的get/set使用

原文:http://www.cnblogs.com/kingBook/p/6309028.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!