Esempio n. 1
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();
     });
 }
Esempio n. 2
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;
                    });
                }
            }
        }
Esempio n. 3
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;
        }