• get set 方法


    1问题描述:在inspector面板中修改一个参数的值,但是set并没有执行,及面板中修改的值没有放到set中。

    随便挂在一个物体之上就行

    using UnityEngine;
    using System.Collections;

    public class GetSet : MonoBehaviour
    {
     public int width
     {
      get {
       return _width;
      }
      set {
       Debug.Log("set :" + value);//通过输出来鉴别是否修改成功了
       _width = value;
      }
     }
        private int _width;
    }

    2.使用unity自带的editor把值写出在面板中,并更新它的值,这样就可以实现面板中和set中的值同步了

    using UnityEngine;
    using UnityEditor;
    using System.Collections;


    [CustomEditor(typeof(GetSet))]
    public class TestInspector : Editor
    {
        GetSet gt;
        public override void OnInspectorGUI()
        {
            gt = target as GetSet;
            int width = EditorGUILayout.IntField("Width", gt.width);
            if(gt.width != width)
            {
                gt.width = width;
            }
            base.OnInspectorGUI();
        }

    }

  • 相关阅读:
    面向对象六
    面向对象五
    面向对象四
    面向对象三
    面向对象二
    CentOS7下安装Redis4.0
    在亚马逊的EC2环境中创建swap
    centos7安装rabbitmq操作步骤
    在VUE下使用阿里图标
    Centos7-安装telnet服务
  • 原文地址:https://www.cnblogs.com/xwwFrank/p/4434238.html
Copyright © 2020-2023  润新知