码迷,mamicode.com
首页 > 编程语言 > 详细

UNITY 手动定制inspector

时间:2017-03-28 19:21:15      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:button   generic   serial   tar   sys   点击   ext   date   guilayout   

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

UNITY 手动定制inspector

标签:button   generic   serial   tar   sys   点击   ext   date   guilayout   

原文地址:http://www.cnblogs.com/timeObjserver/p/6636051.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!