2017-12-11 18 views
1

UnityEngine.Editorから派生したCustomEditorクラスにGameObject配列フィールドがあります。私は表示(描画)し、その配列を変更するユーザーの能力を与えることができる必要があります。エディタウィンドウで配列を表示および変更する方法は?

Unityable InspectorがScriptableObjectから派生したオブジェクトのSerializableフィールドでこれを行う仕組みと似ています。例えば。インスペクタでの材料の配列を表示する: .

答えて

0

を公共の配列を追加します。

public class MyEditorWindow : EditorWindow 
{ 
    [MenuItem("Window/My Editor Window")] 
    public static void ShowWindow() 
    { 
     GetWindow<MyEditorWindow>(); 
    } 

    public string[] Strings = { "Larry", "Curly", "Moe" }; 

    void OnGUI() 
    { 
     // "target" can be any class derrived from ScriptableObject 
     // (could be EditorWindow, MonoBehaviour, etc) 
     ScriptableObject target = this; 
     SerializedObject so = new SerializedObject(target); 
     SerializedProperty stringsProperty = so.FindProperty("Strings"); 

     EditorGUILayout.PropertyField(stringsProperty, true); // True means show children 
     so.ApplyModifiedProperties(); // Remember to apply modified properties 
    } 
} 

オリジナルの答えをhere

1

public GameObject[] yourGameObjects;

はその後インスペクタであなたのサイズを設定し、フィールドが開くはずです。

+0

私はEditorWindowクラスを意味します。これにより、IDEでカスタムウィンドウを作成することができます。 –

+0

@ИльяМашинあなたが何を意味するのか分かりません。これとFribuから提供された答えは、あなたが提供したイメージのもののような変数を両方表示します。 – Tom

+0

[link](https://docs.unity3d.com/Manual/editor-EditorWindows.html) エディタモードでカスタムウィンドウを作成するためのこのクラスです。私は、ゲームオブジェクトの配列のフィールドを追加しようとします。 –

1

SerializedObjectへとあなたのエディタオブジェクトを参照し、その後、すべての必要なプロパティを見つけ、それを描画し、変更を適用するスクリプトに

public GameObject[] myObjects 
+0

これはプレイモードで動作します。エディタのスクリプティングとEditorWindowを意味します。 –

関連する問題