public static BlueprintDatabase asset;                                                  //The List of all Blueprints

#if UNITY_EDITOR
        public static BlueprintDatabase createBlueprintDatabase()                                         //creates a new BlueprintDatabase(new instance)
        {
            asset = ScriptableObject.CreateInstance <BlueprintDatabase>();                                //of the ScriptableObject Blueprint

            AssetDatabase.CreateAsset(asset, "Assets/InventoryMaster/Resources/BlueprintDatabase.asset"); //in the Folder Assets/Resources/BlueprintDatabase.asset
            AssetDatabase.SaveAssets();                                                                   //and than saves it there
            asset.blueprints.Add(new Blueprint());
            return(asset);
        }
示例#2
0
        void BluePrintDataBase()
        {
            EditorGUILayout.BeginVertical("Box");
            if (bluePrintDatabase == null)
            {
                bluePrintDatabase = (BlueprintDatabase)Resources.Load("BlueprintDatabase");
            }

            GUILayout.BeginHorizontal();
            toolbarInt1 = GUILayout.Toolbar(toolbarInt1, toolbarStrings1, GUILayout.Width(position.width - 20));                                                    //creating a toolbar(tabs) to navigate what you wanna do
            GUILayout.EndHorizontal();
            scrollPosition1 = EditorGUILayout.BeginScrollView(scrollPosition1);
            GUILayout.Space(10);

            if (toolbarInt1 == 0)                                                                                                                              //if equal 0 than it is "Create Item"
            {
                GUI.color = Color.white;
                try
                {
                    GUILayout.BeginVertical("Box");
                    string[] items = new string[inventoryItemList.itemList.Count];                                                      //create a string array in length of the itemcount
                    for (int i = 1; i < items.Length; i++)                                                                              //go through the item array
                    {
                        items[i] = inventoryItemList.itemList[i].itemName;                                                              //and paste all names into the array
                    }
                    EditorGUILayout.BeginHorizontal();
                    finalItemID       = EditorGUILayout.Popup("Final Item", finalItemID, items, EditorStyles.popup);
                    amountOfFinalItem = EditorGUILayout.IntField("Value", amountOfFinalItem);
                    EditorGUILayout.EndHorizontal();
                    //timeToCraft = EditorGUILayout.FloatField("Time to craft", timeToCraft);
                    EditorGUILayout.Space();

                    EditorGUILayout.Space();
                    EditorGUI.BeginChangeCheck();
                    amountofingredients = EditorGUILayout.IntSlider("Ingredients", amountofingredients, 1, 50, GUILayout.Width(position.width - 38));
                    if (EditorGUI.EndChangeCheck())
                    {
                        ingredients = new int[amountofingredients];
                        amount      = new int[amountofingredients];
                    }
                    for (int i = 0; i < amountofingredients; i++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        ingredients[i] = EditorGUILayout.Popup("Ingredient " + i, ingredients[i], items, EditorStyles.popup, GUILayout.Width((position.width / 2) - 20));
                        amount[i]      = EditorGUILayout.IntField("Value", amount[i], GUILayout.Width((position.width / 2) - 20));

                        EditorGUILayout.EndHorizontal();
                    }
                    GUI.color = Color.green;
                    if (GUILayout.Button("Add Blueprint", GUILayout.Width(position.width - 35), GUILayout.Height(50)))
                    {
                        addBlueprint();
                    }

                    GUILayout.EndVertical();
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                }
            }

            if (toolbarInt1 == 1)
            {
                if (bluePrintDatabase == null)
                {
                    bluePrintDatabase = (BlueprintDatabase)Resources.Load("BlueprintDatabase");
                    if (bluePrintDatabase == null)
                    {
                        bluePrintDatabase = CreateBlueprintDatabase.createBlueprintDatabase();
                        bluePrintDatabase = (BlueprintDatabase)Resources.Load("BlueprintDatabase");
                    }
                }

                if (bluePrintDatabase.blueprints.Count == 1)
                {
                    GUILayout.Label("There is no Blueprint in the Database!");
                }
                else
                {
                    GUILayout.BeginVertical();
                    for (int i = 1; i < bluePrintDatabase.blueprints.Count; i++)
                    {
                        try
                        {
                            manageItem1.Add(false);
                            GUILayout.BeginVertical("Box", GUILayout.Width(position.width - 23));
                            manageItem1[i] = EditorGUILayout.Foldout(manageItem1[i], "" + bluePrintDatabase.blueprints[i].finalItem.itemName);       //create for every item which you have in the itemdatabase a foldout
                            if (manageItem1[i])                                                                                                      //if you press on it you get this
                            {
                                EditorGUI.indentLevel++;
                                EditorUtility.SetDirty(bluePrintDatabase);                                                                          //message the scriptableobject that you change something now
                                GUI.color = Color.red;                                                                                              //all upcoming GUIelements get changed to red
                                if (GUILayout.Button("Delete Blueprint", GUILayout.Width(position.width - 38)))                                     //create button that deletes the item
                                {
                                    bluePrintDatabase.blueprints.RemoveAt(i);                                                                       //remove the item out of the itemdatabase
                                    EditorUtility.SetDirty(bluePrintDatabase);                                                                      //and message the database again that you changed something
                                }

                                GUI.color = Color.white;
                                EditorUtility.SetDirty(bluePrintDatabase);
                                bluePrintDatabase.blueprints[i].amountOfFinalItem = EditorGUILayout.IntField("Amount of final items", bluePrintDatabase.blueprints[i].amountOfFinalItem, GUILayout.Width(position.width - 35));
                                //bluePrintDatabase.blueprints[i].timeToCraft = EditorGUILayout.FloatField("Time to craft", bluePrintDatabase.blueprints[i].timeToCraft);
                                EditorUtility.SetDirty(bluePrintDatabase);
                                string[] items = new string[inventoryItemList.itemList.Count];                                                      //create a string array in length of the itemcount
                                for (int z = 1; z < items.Length; z++)                                                                              //go through the item array
                                {
                                    items[z] = inventoryItemList.itemList[z].itemName;                                                              //and paste all names into the array
                                }
                                string[] categories       = new string[itemCategoryList.itemCategoryList.Count];
                                int      selectedCategory = 0;
                                for (int ic = 0; ic < itemCategoryList.itemCategoryList.Count; ic++)
                                {
                                    categories[ic] = itemCategoryList.itemCategoryList[ic].categoryName;
                                    if (categories[ic] == bluePrintDatabase.blueprints[i].itemCategory.categoryName)
                                    {
                                        selectedCategory = ic;
                                    }
                                }

                                bluePrintDatabase.blueprints[i].itemCategory = itemCategoryList.itemCategoryList[EditorGUILayout.Popup("Category", selectedCategory, categories, EditorStyles.popup)];

                                GUILayout.Label("Ingredients");
                                for (int k = 0; k < bluePrintDatabase.blueprints[i].ingredients.Count; k++)
                                {
                                    GUILayout.BeginHorizontal();
                                    GUI.color = Color.red;
                                    if (GUILayout.Button("-"))
                                    {
                                        bluePrintDatabase.blueprints[i].ingredients.RemoveAt(k);
                                    }
                                    GUI.color = Color.white;
                                    bluePrintDatabase.blueprints[i].ingredients[k] = EditorGUILayout.Popup("Ingredient " + (k + 1), bluePrintDatabase.blueprints[i].ingredients[k], items, EditorStyles.popup);
                                    bluePrintDatabase.blueprints[i].amount[k]      = EditorGUILayout.IntField("Value", bluePrintDatabase.blueprints[i].amount[k]);

                                    GUILayout.EndHorizontal();
                                }

                                GUI.color = Color.green;
                                if (GUILayout.Button("+"))
                                {
                                    bluePrintDatabase.blueprints[i].ingredients.Add(0);
                                    bluePrintDatabase.blueprints[i].amount.Add(0);
                                }
                                GUI.color = Color.white;
                                EditorGUI.indentLevel--;
                                EditorUtility.SetDirty(bluePrintDatabase);                                                                                              //message scriptable object that you have changed something
                            }
                            GUILayout.EndVertical();
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogError(ex.ToString());
                        }
                    }
                    GUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
示例#3
0
        //PlayerScript PlayerstatsScript;

        // Use this for initialization
        void Start()
        {
            blueprintDatabase = (BlueprintDatabase)Resources.Load("BlueprintDatabase");
            //playerStatsScript = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
        }