例えば、以下のようなクラスを用意してGameObjectにアタッチ
c#
1using UnityEditor;
2using UnityEngine;
3
4public class editorTest : MonoBehaviour {
5
6 public Vector3 position
7 {
8 get
9 {
10 return transform.position;
11 }
12 set
13 {
14 transform.position = value;
15 }
16 }
17 public Vector3 scale
18 {
19 get
20 {
21 return transform.localScale;
22 }
23 set
24 {
25 transform.localScale = value;
26 }
27 }
28
29 // Use this for initialization
30 void Start () {
31
32 }
33
34 // Update is called once per frame
35 void Update () {
36
37 }
38}
Editor側では、OnInspectorGUIでflg変数を用意してGUILayout.Toggleで制御し、flgの値によりEditorGUILayout.xxxxの実行を制御すればできるかと思います。
c#
1[CustomEditor(typeof(editorTest))]
2[CanEditMultipleObjects]
3public class PosiitonScaleEditor : Editor
4{
5 bool flg = false;
6
7 public override void OnInspectorGUI()
8 {
9 serializedObject.Update();
10 var test = target as editorTest;
11 flg = GUILayout.Toggle(flg, "Position & Scale");
12 if (flg)
13 {
14 test.position = EditorGUILayout.Vector3Field("Position", test.position);
15 test.scale = EditorGUILayout.Vector3Field("Scale", test.scale);
16 }
17 serializedObject.ApplyModifiedProperties();
18 }
19}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/06 04:11