2016-08-22 4 views
1

유니티 프로젝트에서 학습용 AI와 함께 사용하기 위해 데이터를 저장하는 아주 간단한 클래스를 작성하고 있습니다. 관리자에서 여러 에이전트를 쉽게 사용자 지정할 수 있기를 원하며 수직으로 쌓인 확인란의 수가 프로젝트의이 부분을 검사자를 압도하게 만듭니다. 검사관의 오른쪽에 충분한 빈 공간을 하나의 섹션에서 사용할 수 있다면 간단하게 추한 것입니다.유니티 인스펙터에서 변수를 가로로 맞 춥니 다

커스텀 서랍 서랍 창과 검사기 창에 대해서는 많이 읽었지만 한 가지 변경 사항으로 전체 클래스가 표시되는 방식을 다시 작성하는 작업이 많은 것 같습니다.

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

나는이 주제에 속하지 않는다고 생각합니다. 질문은 Unity Dev 도구에 관한 것이므로 순수 프로그래밍과 직접 관련이 없습니다. Game Dev (http://gamedev.stackexchange.com/) 또는 Unity Answers 웹 사이트 (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

관련 문제