2016-08-22 17 views
1

私は、ユニティプロジェクトで学習AIを使用するために(少なくとも今のところ)データを格納するための非常に簡単なクラスを作成しています。私はインスペクタで複数のエージェントを簡単にカスタマイズできるようにしたいが、垂直に積み重ねられたチェックボックスの数によって、プロジェクトのこの部分がインスペクタを支配するようになります。私が単純に1つのセクションにインスペクタの右側の十分な空き領域を利用させることができれば、それはかなり醜いことになります。ユニティインスペクタで変数を水平方向に整列する

私はカスタムのプロパティー・ドロワーとインスペクター・ウインドウについてたくさんのことを読んできましたが、1つの変更で、クラス全体の表示方法を書き直すなど、多くの作業のようです。

enter image description here

は参考のため、ここではクラス自体です。

[System.Serializable] 
public class NNInfo 
{ 
    public string networkName = "Agent"; 

    [Header("Movement Properties")] 
    public float movementSpeed = 10f; 
    public float rotationSpeed = 1f; 

    [Header("Learning Properties")] 
    public float learningRate = 0.1f; 
    public float momentum = 0f; 
    public Rewards rewardFunc; 
    public int[] hiddenLayers; 

    [Header("Other Properties")] 
    public int maxHealth = 1000; 

    [Header("Optional Inputs")] 
    public bool m_PointToNearestBall = false;   // input which is 1 while the agent is facing a ball and -1 when facing away 
    public bool m_DistanceToNearestBall = false;  // input which is 1 while the agent is at the ball and -1 when at max possible distance away 
    public bool m_PointToEndzone = false;    // similar to m_PointToNearestBall but for the endzone 
    public bool m_Position = false;      // two inputs which inform the player of its normalized x and y coordinates on the field 
    public bool m_WhetherHoldingBall = false;   // tells the player whether its holding a ball 
    public bool m_CanSeeHealth = false;     // Whether the player can know its own health 

    [Header("Optional Outputs")] 
    public bool m_ForwardLeft = false;     // turn left and move forward simultaneously 
    public bool m_ForwardRight = false;     // turn right and move forward simultaneously 
    public bool m_Reverse = false;      // move backwards 
    public bool m_Flip = false;       // instantly switch to opposite direction 
    public bool m_TurnToBall = false;     // instantly turn to face nearest ball 
    public bool m_TurnToLeft = false;     // instantly turn to face left side of field 
    public bool m_Attack = false;      // attack a player (or idle if no contact) 
} 
+0

これは本当にクールなアイデアですが、私はそれが(簡単な方法で)可能ではないと思います。 – byxor

+1

私はこれがSOに属していないと思います。質問はUnity Devツールに関するものであるため、純粋なプログラミングには直接関係しません。これはGame Dev(http://gamedev.stackexchange.com/)に属している必要があります。Unity AnswersのWebサイト(http://answers.unity3d.com/)には記載されていません。 –

+0

を使用して、エディタコードを更新する(または独自の関数を記述する)必要があります。それは非常に困難ではなく、オンラインで多くのチュートリアルがあります。 – Cabrra

答えて

0

カスタムプロパティードローラーは興味深いはずのキーワードです。

これらを管理するための独自のコードを記述することで、UnityエディタでInspector Viewのプロパティをどのように表示するかを記述できます。

開始するには、documentation site,にアクセスしてください。このコードには、基になるコードが含まれています。 (Javacrpt、C#のバージョンがリンクの下に見つけることができます)

コードスニペット:

オブジェクトのコード:

enum IngredientUnit { Spoon, Cup, Bowl, Piece } 

// Custom serializable class 
class Ingredient extends System.Object { 
    var name : String; 
    var amount : int = 1; 
    var unit : IngredientUnit; 
} 

var potionResult : Ingredient; 
var potionIngredients : Ingredient[]; 

function Update() { 
    // Update logic here... 
} 

エディタコード:

@CustomPropertyDrawer(Ingredient) 
class IngredientDrawer extends PropertyDrawer { 

    // Draw the property inside the given rect 
    function OnGUI (position : Rect, property : SerializedProperty, label : GUIContent) { 
     // Using BeginProperty/EndProperty on the parent property means that 
     // prefab override logic works on the entire property. 
     EditorGUI.BeginProperty (position, label, property); 

     // Draw label 
     position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label); 

     // Don't make child fields be indented 
     var indent = EditorGUI.indentLevel; 
     EditorGUI.indentLevel = 0; 

     // Calculate rects 
     var amountRect = new Rect (position.x, position.y, 30, position.height); 
     var unitRect = new Rect (position.x+35, position.y, 50, position.height); 
     var nameRect = new Rect (position.x+90, position.y, position.width-90, position.height); 

     // Draw fields - passs GUIContent.none to each so they are drawn without labels 
     EditorGUI.PropertyField (amountRect, property.FindPropertyRelative ("amount"), GUIContent.none); 
     EditorGUI.PropertyField (unitRect, property.FindPropertyRelative ("unit"), GUIContent.none); 
     EditorGUI.PropertyField (nameRect, property.FindPropertyRelative ("name"), GUIContent.none); 

     // Set indent back to what it was 
     EditorGUI.indentLevel = indent; 

     EditorGUI.EndProperty(); 
    } 
} 

enter image description here

関連する問題