public static void DrawItemAmountRow(Rect rect, SerializedProperty property)
        {
            var r2 = rect;

            r2.width /= 2;
            r2.width -= 5;

            var amount  = property.FindPropertyRelative("amount");
            var itemRef = property.FindPropertyRelative("item");
            var item    = itemRef.objectReferenceValue as InventoryItemBase;

            amount.intValue = EditorGUI.IntField(r2, amount.intValue);
            if (amount.intValue < 1)
            {
                amount.intValue = 1;
            }

            r2.x += r2.width + 5;

            if (item == null)
            {
                GUI.backgroundColor = Color.red;
            }

            ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(r2, "", itemRef);
            GUI.backgroundColor = Color.white;
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            var amount   = property.FindPropertyRelative("_amount");
            var currency = property.FindPropertyRelative("_currency");

            var w3 = position.width / 3f;

            position.width = w3 * 2;

            using (new ColorBlock(Color.red, amount.floatValue > 0f && currency.objectReferenceValue == null))
            {
                ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>(position, label.text, currency);
            }

            position.x    += position.width + 10;
            position.width = w3;

            var prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 60;
            EditorGUI.PropertyField(position, amount);
            EditorGUIUtility.labelWidth = prevLabelWidth;

            if (amount.floatValue < 0f)
            {
                amount.floatValue = 0f;
            }

            EditorGUI.EndProperty();
        }
        public override void EditItem(EquipmentType item)
        {
            base.EditItem(item);
            _equipmentHandlerDrawer = ReflectionDrawerUtility.BuildEditorHierarchy(ReflectionUtility.GetFieldInherited(item.GetType(), "equipmentHandler"), item);

            _restrictionList = new UnityEditorInternal.ReorderableList(selectedItem.blockTypes, typeof(int), false, true, true, true);
            _restrictionList.drawHeaderCallback  += rect => GUI.Label(rect, "Restrictions");
            _restrictionList.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 2;
                rect.width -= 30;
                rect.x     += 30; // Some selection room

                if (index < 0 || index >= selectedItem.blockTypes.Length)
                {
                    return;
                }

                // Trying to block self, not allowed.
                if (selectedItem.blockTypes[index] == selectedItem)
                {
                    var t = rect;
                    t.width = 200;

                    GUI.backgroundColor = Color.red;
                    EditorGUI.LabelField(t, "Can't block self");

                    rect.x     += 205; // +5 for margin
                    rect.width -= 205;
                }

                ObjectPickerUtility.RenderObjectPickerForType(rect, string.Empty, selectedItem.blockTypes[index], typeof(EquipmentType),
                                                              (val) =>
                {
                    selectedItem.blockTypes[index] = (EquipmentType)val;
                });

                GUI.backgroundColor = Color.white;
            };
            _restrictionList.onAddCallback += list =>
            {
                var l = new List <EquipmentType>(selectedItem.blockTypes);
                l.Add(null);
                selectedItem.blockTypes = l.ToArray();
                list.list = selectedItem.blockTypes;

                window.Repaint();
            };
            _restrictionList.onRemoveCallback += list =>
            {
                // Remove the element itself
                var l = new List <EquipmentType>(selectedItem.blockTypes);
                l.RemoveAt(list.index);
                selectedItem.blockTypes = l.ToArray();
                list.list = selectedItem.blockTypes;

                window.Repaint();
            };
        }
        public override object OnGUI(GUIContent label, object obj, bool isSceneObject, params object[] attributes)
        {
            var t = (InventoryItemPlayerMakerAdapter)obj;

            if (t.item == null)
            {
                GUI.color = Color.yellow;
            }

            ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(label.text, t.item, item =>
            {
                _item       = item;
                GUI.changed = true;
            });

            if (_item != null)
            {
                t.item      = _item;
                _item       = null;
                GUI.changed = true;
            }

            GUI.color = Color.white;
            return(t);
        }
Ejemplo n.º 5
0
        protected override object DrawInternal(Rect rect)
        {
            rect = GetSingleLineHeightRect(rect);

            var unityEngineObject = (UnityEngine.Object)value; // Cast first, otherwise unity thinks it's not null (wrapped C# / C++ object fails check for some reason)

            if (forceUnityPicker)
            {
                EditorGUI.BeginChangeCheck();
                this.value = EditorGUI.ObjectField(rect, unityEngineObject, GetFieldType(false), true);
                if (EditorGUI.EndChangeCheck() && ReferenceEquals(unityEngineObject, value) == false)
                {
                    NotifyValueChanged(value);
                }
            }
            else
            {
                ObjectPickerUtility.RenderObjectPickerForType(rect, fieldName.text, unityEngineObject, GetFieldType(false), o =>
                {
                    this.value = o;
                    NotifyValueChanged(value);
                });
            }

            return(value);
        }
Ejemplo n.º 6
0
 protected virtual void OnClickedFieldRightSide(SerializedProperty prop)
 {
     // Use custom picker only for prefabs. Use Unity's picker for scene objects and built-in types.
     ObjectPickerUtility.GetObjectPickerForType(typeof(T), (asset) =>
     {
         prop.objectReferenceValue = asset;
         prop.serializedObject.ApplyModifiedProperties();
     });
 }
Ejemplo n.º 7
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            var l = new List <CustomOverrideProperty>(extraOverride)
            {
                new CustomOverrideProperty(_currency.name, () =>
                {
                    ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>(_currency);
                })
            };

            base.OnCustomInspectorGUI(l.ToArray());
        }
        public override void EditItem(CurrencyDefinition item)
        {
            base.EditItem(item);

            _currencyConversionList = new UnityEditorInternal.ReorderableList(item.currencyConversions, typeof(CurrencyConversion), true, true, true, true);
            _currencyConversionList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Currency conversions");
            _currencyConversionList.drawElementCallback += (rect, index, active, focused) =>
            {
                var r = rect;
                r.height = 18;
                r.y     += 2;

                var conversion = item.currencyConversions[index];

                r.width /= 3;
                r.width -= 5;
                EditorGUIUtility.labelWidth = 100;
                conversion.factor           = EditorGUI.FloatField(r, "1 " + item.singleName + " to ", conversion.factor);
                EditorGUIUtility.labelWidth = EditorStyles.labelWidth;

                r.x += r.width + 5;

                //r.width /= 2;
                ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>(r, string.Empty, conversion.currency, (c) =>
                {
                    conversion.currency = c;
                });

                r.x += r.width + 5;
                EditorGUIUtility.labelWidth    = 80;
                conversion.useInAutoConversion = EditorGUI.Toggle(r, "auto conv.", conversion.useInAutoConversion);
                EditorGUIUtility.labelWidth    = EditorStyles.labelWidth;
            };
            _currencyConversionList.onAddCallback += list =>
            {
                var l = new List <CurrencyConversion>(item.currencyConversions);
                l.Add(new CurrencyConversion());
                item.currencyConversions = l.ToArray();

                list.list = item.currencyConversions;
            };
            _currencyConversionList.onRemoveCallback += list =>
            {
                var l = new List <CurrencyConversion>(item.currencyConversions);
                l.RemoveAt(list.index);
                item.currencyConversions = l.ToArray();

                list.list = item.currencyConversions;
            };
        }
        public static void AudioClipInfo(string name, AudioClipInfo clip)
        {
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            ObjectPickerUtility.RenderObjectPickerForType(name, clip.audioClip, typeof(AudioClip), val =>
            {
                clip.audioClip = (AudioClip)val;
            });
            clip.volume = EditorGUILayout.FloatField("Volume", clip.volume);
            clip.pitch  = EditorGUILayout.FloatField("Pitch", clip.pitch);
            clip.loop   = EditorGUILayout.Toggle("Loop", clip.loop);

            EditorGUILayout.EndVertical();
        }
Ejemplo n.º 10
0
        protected override void DrawDetail(CraftingCategory category, int index)
        {
            EditorGUIUtility.labelWidth = EditorStyles.labelWidth;
            RenameScriptableObjectIfNeeded(category, category.name);

            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            EditorGUILayout.LabelField("Note that this is not used for item categories but rather category types such as Smithing, Tailoring, etc.", EditorStyles.titleStyle);
            EditorGUILayout.Space();

            category.name        = EditorGUILayout.DelayedTextField("Category name", category.name);
            category.description = EditorGUILayout.TextField("Category description", category.description);

            EditorGUILayout.Space();
            category.alsoScanBankForRequiredItems = EditorGUILayout.Toggle("Scan bank for craft items", category.alsoScanBankForRequiredItems);
            EditorGUILayout.Space();


            EditorGUILayout.LabelField("Audio clips", EditorStyles.titleStyle);
            EditorGUILayout.Space();

            InventoryEditorUtility.AudioClipInfo("Success Audio clip", category.successAudioClip);
            InventoryEditorUtility.AudioClipInfo("Crafting Audio clip", category.craftingAudioClip);
            InventoryEditorUtility.AudioClipInfo("Canceled Audio clip", category.canceledAudioClip);
            InventoryEditorUtility.AudioClipInfo("Failed Audio clip", category.failedAudioClip);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Layout crafting", EditorStyles.titleStyle);
            EditorGUILayout.Space();

            ObjectPickerUtility.RenderObjectPickerForType("Icon", category.icon, typeof(Sprite), val =>
            {
                category.icon = (Sprite)val;
            });

            category.rows = (uint)EditorGUILayout.IntField("Layout rows", (int)category.rows);
            category.cols = (uint)EditorGUILayout.IntField("Layout cols", (int)category.cols);

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Category contains " + category.blueprints.Length + " blueprints.", EditorStyles.titleStyle);
            EditorGUILayout.EndVertical();


            ValidateItemFromCache(category);

            EditorGUIUtility.labelWidth = 0;
        }
        public void OnEnable()
        {
            _equipTypes = serializedObject.FindProperty("_equipmentTypes");

            _list = new UnityEditorInternal.ReorderableList(serializedObject, _equipTypes, true, true, true, true);
            _list.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Which types can be placed in this field?");
            _list.drawElementCallback += (rect, index, active, focused) =>
            {
                rect.height = 16;
                rect.y     += 3;

                var i = _equipTypes.GetArrayElementAtIndex(index);
                ObjectPickerUtility.RenderObjectPickerForType <EquipmentType>(rect, i);
            };
        }
Ejemplo n.º 12
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraSpecific)
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(script);

            GUILayout.Label("Behavior", EditorStyles.titleStyle);
            ObjectPickerUtility.RenderObjectPickerForType <CraftingCategory>(_startCraftingCategory);

            DrawPropertiesExcluding(serializedObject, new string[]
            {
                "m_Script",
                "_startCraftingCategoryID",
            });

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 13
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>(_currency);
            var doNotDrawList = new List <string>()
            {
                "m_Script",
                _currency.name
            };

            foreach (var extra in extraOverride)
            {
                extra.action();
                doNotDrawList.Add(extra.serializedName);
            }

            DrawPropertiesExcluding(serializedObject, doNotDrawList.ToArray());
        }
        public override bool DrawField(ref object obj, plyBlock fieldOfBlock)
        {
            bool ret    = (obj == null);
            var  target = obj == null ? new InventoryItemBaseFieldData() : obj as InventoryItemBaseFieldData;

            ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>("", target.item, item =>
            {
                target.item = item;
                GUI.changed = true;

                ed.ForceSerialise();
                ed.Repaint();
            });

            obj = target;
            return(ret);
        }
Ejemplo n.º 15
0
        /// <summary> Called when the nfo[] edit fields should be rendered </summary>
        public override void NfoField(plyDataObject data, EditorWindow ed)
        {
            // nfo[0] = 0:Currency, 1:Item
            // nfo[1] = the identifier of the attribute or item.(not used with currency selected)
            // nfo[2] = cached name of selected attribute or item

            EditorGUI.BeginChangeCheck();
            _selected = EditorGUILayout.Popup("Reward Type", _selected, _options);
            if (EditorGUI.EndChangeCheck())
            {
                data.nfo[0] = _selected.ToString();
                data.nfo[1] = "-1";
                data.nfo[2] = "";
            }

            if (_selected == 0)
            {
                ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>("Currency", _selectedCurrency, (val) =>
                {
                    _selectedCurrency = val;
                });

                data.nfo[0] = "0";
                data.nfo[1] = _selectedCurrency.ToString();
                data.nfo[2] = _selectedCurrency != null ? _selectedCurrency.singleName : " (NOT FOUND)";
            }
            else if (_selected == 1)
            {
                if (GUILayout.Button("Select item"))
                {
                    //itemPicker = InventoryItemPicker.Get();
                    ObjectPickerUtility.GetObjectPickerForType <InventoryItemBase>(item =>
                    {
                        data.nfo[0]       = "1";
                        data.nfo[1]       = item.ID.ToString();
                        data.nfo[2]       = item.name;
                        _selectedCurrency = null;
                        //data.nfo[2] = item.currentStackSize.ToString();

                        ed.Repaint();
                        GUI.changed = true;
                    });
                }
            }
        }
        public static void DrawStatRequirement(Rect rect, SerializedProperty statLookup, bool isActive, bool isFocused, bool drawFilterType)
        {
            rect.height = 16;
            rect.y     += 2;

            var r2 = rect;

            r2.y     += 20;
            r2.width /= 2;
            r2.width -= 5;

            var popupRect = rect;

            popupRect.width /= 2;
            popupRect.width -= 5;

            var stat          = statLookup.FindPropertyRelative("stat");
            var statValue     = statLookup.FindPropertyRelative("value");
            var statValueType = statLookup.FindPropertyRelative("statValueType");
            var filterType    = statLookup.FindPropertyRelative("filterType");

            ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(popupRect, string.Empty, stat);
            popupRect.x += popupRect.width;
            popupRect.x += 5;

            if (IsStatValueValid(statValue.floatValue) == false)
            {
                GUI.color = Color.red;
            }

            statValue.floatValue = EditorGUI.FloatField(popupRect, "", statValue.floatValue);
            GUI.color            = Color.white;

            if (drawFilterType)
            {
                var r3 = r2;
                EditorGUI.PropertyField(r3, statValueType, new GUIContent(""));

                r3.x += r3.width + 5;
                EditorGUI.PropertyField(r3, filterType, new GUIContent(""));
            }

            GUI.enabled = true;
        }
Ejemplo n.º 17
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            base.OnCustomInspectorGUI(extraOverride);

            serializedObject.Update();

            // Draws remaining items
            EditorGUILayout.BeginVertical();
            DrawPropertiesExcluding(serializedObject, new string[]
            {
                "m_Script",
                _craftingCategory.name,
            });

            ObjectPickerUtility.RenderObjectPickerForType <CraftingCategory>(_craftingCategory);
            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
        public static void DrawStatRequirement(Rect rect, StatRequirement stat, bool isActive, bool isFocused, bool drawFilterType)
        {
            rect.height = 16;
            rect.y     += 2;

            var r2 = rect;

            r2.y     += 20;
            r2.width /= 2;
            r2.width -= 5;

            var popupRect = rect;

            popupRect.width /= 2;
            popupRect.width -= 5;

            ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(popupRect, string.Empty, stat.stat, (val) =>
            {
                stat.stat = val;
            });

            popupRect.x += popupRect.width;
            popupRect.x += 5;

            if (IsStatValueValid(stat.value) == false)
            {
                GUI.color = Color.red;
            }

            stat.value = EditorGUI.FloatField(popupRect, "", stat.value);
            GUI.color  = Color.white;

            if (drawFilterType)
            {
                EditorGUI.LabelField(r2, "Filter type");

                r2.x           += r2.width + 5;
                stat.filterType = (StatRequirement.FilterType)EditorGUI.EnumPopup(r2, GUIContent.none, stat.filterType);
            }

            GUI.enabled = true;
        }
Ejemplo n.º 19
0
        public override InventoryItemBase OnGUI(string label, InventoryItemBase instance)
        {
            Rect rect = GUILayoutUtility.GetRect(300, 300f, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight, GUILayout.ExpandHeight(false));

            rect.x     += 5f;
            rect.width -= 5f;

            ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(rect, label, instance, (val) =>
            {
                _pickedValue = val;
            });

            if (_pickedValue != null)
            {
                instance     = _pickedValue;
                _pickedValue = null;
            }

            return(instance);
        }
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            var t = (plyGameSkillInventoryItem)target;

            var l = new List <CustomOverrideProperty>(extraOverride);

            l.Add(new CustomOverrideProperty("skill", () =>
            {
                EditorGUILayout.BeginHorizontal();

                GUILayout.Label("plyGame skill", GUILayout.Width(EditorGUIUtility.labelWidth));
                ObjectPickerUtility.RenderObjectPickerForType <Skill>("", t.skill, skill =>
                {
                    t.skill     = skill;
                    GUI.changed = true;
                });

                EditorGUILayout.EndHorizontal();
            }));

            base.OnCustomInspectorGUI(l.ToArray());
        }
        public static void CurrencyDecorator(string name, CurrencyDecorator currencyDecorator)
        {
            EditorGUILayout.BeginHorizontal();

            if (currencyDecorator.amount > 0f && currencyDecorator.currency == null)
            {
                GUI.color = Color.red;
            }
            ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>(string.Empty, currencyDecorator.currency, (val) =>
            {
                currencyDecorator.currency = val;
            });

            GUI.color = Color.white;
            var prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 60;
            currencyDecorator.amount    = EditorGUILayout.FloatField("Amount", currencyDecorator.amount);
            EditorGUIUtility.labelWidth = prevLabelWidth;

            EditorGUILayout.EndHorizontal();
        }
Ejemplo n.º 22
0
        protected override void DrawDetail(ItemCategory item, int index)
        {
            EditorGUIUtility.labelWidth = EditorStyles.labelWidth;
            RenameScriptableObjectIfNeeded(item, item.name);

            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            EditorGUILayout.LabelField("ID", item.ID.ToString());
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("The name of the category, is displayed in the tooltip in UI elements.", EditorStyles.labelStyle);
            item.name = EditorGUILayout.DelayedTextField("TypeID", item.name);
            ObjectPickerUtility.RenderObjectPickerForType("Icon", item.icon, typeof(Sprite), val =>
            {
                item.icon = (Sprite)val;
            });

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            EditorGUILayout.LabelField("Items can have a 'global' cooldown. Whenever an item of this category is used, all items with the same category will go into cooldown.", EditorStyles.labelStyle);
            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("Note, that items can individually override the timeout.", EditorStyles.labelStyle);
            GUI.color         = Color.white;
            item.cooldownTime = EditorGUILayout.Slider("Cooldown time (seconds)", item.cooldownTime, 0.0f, 999.0f);
            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();


            ValidateItemFromCache(item);

            EditorGUIUtility.labelWidth = 0;
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            var r = position;

            r.width = 100;

            EditorGUI.PropertyField(r, property.FindPropertyRelative("restrictionType"), new GUIContent(""));

            r.x += r.width + 5;
            EditorGUI.PropertyField(r, property.FindPropertyRelative("filterType"), new GUIContent(""));


            int restrictionTypeIndex = property.FindPropertyRelative("restrictionType").enumValueIndex;
            var restrictionType      = (ItemFilter.RestrictionType)restrictionTypeIndex;

            int filterTypeIndex = property.FindPropertyRelative("filterType").enumValueIndex;

            ItemFilter.FilterType filterType = (ItemFilter.FilterType)filterTypeIndex;

            r.x    += r.width + 5;
            r.width = position.width - 210;


            var categoryValue = property.FindPropertyRelative("categoryValue");
            var propertyValue = property.FindPropertyRelative("statDefinitionValue");
            var rarityValue   = property.FindPropertyRelative("rarityValue");

            var stringValue = property.FindPropertyRelative("stringValue");
            var boolValue   = property.FindPropertyRelative("boolValue");
            var floatValue  = property.FindPropertyRelative("floatValue");

//            var intValue = property.FindPropertyRelative("intValue");

            switch (restrictionType)
            {
            case ItemFilter.RestrictionType.Type:

                //r.width -= 65;
                GUI.enabled = false;
                var t = System.Type.GetType(stringValue.stringValue);
                EditorGUI.LabelField(r, t != null ? t.Name : "(NOT SET)");
                GUI.enabled = true;

                r.x     += r.width - 60;
                r.width  = 60;
                r.height = 14;
                if (GUI.Button(r, "Set", "minibutton"))
                {
                    var typePicker = ScriptPickerEditor.Get(typeof(InventoryItemBase));
                    typePicker.Show();
                    typePicker.OnPickObject += type =>
                    {
                        stringValue.stringValue = type.AssemblyQualifiedName;
                        GUI.changed             = true; // To save..
                        stringValue.serializedObject.ApplyModifiedProperties();
                    };
                }

                break;

            case ItemFilter.RestrictionType.Stat:

                if (filterType == ItemFilter.FilterType.LessThan || filterType == ItemFilter.FilterType.GreatherThan)
                {
                    r.width /= 2;

                    ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(r, "", propertyValue);

                    r.x += r.width;
                    floatValue.floatValue = EditorGUI.FloatField(r, floatValue.floatValue);
                }
                else
                {
                    ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(r, "", propertyValue);
                }

                break;

            case ItemFilter.RestrictionType.Category:

                ObjectPickerUtility.RenderObjectPickerForType <ItemCategory>(r, "", categoryValue);
                break;

            case ItemFilter.RestrictionType.Rarity:

                ObjectPickerUtility.RenderObjectPickerForType <ItemRarity>(r, "", rarityValue);

                break;

            case ItemFilter.RestrictionType.Weight:
                floatValue.floatValue = EditorGUI.FloatField(r, floatValue.floatValue);
                break;

            case ItemFilter.RestrictionType.Sellable:
            case ItemFilter.RestrictionType.Storable:
            case ItemFilter.RestrictionType.Droppable:
                boolValue.boolValue = EditorGUI.Toggle(r, boolValue.boolValue);
                break;

            default:
                break;
            }

            EditorGUI.EndProperty();
        }
Ejemplo n.º 24
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            var l = new List <CustomOverrideProperty>(extraOverride);

            l.Add(new CustomOverrideProperty(equipmentType.name, () =>
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("EquippedItem type", GUILayout.Width(EditorGUIUtility.labelWidth - 5));

                EditorGUILayout.BeginVertical();
                EditorGUILayout.HelpBox("Edit types in the EquippedItem editor", MessageType.Info);
                ObjectPickerUtility.RenderObjectPickerForType <EquipmentType>(equipmentType);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }));
            l.Add(new CustomOverrideProperty(equipVisually.name, () =>
            {
                EditorGUILayout.PropertyField(equipVisually);
            }));
            l.Add(new CustomOverrideProperty(equipPosition.name, () =>
            {
                GUI.enabled = equipVisually.boolValue;

                if (currentEquippable == null)
                {
                    if (GUILayout.Button("Position now"))
                    {
                        player = GetPlayer();
                        if (player != null)
                        {
                            player.characterUI.character = player;
                            player.characterUI.IndexManuallyDefinedCollection();
                            player.characterUI.UpdateEquippableSlots();

                            UnityEngine.Object prefab = GetPrefabFor(target);

                            if (prefab == null)
                            {
                                Debug.LogError("prefab == null");
                            }

                            var instance = PrefabUtility.InstantiatePrefab(prefab);
                            if (instance == null)
                            {
                                Debug.LogError("instance == null");
                            }

                            currentEquippable = (EquippableInventoryItem)instance;
                            if (currentEquippable == null)
                            {
                                Debug.LogError("currentEquippable == null");
                            }

                            currentBinder = player.equipmentHandler.FindEquipmentLocation(player.equipmentHandler.FindEquippableSlotForItem(currentEquippable));
                            if (currentBinder == null)
                            {
                                Debug.Log("No suitable equip location found");
                                UnityEngine.Object.DestroyImmediate(currentEquippable.gameObject);
                                return;
                            }

                            currentBinder.equippableSlot.equipmentTypes.First(o => o == currentEquippable.equipmentType).equipmentHandler.Equip(currentEquippable, currentBinder, false);

                            currentEquippable.transform.localPosition = equipPosition.vector3Value;
                            currentEquippable.transform.localRotation = equipRotation.quaternionValue;

                            Selection.activeObject = currentEquippable.gameObject;
                            if (SceneView.currentDrawingSceneView != null)
                            {
                                SceneView.currentDrawingSceneView.LookAt(currentEquippable.transform.position);
                            }
                        }
                    }
                }
                else
                {
                    // Ugly workaround...
                    if (currentBinder != null && currentEquippable.transform.parent == null)
                    {
                        currentBinder.equippableSlot.equipmentTypes.First(o => o == currentEquippable.equipmentType).equipmentHandler.Equip(currentEquippable, currentBinder, false);
                    }

                    GUI.color = Color.green;
                    if (GUILayout.Button("Save state"))
                    {
                        equipPosition.vector3Value    = currentEquippable.transform.localPosition;
                        equipRotation.quaternionValue = currentEquippable.transform.localRotation;

                        serializedObject.ApplyModifiedProperties();
#if UNITY_2018_3_OR_NEWER
                        PrefabUtility.ApplyPrefabInstance(currentEquippable.gameObject, InteractionMode.AutomatedAction);
#endif
                        AssetDatabase.SaveAssets();                     // Save it

                        DestroyImmediate(currentEquippable.gameObject); // Get rid of positioning object
                        //SceneView.currentDrawingSceneView.SetSceneViewFiltering(false);
                    }
                    GUI.color = Color.white;
                }

                if (currentEquippable != null)
                {
                    GUI.enabled = false;
                }

                GUILayout.Space(5);
                EditorGUILayout.BeginHorizontal(EditorStyles.boxStyle);

                EditorGUILayout.PropertyField(equipPosition);
                GUILayout.Space(20);
                equipRotation.quaternionValue = ToQuat(EditorGUILayout.Vector4Field("EquippedItem Rotation", ToVec4(equipRotation.quaternionValue)));

                EditorGUILayout.EndHorizontal();
                GUILayout.Space(10);

                GUI.enabled = true;
            }));
            l.Add(new CustomOverrideProperty(equipRotation.name, null));

            base.OnCustomInspectorGUI(l.ToArray());
        }
        protected override void DrawDetail(CurrencyDefinition currency, int itemIndex)
        {
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);
            EditorGUIUtility.labelWidth = EditorStyles.labelWidth;
            RenameScriptableObjectIfNeeded(currency, currency.singleName);

            EditorGUILayout.LabelField("#" + currency.ID);
            if (currency.singleName == "")
            {
                GUI.color = Color.red;
            }

            currency.singleName = EditorGUILayout.DelayedTextField("Single name", currency.singleName);
            GUI.color           = Color.white;

            if (currency.pluralName == "")
            {
                GUI.color = Color.red;
            }

            currency.pluralName = EditorGUILayout.TextField("Plural name", currency.pluralName);
            GUI.color           = Color.white;

            currency.description    = EditorGUILayout.TextField("Description", currency.description);
            currency.allowFractions = EditorGUILayout.Toggle("Allow fractions", currency.allowFractions);

            ObjectPickerUtility.RenderObjectPickerForType("Icon", currency.icon, typeof(Sprite), val =>
            {
                currency.icon = (Sprite)val;
            });

            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("You can use string.Format elements to define the text formatting of the currency: ", EditorStyles.labelStyle);
            EditorGUILayout.LabelField("{0} = The current amount");
            EditorGUILayout.LabelField("{1} = Min min amount");
            EditorGUILayout.LabelField("{2} = The max amount");
            EditorGUILayout.LabelField("{3} = Single / plural name (depends on amount)");
            GUI.color             = Color.white;
            currency.stringFormat = EditorGUILayout.TextField("String format", currency.stringFormat);

            EditorGUILayout.LabelField("Format example (single): ", currency.ToString(1, 0.0f, 10f));
            EditorGUILayout.LabelField("Format example (pural): ", currency.ToString(100f, 0.0f, 100f));

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Conversions", EditorStyles.titleStyle);


            EditorGUILayout.LabelField("Currencies can be converted between one another. For example convert 1 Japanese yen to 0.008 dollars.", EditorStyles.labelStyle);
            if (currency.autoConvertOnMaxCurrency != null &&
                currency.currencyConversions.Any(o => o.currency == currency.autoConvertOnMaxCurrency) == false &&
                currency.autoConvertOnMax)
            {
                EditorGUILayout.HelpBox("Auto convert on max currency " + currency.autoConvertOnMaxCurrency.pluralName + " not in list. Can't convert currency", MessageType.Error);
            }

            if (currency.autoConvertFractionsToCurrency != null &&
                currency.currencyConversions.Any(o => o.currency == currency.autoConvertFractionsToCurrency) == false &&
                currency.autoConvertFractions && currency.allowFractions == false)
            {
                EditorGUILayout.HelpBox("Auto convert on fractions " + currency.autoConvertFractionsToCurrency.pluralName + " not in list. Can't convert currency", MessageType.Error);
            }

            EditorGUILayout.LabelField("Make sure you order conversions based on priority.", EditorStyles.labelStyle);
            _currencyConversionList.DoLayoutList();


            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Automatic conversions", EditorStyles.titleStyle);

            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("When a currency hits the maximum amount auto. convert it to another currency.", EditorStyles.labelStyle);
            EditorGUILayout.LabelField("For example, in some games you have copper, silver and gold. You can never have more than 99 coper, because it's converted to silver.", EditorStyles.labelStyle);
            GUI.color = Color.white;

            currency.autoConvertOnMax = EditorGUILayout.Toggle("Auto convert on max", currency.autoConvertOnMax);
            if (currency.autoConvertOnMax)
            {
                currency.autoConvertOnMaxAmount = EditorGUILayout.FloatField("Auto convert on max amount", currency.autoConvertOnMaxAmount);

                if (currency.autoConvertOnMaxCurrency == currency)
                {
                    GUI.color = Color.red;
                }

                ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>("Auto convert on max currency", currency.autoConvertOnMaxCurrency, (val) =>
                {
                    currency.autoConvertOnMaxCurrency = val;
                });

                GUI.color = Color.white;
                if (currency.autoConvertOnMaxCurrency == currency)
                {
                    EditorGUILayout.HelpBox("Can't auto convert to self", MessageType.Error);
                }
            }

            if (currency.allowFractions == false)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();

                GUI.color = Color.yellow;
                EditorGUILayout.LabelField("When a fraction is introduced convert it to a lower currency.");
                EditorGUILayout.LabelField("For example, in some games you have copper, silver and gold. When an attempt is done to add 1.1 silver, add 1 silver and 10 copper (converting the fraction to 10 copper).", EditorStyles.labelStyle);
                EditorGUILayout.LabelField("When this option is disabled fractions will be discarded.");
                GUI.color = Color.white;

                currency.autoConvertFractions = EditorGUILayout.Toggle("Auto convert fractions", currency.autoConvertFractions);
                if (currency.autoConvertFractions)
                {
                    ObjectPickerUtility.RenderObjectPickerForType <CurrencyDefinition>("Auto convert fractions to currency", currency.autoConvertFractionsToCurrency, (val) =>
                    {
                        currency.autoConvertFractionsToCurrency = val;
                    });
                }
            }



            EditorGUILayout.EndVertical();


            ValidateItemFromCache(currency);
        }
Ejemplo n.º 26
0
        protected override void DrawDetail(CraftingBlueprint selectedBlueprint, int index)
        {
            EditorGUIUtility.labelWidth = EditorStyles.labelWidth;
            // RenameScriptableObjectIfNeeded(selectedBlueprint, selectedBlueprint.ID + "_" + selectedBlueprint.name.Replace(",", "_").Replace(" ", "_"));

            UpdateBlueprintID(selectedBlueprint);

            #region About craft

            EditorGUILayout.LabelField("Step 1. What are we crafting?", EditorStyles.titleStyle);

            var    itemRow = selectedBlueprint.resultItems.FirstOrDefault();
            string name    = "";
            string desc    = "";
            string cat     = "";
            if (itemRow.item != null)
            {
                name = itemRow.item.name;
                desc = itemRow.item.description;
                cat  = itemRow.item.categoryName;
            }

            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            selectedBlueprint.useItemResultNameAndDescription = EditorGUILayout.Toggle("Use result item's name", selectedBlueprint.useItemResultNameAndDescription);
            if (selectedBlueprint.useItemResultNameAndDescription == false)
            {
                selectedBlueprint.customName        = EditorGUILayout.DelayedTextField("Blueprint name", selectedBlueprint.customName);
                selectedBlueprint.customDescription = EditorGUILayout.TextField("Blueprint description", selectedBlueprint.customDescription);
                GUI.enabled = false;

                EditorGUILayout.TextField("Category", cat);
            }
            else
            {
                GUI.enabled = false;

                EditorGUILayout.DelayedTextField("Blueprint name", name);
                EditorGUILayout.TextField("Blueprint description", desc);
                EditorGUILayout.TextField("Category", cat);
            }
            GUI.enabled = true;

            EditorGUILayout.EndVertical();

            #endregion

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            #region Crafting process

            EditorGUILayout.LabelField("Step 2. How are we crafting it?", EditorStyles.titleStyle);

            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            selectedBlueprint.playerLearnedBlueprint    = EditorGUILayout.Toggle("Player learned blueprint", selectedBlueprint.playerLearnedBlueprint);
            selectedBlueprint.successChanceFactor       = EditorGUILayout.Slider("Chance factor", selectedBlueprint.successChanceFactor, 0.0f, 1.0f);
            selectedBlueprint.craftingTimeDuration      = EditorGUILayout.FloatField("Crafting time duration (seconds)", selectedBlueprint.craftingTimeDuration);
            selectedBlueprint.craftingTimeSpeedupFactor = EditorGUILayout.FloatField("Speedup factor", selectedBlueprint.craftingTimeSpeedupFactor);
            selectedBlueprint.craftingTimeSpeedupMax    = EditorGUILayout.FloatField("Max speedup", selectedBlueprint.craftingTimeSpeedupMax);

            if (selectedBlueprint.craftingTimeSpeedupFactor != 1.0f)
            {
                EditorGUILayout.Space();

                for (int i = 1; i < 16; i++)
                {
                    float f = Mathf.Clamp(Mathf.Pow(selectedBlueprint.craftingTimeSpeedupFactor, i * 5), 0.0f, selectedBlueprint.craftingTimeSpeedupMax);

                    if (f != selectedBlueprint.craftingTimeSpeedupMax)
                    {
                        EditorGUILayout.LabelField("Speedup after \t" + (i * 5) + " crafts \t" + System.Math.Round(f, 2) + "x \t(" + System.Math.Round(selectedBlueprint.craftingTimeDuration / f, 2) + "s per item)");
                    }
                }

                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Reached max after " + 1.0f / Mathf.Log(selectedBlueprint.craftingTimeSpeedupFactor, selectedBlueprint.craftingTimeSpeedupMax) + " crafts");
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Step 3. What items does the user need? (Ignore if using layouts)", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            if (selectedBlueprint.craftingCost != null)
            {
                InventoryEditorUtility.CurrencyDecorator("Crafting cost", selectedBlueprint.craftingCost);
            }

            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            _requiredItemsList.DoLayoutList();
            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            _usageRequirementPropertiesList.DoLayoutList();

            #endregion

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            #region Craft result

            EditorGUILayout.LabelField("Step 4. What's the result?", EditorStyles.titleStyle);

            EditorGUILayout.BeginVertical();
            _resultItemsList.DoLayoutList();
            EditorGUILayout.EndVertical();

            #endregion

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            #region Layout editor

            EditorGUILayout.LabelField("Step 5. (optional) Define the layouts to use", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            int counter = 0;
            foreach (var l in selectedBlueprint.blueprintLayouts)
            {
                EditorGUILayout.BeginVertical(EditorStyles.boxStyle);
                EditorGUILayout.BeginHorizontal();

                l.enabled = EditorGUILayout.BeginToggleGroup("Layout #" + l.ID + "-" + (l.enabled ? "(enabled)" : "(disabled)"), l.enabled);
                EditorGUILayout.BeginHorizontal();

                GUI.color = Color.red;
                if (GUILayout.Button("Delete"))
                {
                    var t = new List <CraftingBlueprintLayout>(selectedBlueprint.blueprintLayouts);
                    t.RemoveAt(counter);
                    selectedBlueprint.blueprintLayouts = t.ToArray();

                    AssetDatabase.SaveAssets();
                }
                GUI.color = Color.white;
                EditorGUILayout.EndHorizontal();
                //EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginVertical();
                if (l.enabled)
                {
                    foreach (var r in l.rows)
                    {
                        EditorGUILayout.BeginHorizontal();
                        foreach (var c in r.columns)
                        {
                            if (c.item != null)
                            {
                                GUI.color = Color.green;
                            }

                            EditorGUILayout.BeginVertical("box", GUILayout.Width(80), GUILayout.Height(80));

                            EditorGUILayout.LabelField((c.item != null) ? c.item.name : string.Empty, EditorStyles.labelStyle);
                            c.amount = EditorGUILayout.IntField(c.amount);

                            if (GUILayout.Button("Set", GUILayout.Width(80)))
                            {
                                var clickedItem = c;
                                ObjectPickerUtility.GetObjectPickerForType <InventoryItemBase>(item => {
                                    clickedItem.item   = item;
                                    clickedItem.amount = 1;
                                    GUI.changed        = true;
                                    window.Repaint();
                                });

                                //layoutObjectPickerSetFor = c;
                                //EditorGUIUtility.ShowObjectPicker<UnityEngine.Object>(null, false, "l:InventoryItemPrefab", 61);
                            }
                            if (GUILayout.Button("Clear", UnityEditor.EditorStyles.miniButton))
                            {
                                c.amount = 0;
                                c.item   = null;
                            }

                            EditorGUILayout.EndVertical();

                            GUI.color = Color.white;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndToggleGroup();

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
                counter++;
            }

            if (GUILayout.Button("Add layout"))
            {
                var l   = new List <CraftingBlueprintLayout>(selectedBlueprint.blueprintLayouts);
                var obj = new CraftingBlueprintLayout();

                obj.ID   = l.Count;
                obj.rows = new CraftingBlueprintLayout.Row[category.rows];
                for (int i = 0; i < obj.rows.Length; i++)
                {
                    obj.rows[i]         = new CraftingBlueprintLayout.Row();
                    obj.rows[i].index   = i;
                    obj.rows[i].columns = new CraftingBlueprintLayout.Row.Cell[category.cols];

                    for (int j = 0; j < obj.rows[i].columns.Length; j++)
                    {
                        obj.rows[i].columns[j]       = new CraftingBlueprintLayout.Row.Cell();
                        obj.rows[i].columns[j].index = j;
                    }
                }

                l.Add(obj);
                selectedBlueprint.blueprintLayouts = l.ToArray();
            }

            EditorGUILayout.EndVertical();
            #endregion

            GUI.enabled = true; // From layouts
            EditorGUIUtility.labelWidth = 0;
        }
Ejemplo n.º 27
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            base.OnCustomInspectorGUI(extraOverride);

            if (serializedObject == null || target == null)
            {
                return;
            }

            serializedObject.Update();
            overrides = extraOverride;

            // Can't go below 0
            if (cooldownTime.floatValue < 0.0f)
            {
                cooldownTime.floatValue = 0.0f;
            }

            GUI.color = Color.yellow;
            var item = (InventoryItemBase)target;

            if (item.gameObject.activeInHierarchy && item.rarity != null && item.rarity.dropObject != null)
            {
                if (GUILayout.Button("Convert to drop object"))
                {
                    var dropObj      = item.rarity.dropObject;
                    var dropInstance = (GameObject)PrefabUtility.InstantiatePrefab(dropObj.gameObject);
                    var itemTrigger  = dropInstance.AddComponent <ItemTrigger>();

                    var t = target;
                    if (t == null)
                    {
                        t = PrefabUtility.GetPrefabParent(t);
                    }

                    string path  = AssetDatabase.GetAssetPath(t);
                    var    asset = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
                    if (asset != null)
                    {
                        itemTrigger.itemPrefab = asset.GetComponent <InventoryItemBase>();

                        dropInstance.transform.SetParent(item.transform.parent);
                        dropInstance.transform.SetSiblingIndex(item.transform.GetSiblingIndex());
                        dropInstance.transform.position = item.transform.position;
                        dropInstance.transform.rotation = item.transform.rotation;

                        Selection.activeGameObject = itemTrigger.gameObject;

                        item.StartCoroutine(DestroyImmediateThis(item));
                    }

                    return;
                }
            }
            GUI.color = Color.white;

            if (target == null)
            {
                return;
            }

            var excludeList = new List <string>()
            {
                "m_Script",
                id.name,
                itemName.name,
                description.name,
                stats.name,
                usageRequirements.name,
                useCategoryCooldown.name,
                overrideDropObjectPrefab.name,
                category.name,
                icon.name,
                weight.name,
                layoutSizeCols.name,
                layoutSizeRows.name,
                requiredLevel.name,
                rarity.name,
                buyPrice.name,
                sellPrice.name,
                isDroppable.name,
                isSellable.name,
                isStorable.name,
                maxStackSize.name,
                cooldownTime.name,
            };

            GUILayout.Label("Default", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);
            if (FindOverride(id.name) != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.LabelField("ID: ", id.intValue.ToString());
            GUI.enabled = true;

            if (FindOverride(itemName.name) != null)
            {
                GUI.enabled = false;
            }

            GUI.SetNextControlName("ItemEditor_itemName");
            Devdog.General.Editors.EditorUtility.EditableLabel(itemName, false, MarkToSave);

            GUI.enabled = true;

            if (FindOverride(description.name) != null)
            {
                GUI.enabled = false;
            }

            Devdog.General.Editors.EditorUtility.EditableLabel(description, true, MarkToSave, "Note, that you can use rich text like <b>asd</b> to write bold text and <i>Potato</i> to write italic text.");

            GUI.enabled = true;

            EditorGUILayout.PropertyField(icon);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Item layout");

            EditorGUILayout.BeginVertical();
            for (int i = 1; i < 7; i++)
            {
                EditorGUILayout.BeginHorizontal();
                for (int j = 1; j < 7; j++)
                {
                    if (layoutSizeCols.intValue < j || layoutSizeRows.intValue < i)
                    {
                        GUI.color = Color.gray;
                    }

                    var c = new GUIStyle("CN Box");
                    c.alignment = TextAnchor.MiddleCenter;
                    if (GUILayout.Button(j + " X " + i, c, GUILayout.Width(40), GUILayout.Height(40)))
                    {
                        layoutSizeCols.intValue = j;
                        layoutSizeRows.intValue = i;
                    }

                    GUI.color = Color.white;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            if (item.icon != null)
            {
                var a = item.icon.bounds.size.x / item.icon.bounds.size.y;
                var b = (float)item.layoutSizeCols / item.layoutSizeRows;

                if (Mathf.Approximately(a, b) == false)
                {
                    EditorGUILayout.HelpBox("Layout size is different from icon aspect ratio.", MessageType.Warning);
                }
            }

#if RELATIONS_INSPECTOR
            if (GUILayout.Button("Show relations", GUILayout.ExpandWidth(false)))
            {
                EditorWindow
                .GetWindow <RelationsInspector.RelationsInspectorWindow>()
                .GetAPI1
                .ResetTargets(new [] { t }, typeof(RelationsInspector.InventoryProBackends.ItemBackend));
            }
#endif

            EditorGUILayout.EndVertical();

            // Draws remaining items
            GUILayout.Label("Item specific", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            foreach (var x in extraOverride)
            {
                if (x.action != null)
                {
                    x.action();
                }

                excludeList.Add(x.serializedName);
            }

            DrawPropertiesExcluding(serializedObject, excludeList.ToArray());
            EditorGUILayout.EndVertical();

            #region Properties

            GUILayout.Label("Item stats", EditorStyles.titleStyle);
            GUILayout.Label("You can create stats in the Item editor / Item stats editor");

            EditorGUILayout.BeginVertical();
            _statsList.DoLayoutList();
            EditorGUILayout.EndVertical();

            GUILayout.Label("Usage requirement stats", EditorStyles.titleStyle);
            GUILayout.Label("Add stats the user is required to have in order to use this item.");
            GUILayout.Label("Example: Usage stat of 10 strength means:");
            GUILayout.Label("The user can only use this item if he/she has 10 or more strength.");

            EditorGUILayout.BeginVertical();
            _usageRequirementList.DoLayoutList();
            EditorGUILayout.EndVertical();

            #endregion

            GUILayout.Label("Behavior", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            GUILayout.Label("Details", EditorStyles.titleStyle);
            if (rarity.objectReferenceValue != null)
            {
                var color = ((ItemRarity)rarity.objectReferenceValue).color;
                color.a   = 1.0f;               // Ignore alpha in the editor.
                GUI.color = color;
            }

            ObjectPickerUtility.RenderObjectPickerForType <ItemRarity>(rarity);
            GUI.color = Color.white;

            ObjectPickerUtility.RenderObjectPickerForType <ItemCategory>(category);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(useCategoryCooldown);
            if (useCategoryCooldown.boolValue)
            {
                if (category.objectReferenceValue != null)
                {
                    var c = (ItemCategory)category.objectReferenceValue;
                    EditorGUILayout.LabelField(string.Format("({0} seconds)", c.cooldownTime));
                }
            }

            EditorGUILayout.EndHorizontal();
            if (useCategoryCooldown.boolValue == false)
            {
                EditorGUILayout.PropertyField(cooldownTime);
            }

            EditorGUILayout.PropertyField(overrideDropObjectPrefab);

            GameObject dropPrefab = null;
            if (overrideDropObjectPrefab.objectReferenceValue != null)
            {
                EditorGUILayout.HelpBox("Overriding drop object to: " + overrideDropObjectPrefab.objectReferenceValue.name, MessageType.Info);
                dropPrefab = (GameObject)overrideDropObjectPrefab.objectReferenceValue;
            }
            else if (item.rarity != null && item.rarity.dropObject != null)
            {
                EditorGUILayout.HelpBox("Using rarity drop object: " + item.rarity.dropObject.name, MessageType.Info);
                dropPrefab = item.rarity.dropObject;
            }
            else
            {
                EditorGUILayout.HelpBox("No drop object set.", MessageType.Info);
                dropPrefab = item.gameObject;
            }

            if (dropPrefab.GetComponentsInChildren <Collider>(true).Any(o => o.isTrigger) == false && dropPrefab.GetComponentsInChildren <Collider2D>(true).Any(o => o.isTrigger) == false)
            {
                EditorGUILayout.HelpBox("Drop object has no triggers and therefore can never be picked up!", MessageType.Error);
            }

            GUILayout.Label("Buying & Selling", EditorStyles.titleStyle);
            //            EditorGUILayout.BeginHorizontal();
            //            EditorGUILayout.LabelField("Buy price", GUILayout.Width(EditorStyles.labelWidth));
            EditorGUILayout.PropertyField(buyPrice);
            //            EditorGUILayout.EndHorizontal();

            //            EditorGUILayout.BeginHorizontal();
            //            EditorGUILayout.LabelField("Sell price", GUILayout.Width(EditorStyles.labelWidth));
            EditorGUILayout.PropertyField(sellPrice);
            //            EditorGUILayout.EndHorizontal();

            GUILayout.Label("Restrictions", EditorStyles.titleStyle);
            EditorGUILayout.PropertyField(isDroppable);
            EditorGUILayout.PropertyField(isSellable);
            EditorGUILayout.PropertyField(isStorable);
            EditorGUILayout.PropertyField(maxStackSize);
            EditorGUILayout.PropertyField(weight);
            EditorGUILayout.PropertyField(requiredLevel);

            EditorGUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
        public static void DrawStatDecorator(Rect rect, SerializedProperty stat, bool isActive, bool isFocused, bool drawRestore, bool drawPercentage)
        {
            rect.height = 16;
            rect.y     += 2;

            var r2 = rect;

            r2.y     += 20;
            r2.width /= 2;
            r2.width -= 5;

            var popupRect = rect;

            popupRect.width /= 2;
            popupRect.width -= 5;

            var prop         = stat.FindPropertyRelative("_stat");
            var propIsFactor = stat.FindPropertyRelative("isFactor");
            var propValue    = stat.FindPropertyRelative("value");
            var propEffect   = stat.FindPropertyRelative("actionEffect");

            ObjectPickerUtility.RenderObjectPickerForType <StatDefinition>(popupRect, string.Empty, prop);

            popupRect.x += popupRect.width;
            popupRect.x += 5;

            if (propIsFactor.boolValue)
            {
                popupRect.width -= 65;

                propValue.stringValue = EditorGUI.TextField(popupRect, "", propValue.stringValue);

                var p = popupRect;
                p.x    += popupRect.width + 5;
                p.width = 60;

                float floatVal;
                float.TryParse(propValue.stringValue, out floatVal);

                EditorGUI.LabelField(p, "(" + (floatVal - 1.0f) * 100.0f + "%)");
            }
            else
            {
                propValue.stringValue = EditorGUI.TextField(popupRect, "", propValue.stringValue);
            }

            if (drawRestore)
            {
                var r3 = r2;
                r3.width /= 2;
                r3.width -= 5;
                EditorGUI.LabelField(r3, "Action effect");

                r3.x += r3.width + 5;
                EditorGUI.PropertyField(r3, propEffect, new GUIContent(""));

                r2.x += r2.width + 5;
            }

            if (drawPercentage)
            {
                propIsFactor.boolValue = EditorGUI.Toggle(r2, "Is factor (multiplier 0...1)", propIsFactor.boolValue);
                r2.x += r2.width + 5;
            }


            GUI.enabled = true;
        }
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            var l = new List <CustomOverrideProperty>(extraOverride);

            l.Add(new CustomOverrideProperty("_equipmentType", () =>
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("EquippedItem type", GUILayout.Width(EditorGUIUtility.labelWidth - 5));

                EditorGUILayout.BeginVertical();
                EditorGUILayout.HelpBox("Edit types in the EquippedItem editor", MessageType.Info);
                ObjectPickerUtility.RenderObjectPickerForType <EquipmentType>(string.Empty, equipType);
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
            }));
            l.Add(new CustomOverrideProperty("equipVisually", null));
            l.Add(new CustomOverrideProperty("equipPosition", null));
            l.Add(new CustomOverrideProperty("equipRotation", null));


            l.Add(new CustomOverrideProperty(equipSlotsData.name, () =>
            {
                reorderableList.DoLayoutList();
            }));

//            l.Add(new CustomOverrideProperty(umaEquipSlot.name, () =>
//                {
//                    EditorGUILayout.PropertyField(umaEquipSlot);
//                    EditorGUILayout.Space();
//                }));
//            l.Add(new CustomOverrideProperty(umaOverrideColor.name, () => EditorGUILayout.PropertyField(umaOverrideColor)));
//            l.Add(new CustomOverrideProperty(umaOverlayColor.name, () =>
//                {
//                    if (umaOverrideColor.boolValue)
//                    {
//                        EditorGUILayout.PropertyField(umaOverlayColor);
//                    }
//
//                    EditorGUILayout.Space();
//                }));
//            l.Add(new CustomOverrideProperty(umaOverlayDataAsset.name, () => EditorGUILayout.PropertyField(umaOverlayDataAsset)));
//            l.Add(new CustomOverrideProperty(umaSlotDataAsset.name, () => EditorGUILayout.PropertyField(umaSlotDataAsset)));
//            l.Add(new CustomOverrideProperty(umaReplaceSlot.name, () =>
//                {
//                    EditorGUILayout.PropertyField(umaReplaceSlot);
//
//                    string msg = "";
//                    if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue == null && umaReplaceSlot.objectReferenceValue == null)
//                    {
//                        msg = "Equipping UMA object to equip slot";
//                    }
//                    else if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue != null && umaReplaceSlot.objectReferenceValue == null)
//                    {
//                        msg = "Equipping UMA object to a new slot that will be created at run-time if it doesn't exist yet.";
//                    }
//                    else if (umaOverlayDataAsset.objectReferenceValue != null && umaSlotDataAsset.objectReferenceValue != null && umaReplaceSlot.objectReferenceValue != null)
//                    {
//                        msg = "Equipping UMA object to a new slot that will be created at run-time if it doesn't exist yet.\nReplacing slot " + umaReplaceSlot.objectReferenceValue.ToString() + " while equipped.";
//                    }
//
//                    EditorGUILayout.HelpBox(msg, MessageType.Info);
//                }));
//



            base.OnCustomInspectorGUI(l.ToArray());
        }
Ejemplo n.º 30
0
        public override void EditItem(CraftingBlueprint item, int itemIndex)
        {
            base.EditItem(item, itemIndex);

            _requiredItemsList = new UnityEditorInternal.ReorderableList(item.requiredItems, typeof(ItemAmountRow), true, true, true, true);
            _requiredItemsList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Required items");
            _requiredItemsList.drawElementCallback += (rect, index, active, focused) => {
                rect.height = 16;
                rect.y     += 2;

                var r2 = rect;
                r2.width /= 2;
                r2.width -= 5;

                if (item.requiredItems[index].amount < 1)
                {
                    item.requiredItems[index].SetAmount(1);
                }

                item.requiredItems[index].SetAmount((uint)EditorGUI.IntField(r2, (int)item.requiredItems[index].amount));

                r2.x += r2.width + 5;

                if (item.requiredItems[index].item == null)
                {
                    GUI.backgroundColor = Color.red;
                }

                ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(r2, "", item.requiredItems[index].item,
                                                                                  newItem => {
                    item.requiredItems[index].SetItem(newItem);
                    GUI.changed = true;     // To save..
                    //                        window.Repaint();
                });

                GUI.backgroundColor = Color.white;
            };
            _requiredItemsList.onAddCallback += list => {
                var l = new List <ItemAmountRow>(item.requiredItems)
                {
                    new ItemAmountRow()
                };

                item.requiredItems = l.ToArray();
                list.list          = item.requiredItems;

                window.Repaint();
            };
            _requiredItemsList.onRemoveCallback += list => {
                var l = new List <ItemAmountRow>(item.requiredItems);
                l.RemoveAt(list.index);
                item.requiredItems = l.ToArray();
                list.list          = item.requiredItems;

                window.Repaint();
            };

            _resultItemsList = new UnityEditorInternal.ReorderableList(item.resultItems, typeof(ItemAmountRow), true, true, true, true);
            _resultItemsList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Result items");
            _resultItemsList.drawElementCallback += (rect, index, active, focused) => {
                rect.height = 16;
                rect.y     += 2;

                var r2 = rect;
                r2.width /= 2;
                r2.width -= 5;

                if (item.resultItems[index].amount < 1)
                {
                    item.resultItems[index].SetAmount(1);
                }

                item.resultItems[index].SetAmount((uint)EditorGUI.IntField(r2, (int)item.resultItems[index].amount));

                r2.x += r2.width + 5;

                if (item.resultItems[index].item == null)
                {
                    GUI.backgroundColor = Color.red;
                }

                ObjectPickerUtility.RenderObjectPickerForType <InventoryItemBase>(r2, "", item.resultItems[index].item,
                                                                                  val => {
                    item.resultItems[index].SetItem(val);
                    GUI.changed = true;     // To save..
                    //                        window.Repaint();
                });

                GUI.backgroundColor = Color.white;
            };
            _resultItemsList.onAddCallback += list => {
                var l = new List <ItemAmountRow>(item.resultItems);
                l.Add(new ItemAmountRow());
                item.resultItems = l.ToArray();
                list.list        = item.resultItems;

                window.Repaint();
            };
            _resultItemsList.onRemoveCallback += list => {
                var l = new List <ItemAmountRow>(item.resultItems);
                l.RemoveAt(list.index);
                item.resultItems = l.ToArray();
                list.list        = item.resultItems;

                window.Repaint();
            };

            _usageRequirementPropertiesList = new UnityEditorInternal.ReorderableList(item.usageRequirement, typeof(StatRequirement), true, true, true, true);
            _usageRequirementPropertiesList.drawHeaderCallback  += rect => EditorGUI.LabelField(rect, "Stat requirements");
            _usageRequirementPropertiesList.elementHeight        = 42;
            _usageRequirementPropertiesList.drawElementCallback += (rect, index, active, focused) => {
                InventoryEditorUtility.DrawStatRequirement(rect, item.usageRequirement[index], active, focused, true);
            };
            _usageRequirementPropertiesList.onAddCallback += list => {
                var l = new List <StatRequirement>(item.usageRequirement);
                l.Add(new StatRequirement());
                item.usageRequirement = l.ToArray();
                list.list             = item.usageRequirement;

                window.Repaint();
            };
            _usageRequirementPropertiesList.onRemoveCallback += list => {
                var l = new List <StatRequirement>(item.usageRequirement);
                l.RemoveAt(list.index);
                item.usageRequirement = l.ToArray();
                list.list             = item.usageRequirement;

                window.Repaint();
            };
        }