private void OnEnable()
    {
        large                 = new GUIStyle();
        large.fontSize        = 16;
        medium                = new GUIStyle();
        medium.fontSize       = 13;
        center                = new GUIStyle();
        center.alignment      = TextAnchor.MiddleCenter;
        largecenter           = new GUIStyle();
        largecenter.fontSize  = 16;
        largecenter.alignment = TextAnchor.MiddleCenter;

        if (CustomItemManager.items == null)
        {
            try
            {
                CustomItemManager.items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList(CustomItemManager.getResourcesFolderPrefix() + CustomItemManager.getDefaultListPath() + ".txt"));
            }
            catch
            {
                CustomItem[] temp = new CustomItem[1];
                CustomItem   newi = new CustomItem();
                newi.generationChance = 0.5f;
                newi.type             = "New Item";

                CustomItemManager.saveItemList(CustomItemManager.getDefaultListPath(), temp);
                CustomItemManager.items = temp;
            }
        }
    }
Пример #2
0
    public void PrepareItemList()
    {
        rand = new System.Random((int)(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond));


        if (!Application.isEditor)
        {
            items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList((String.IsNullOrEmpty(CustomListPath)) ? CustomItemManager.getDefaultListPath() : CustomListPath));
        }
        else
        {
            items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList((String.IsNullOrEmpty(CustomListPath)) ? CustomItemManager.getResourcesFolderPrefix() + CustomItemManager.getDefaultListPath() + ".txt": CustomItemManager.getResourcesFolderPrefix() + CustomListPath + ".txt"));
        }

        if (orderedItems == null)
        {
            orderedItems = CustomItemManager.reorderListByChance(items);
        }
    }
    void OnGUI()
    {
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.LabelField("PDT Random Item Spawner 1.2", largecenter);

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



        //
        //if(GUILayout.Button("Force Load"))
        //{
        //    gen.customItems = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList(CustomItemManager.getItemListPath()));
        //}

        if (GUILayout.Button("Add Custom Item Slot"))
        {
            try
            {
                //First try directly editing a correctly loaded list

                CustomItem[] temp = new CustomItem[CustomItemManager.items.Length + 1];
                CustomItem   newi = new CustomItem();
                newi.generationChance = 0.5f;
                newi.type             = "New Item";

                for (int i = 0; i < temp.Length; i++)
                {
                    if (i < CustomItemManager.items.Length)
                    {
                        temp[i] = CustomItemManager.items[i];
                    }
                    else
                    {
                        temp[i] = newi;
                    }
                }

                CustomItemManager.items = temp;
            }
            catch
            {
                //Then try loading list to see if it exists

                try
                {
                    CustomItemManager.items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList(CustomItemManager.getDefaultListPath()));

                    CustomItem[] temp = new CustomItem[CustomItemManager.items.Length + 1];
                    CustomItem   newi = new CustomItem();
                    newi.generationChance = 0.5f;
                    newi.type             = "New Item";

                    for (int i = 0; i < temp.Length; i++)
                    {
                        if (i < CustomItemManager.items.Length)
                        {
                            temp[i] = CustomItemManager.items[i];
                        }
                        else
                        {
                            temp[i] = newi;
                        }
                    }

                    CustomItemManager.items = temp;
                }
                catch
                {
                    //Finally create and save an entirely new list if all fails

                    CustomItem[] temp = new CustomItem[1];
                    CustomItem   newi = new CustomItem();
                    newi.generationChance = 0.5f;
                    newi.type             = "New Item";

                    CustomItemManager.saveItemList(CustomItemManager.getDefaultListPath(), temp);
                    CustomItemManager.items = temp;
                }
            }
        }

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        EditorGUIUtility.labelWidth = 1;
        EditorGUIUtility.fieldWidth = 0;
        GUILayout.Space(30);
        EditorGUILayout.LabelField("Type");
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Prefab");
        GUILayout.Space(20);
        EditorGUILayout.LabelField("Spawn Chance", GUILayout.Width(115));
        //GUILayout.Space(50);
        EditorGUILayout.LabelField("Pickupable?", GUILayout.Width(70));
        GUILayout.Space(10);
        EditorGUILayout.LabelField("Spawn Type", GUILayout.Width(90));
        //GUILayout.Space(20);
        EditorGUILayout.LabelField("Unique?");
        GUILayout.Space(20);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        scrollpos = EditorGUILayout.BeginScrollView(scrollpos);

        if (CustomItemManager.items != null)
        {
            for (int i = 0; i < CustomItemManager.items.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();

                EditorGUIUtility.labelWidth = 50;

                EditorGUIUtility.fieldWidth = 40;


                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    List <CustomItem> t = new List <CustomItem>(CustomItemManager.items);
                    t.RemoveAt(i);
                    CustomItemManager.items = t.ToArray();
                    continue;
                }
                CustomItemManager.items[i].type = EditorGUILayout.TextField(CustomItemManager.items[i].type, GUILayout.Width(55));
                GUILayout.Space(10);
                CustomItemManager.items[i].prefab           = (GameObject)EditorGUILayout.ObjectField("", CustomItemManager.items[i].prefab, typeof(GameObject), GUILayout.Width(70));
                EditorGUIUtility.labelWidth                 = 45;
                CustomItemManager.items[i].generationChance = EditorGUILayout.Slider("", CustomItemManager.items[i].generationChance, 0, 1, GUILayout.Width(140));
                GUILayout.Space(20);
                EditorGUIUtility.labelWidth           = 10;
                CustomItemManager.items[i].pickupable = EditorGUILayout.Toggle("", CustomItemManager.items[i].pickupable, GUILayout.Width(25));
                GUILayout.Space(10);
                CustomItemManager.items[i].spawntype = (CustomItemSpawnType)EditorGUILayout.EnumPopup(CustomItemManager.items[i].spawntype, GUILayout.Width(100));
                GUILayout.Space(20);
                CustomItemManager.items[i].unique = EditorGUILayout.Toggle("", CustomItemManager.items[i].unique, GUILayout.Width(25));

                EditorGUILayout.EndHorizontal();
            }
        }
        else
        {
            try
            {
                CustomItemManager.items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList(CustomItemManager.getDefaultListPath()));
            }
            catch
            {
            }
        }

        EditorGUILayout.EndScrollView();

        EditorGUILayout.Space();


        if (GUILayout.Button("Save Item List File..."))
        {
            string path = EditorUtility.SaveFilePanel("Save Item List File...", CustomItemManager.getResourcesFolderPrefix(), "ItemList", "txt");
            CustomItemManager.saveItemList(path, CustomItemManager.items);
        }

        if (GUILayout.Button("Load Item List File..."))
        {
            string path = EditorUtility.OpenFilePanel("Open Item List File...", CustomItemManager.getResourcesFolderPrefix(), "");
            CustomItemManager.items = CustomItemManager.initializeListPrefab(CustomItemManager.loadItemList(path));
        }
    }