Unity3d 扩展自定义类Inspector

public class MyClass : MonoBehaviour {

    public int A;

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

 

 

using UnityEngine;
using System.Collections;
using UnityEditor;

[CanEditMultipleObjects()]
[CustomEditor(typeof(MyClass), true)]
public class MyClassEditor : Editor
{

	SerializedProperty A;

	// Use this for initialization
	void Start () {
	
	}
	
	void OnEnable()
	{
		this.A = base.serializedObject.FindProperty("A");
	}

	// Update is called once per frame
	public override void OnInspectorGUI()
	{
		//base.DrawDefaultInspector();

		serializedObject.Update();

		EditorGUILayout.PropertyField(A);


		EditorGUILayout.BeginHorizontal();
		if (GUILayout.Button("Set 10", GUILayout.Width(60)))
		{
			(target as MyClass).A = 10;
		}

		else if (GUILayout.Button("Set 20", GUILayout.Width(60)))
		{
			(target as MyClass).A = 20;
		}
		EditorGUILayout.EndHorizontal();
	}
}

  

posted @ 2015-07-20 15:13  MrBlue  阅读(1090)  评论(0编辑  收藏  举报