Unity 3 d拡張カスタムクラスInspector

1648 ワード

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();

	}

}