Esempio n. 1
0
    /*
     * update user interface for the window.
     */
    protected override void DrawInnerWindow()
    {
        // if we haven't done a scan yet, do one
        if (attribSelectionChecklist.Count == 0)
        {
            RebuildAttribSelectionChecklist();
        }

        currentTab = GUILayout.Toolbar(currentTab, new string[] { "Create Items", "Edit Items" });

        switch (currentTab)
        {
        case CREATE_ITEM_TAB:
            newItemName = EditorGUILayout.TextField("Item Name", newItemName);

            // add each item in possibleItems as a toggle
            for (int i = 0; i < itemAttributeResource.ItemAttributeTypes.Count; i++)
            {
                attribSelectionChecklist[i] = EditorGUILayout.Toggle(itemAttributeResource.ItemAttributeNames[i], attribSelectionChecklist[i]);
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            // button used to actually create the asset
            if (GUILayout.Button("Create Item"))
            {
                List <System.Type> selectedAttribs = new List <System.Type>();
                for (int j = 0; j < itemAttributeResource.ItemAttributeTypes.Count; j++)
                {
                    if (attribSelectionChecklist[j])
                    {
                        selectedAttribs.Add(itemAttributeResource.ItemAttributeTypes[j]);
                    }
                }
                itemResource.CreateNewItem(newItemName, selectedAttribs);
                currentTab = EDIT_ITEM_TAB;
            }

            GUILayout.EndHorizontal();
            break;

        case EDIT_ITEM_TAB:
            bool itemSelected = false;
            foreach (Object obj in Selection.objects)
            {
                InventoryItem asItem = obj as InventoryItem;
                if (asItem != null)
                {
                    // we have an InventoryItem!
                    itemSelected = true;

                    EditorGUILayout.LabelField(asItem.itemName, EditorStyles.boldLabel); // name of item

                    EditorGUI.indentLevel++;                                             // indent

                    // for each attribute this item has, list all the attribute's properties
                    foreach (ItemAttribute attrib in asItem.attributes)
                    {
                        EditorGUILayout.LabelField(attrib.GetType().Name);     // name of attrib

                        SerializedObject serializedAttrib = new SerializedObject(attrib);

                        SerializedProperty serializedProp = serializedAttrib.GetIterator();     // iterator over all properties of attrib

                        EditorGUI.indentLevel++;

                        // look through all properties and display them
                        while (serializedProp.NextVisible(true))
                        {
                            if (serializedProp.name != "m_Script")
                            {
                                EditorGUILayout.PropertyField(serializedProp, new GUIContent(UnityEditor.ObjectNames.NicifyVariableName(serializedProp.name)), GUILayout.MinWidth(100));
                            }
                        }

                        // allow modification of properties
                        serializedAttrib.ApplyModifiedProperties();

                        EditorGUI.indentLevel--;
                    }

                    EditorGUI.indentLevel--;
                }
            }
            if (!itemSelected)
            {
                GUILayout.Label("Please select an item to edit from the Project window...");
            }
            break;
        }
    }