public EquipEditor(string name, EditorWindow window)
        {
            this.name             = name;
            this.window           = window;
            this.requiresDatabase = true;

            typeList = new ReorderableList(InventoryEditorUtil.selectedDatabase != null ? InventoryEditorUtil.selectedDatabase.equipStatTypes : new string[] {}, typeof(System.Type), false, true, true, true);
            typeList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Types to scan");
            typeList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                var r = rect;
                r.width -= 60;

                var statTypes = InventoryEditorUtil.selectedDatabase.equipStatTypes;

                EditorGUI.LabelField(r, (string.IsNullOrEmpty(statTypes[index]) == false && System.Type.GetType(statTypes[index]) != null) ? System.Type.GetType(statTypes[index]).FullName : "(NOT SET)");

                var r2 = rect;
                r2.width  = 60;
                r2.height = 14;
                r2.x     += r.width;
                if (GUI.Button(r2, "Set"))
                {
                    var typePicker = InventoryItemTypePicker.Get();
                    typePicker.Show(InventoryEditorUtil.selectedDatabase);
                    typePicker.OnPickObject += type =>
                    {
                        statTypes[index] = type.AssemblyQualifiedName;
                        window.Repaint();
                        GUI.changed = true; // To save..
                    };
                }
            };
            typeList.onAddCallback += list =>
            {
                var l = new List <string>(InventoryEditorUtil.selectedDatabase.equipStatTypes);
                l.Add(null);
                InventoryEditorUtil.selectedDatabase.equipStatTypes = l.ToArray();
                list.list = InventoryEditorUtil.selectedDatabase.equipStatTypes;

                window.Repaint();
            };
            typeList.onRemoveCallback += list =>
            {
                var l = new List <string>(InventoryEditorUtil.selectedDatabase.equipStatTypes);
                l.RemoveAt(list.index);
                InventoryEditorUtil.selectedDatabase.equipStatTypes = l.ToArray();
                list.list = InventoryEditorUtil.selectedDatabase.equipStatTypes;

                window.Repaint();
            };


            resultList = new ReorderableList(InventoryEditorUtil.selectedDatabase != null ? InventoryEditorUtil.selectedDatabase.equipStats : new InventoryEquipStat[] {}, typeof(InventoryEquipStat), true, true, false, false);
            resultList.drawHeaderCallback += rect =>
            {
                var r = rect;
                r.width = 40;
                r.x    += 15; // Little offset on the start

                EditorGUI.LabelField(r, "Show");


                var r2 = rect;
                r2.width -= r.width;
                r2.x     += r.width + 20;
                r2.width /= 4.2f;
                EditorGUI.LabelField(r2, "From type");

                r2.x += r2.width;
                EditorGUI.LabelField(r2, "Display name");

                r2.x += r2.width;
                EditorGUI.LabelField(r2, "Category");

                r2.x += r2.width;
                //r2.width *= 2 - 50;
                EditorGUI.LabelField(r2, "Formatter");
            };
            //resultList.elementHeight = 30;
            resultList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                var stat = InventoryEditorUtil.selectedDatabase.equipStats[index];

                var r = rect;
                r.width   = 40;
                stat.show = EditorGUI.Toggle(r, stat.show);

                GUI.enabled = stat.show;

                var r2 = rect;
                r2.width -= r.width;
                r2.x     += r.width + 5;
                r2.width /= 4.2f;
                EditorGUI.LabelField(r2, stat.fieldInfoNameVisual);

                r2.x     += r2.width + 5;
                stat.name = EditorGUI.TextField(r2, stat.name);

                r2.x         += r2.width + 5;
                stat.category = EditorGUI.TextField(r2, stat.category);

                r2.x          += r2.width + 5;
                stat.formatter = (CharacterStatFormatterBase)EditorGUI.ObjectField(r2, "", stat.formatter, typeof(CharacterStatFormatterBase), false);

                GUI.enabled = true;
            };
        }
Exemple #2
0
        public override void OnEnable()
        {
            base.OnEnable();

            item = (ItemCollectionBase)target;
            //serializer = new SerializedObject(target);
            serializer = serializedObject;

            collectionName    = serializer.FindProperty("collectionName");
            restrictByWeight  = serializer.FindProperty("restrictByWeight");
            restrictMaxWeight = serializer.FindProperty("restrictMaxWeight");
            itemButtonPrefab  = serializer.FindProperty("itemButtonPrefab");

            items                     = serializer.FindProperty("_items");
            useReferences             = serializer.FindProperty("useReferences");
            canDropFromCollection     = serializer.FindProperty("canDropFromCollection");
            canUseFromCollection      = serializer.FindProperty("canUseFromCollection");
            canDragInCollection       = serializer.FindProperty("canDragInCollection");
            canPutItemsInCollection   = serializer.FindProperty("canPutItemsInCollection");
            canStackItemsInCollection = serializer.FindProperty("canStackItemsInCollection");
            manuallyDefineCollection  = serializer.FindProperty("manuallyDefineCollection");
            container                 = serializer.FindProperty("container");
            onlyAllowTypes            = serializer.FindProperty("_onlyAllowTypes");

            itemManager = Editor.FindObjectOfType <ItemManager>();
            if (itemManager == null)
            {
                Debug.LogError("No item manager found in scene, cannot edit item.");
            }


            manualItemsList = new ReorderableList(serializer, items, true, true, true, true);
            manualItemsList.drawHeaderCallback += rect =>
            {
                EditorGUI.LabelField(rect, "Select items");
            };
            manualItemsList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                EditorGUI.PropertyField(rect, items.GetArrayElementAtIndex(index));
            };

            onlyAllowTypesList = new ReorderableList(serializer, onlyAllowTypes, false, true, true, true);
            onlyAllowTypesList.drawHeaderCallback += rect =>
            {
                EditorGUI.LabelField(rect, "Restrict by type, leave empty to allow all types");
            };
            onlyAllowTypesList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;

                var r = rect;
                r.width -= 60;

                EditorGUI.LabelField(r, (item.onlyAllowTypes[index] != null) ? item.onlyAllowTypes[index].FullName : "(NOT SET)");

                var r2 = rect;
                r2.width  = 60;
                r2.height = 14;
                r2.x     += r.width;
                if (GUI.Button(r2, "Set"))
                {
                    var typePicker = InventoryItemTypePicker.Get();
                    typePicker.Show(InventoryEditorUtil.GetItemDatabase(true, false));
                    typePicker.OnPickObject += type =>
                    {
                        item._onlyAllowTypes[index] = type.AssemblyQualifiedName;
                        GUI.changed = true; // To save..
                        EditorUtility.SetDirty(target);
                        serializer.ApplyModifiedProperties();
                        Repaint();
                    };
                }
            };
        }