在统一检查器中水平对齐变量

时间:2016-08-22 14:03:19

标签: unity3d inspector

我正在编写一个非常简单的类来存储数据(至少目前为止),以便在Unity项目中用于学习AI。我希望能够在检查器中轻松自定义多个代理程序,并且垂直堆叠的复选框的数量使我的项目的这一部分在检查器中占主导地位。如果我可以简单地让一个部分利用检查员右侧的充足空白空间,那就不那么难看了。

我一直在阅读很多关于自定义属性抽屉和检查器窗口的内容,但它似乎需要做很多工作,包括重写整个类的显示方式,进行一次更改。

enter image description here

供参考,这是课程本身。

namespace SeleniumTestDriver
{
   class Program
   {

    static void Main(string[] args)
    {
        StringDictionary testData = new StringDictionary();
        testData = GetTestData();

        IWebDriver driver = new InternetExplorerDriver();

        driver.Navigate().GoToUrl("http://toolsqa.com/automation-practice-form/");
        driver.Manage().Window.Maximize();

        IWebElement txtbxFirstName = driver.FindElement(By.Name("firstname"));
        txtbxFirstName.SendKeys(testData["firstName"]);

}


public static StringDictionary GetTestData()
    {
        StringDictionary dataFromExcel = new StringDictionary();
        Excel.Application xlApp = new Excel.Application();
        xlApp.Visible = false;
        Excel.Workbook xlWb = xlApp.Workbooks.Open(@"C:\Users\...\Desktop\1.xlsx");
        Excel.Worksheet xlSht1 = xlWb.Worksheets.get_Item(2);
        dataFromExcel.Add("firstName", xlSht1.Cells[2, 1].value);
        dataFromExcel.Add("lastName", xlSht1.Cells[2, 2].value);
        dataFromExcel.Add("gender", xlSht1.Cells[2, 3].value);
        dataFromExcel.Add("tool", xlSht1.Cells[2, 4].value);
        dataFromExcel.Add("continent", xlSht1.Cells[2, 5].value);
        xlWb.Close();
        xlApp.Quit();
        return dataFromExcel;

    }
 }
}

1 个答案:

答案 0 :(得分: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