zoukankan      html  css  js  c++  java
  • 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();
        }

    }

  • 相关阅读:
    MCU 51-7 I2C Communication EEPROM
    FinalShell(免费的XShell替代品)
    Docker部署Redis
    Docker-Compose部署ELK
    Linux清空文件
    Linux防火墙的操作
    VSCode远程连接Linux服务器
    Apollo分布式配置中心
    SpringBoot整合log4j2
    MySQL区分大小写
  • 原文地址:https://www.cnblogs.com/xwwFrank/p/4434238.html
Copyright © 2011-2022 走看看