UNITY 手动定制inspector

依然范特西╮ 提交于 2019-12-03 16:03:44

UNITY 手动定制inspector

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;

[ExecuteInEditMode]
[CustomEditor(typeof(testxx))]
public class testxxEditor : Editor {

    [SerializeField]
    public float slider_value = 0.3f;

    public bool chk = false;
    SerializedProperty check;

    // Use this for initialization
    void Start () {
        
    }
    void OnEnable()
    {
        check = serializedObject.FindProperty("x");
        Debug.Log("============" + check.floatValue);
    }
    // Update is called once per frame
    void Update () {

    }

    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("hello"))
        {
            //testxx otx = (testxx)target;
//             otx.x = 5.93f;
//             otx.check = false;
            Debug.Log("hello------------");
        }
        slider_value = EditorGUILayout.Slider(slider_value, 0, 1.0f);
        chk = GUILayout.Toggle(chk, new GUIContent("chk"));
        EditorGUILayout.PropertyField(check);
        serializedObject.ApplyModifiedProperties();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

//[ExecuteInEditMode]
public class testxx : MonoBehaviour {

    [Range(1,10)]
    public float x = 0;

    public string text = "hello";

    public bool check = false;

    public bool[] chks = new bool[10];
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if (check)
        {
            Debug.Log("==================" + x);
        }
    }


}

 将testxx.cs挂到一个物体上,点击该GO,即可看到inspector上定制出来的相关UI

posted on 2017-03-28 17:46 时空观察者9号 阅读(...) 评论(...) 编辑 收藏

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!