예제 #1
0
    void OnGUI()
    {
        //Debug.Log (Application.dataPath);
        generalFold = EditorGUILayout.Foldout(generalFold, "General Settings");
        if (generalFold)
        {
            GUILayout.Label("General Settings", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Select the texture with the button below. Emission & Metallic textures are optional. Metallic shaders are experimental, expect issues.", MessageType.Info);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Image Texture");
            //This little void allows me to open a file prompt looking for .png files (Must support transparency at the moment)
            if (GUILayout.Button("Select", GUILayout.Width(200)))
            {
                string path = EditorUtility.OpenFilePanel("Select Texture", "", "png");
                if (path.Length != 0)
                {
                    //The magical and still confusing process of reading bytes from the file into a var.
                    var fileContent = File.ReadAllBytes(path);
                    //Loading that magical var into the Texture2D's image slot.
                    PantsTex.LoadImage(fileContent);
                    //This is the most important, as it applies the changes we have made to the texture.
                    PantsTex.Apply();
                    AssetDatabase.Refresh();
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Emission Texture");
            if (GUILayout.Button("Select", GUILayout.Width(200)))
            {
                string path = EditorUtility.OpenFilePanel("Select Emission Texture", "", "png,jpeg,jpg");
                if (path.Length != 0)
                {
                    var fileContent = File.ReadAllBytes(path);
                    PantsEm.LoadImage(fileContent);
                    PantsEm.Apply();
                    mat.SetColor("_EmissionColor", Color.white);
                    AssetDatabase.Refresh();
                }
            }

            /*Honestly most of the following doesn't need explaining, it's just buttons and switches and sliders.
             * If you'd like to learn about how they work, I'd recommend searching "EditorGUILayout" and "GUILayout" and reading the unity documentation.
             * It's very helpful.
             * */
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Metallic Texture");
            if (GUILayout.Button("Select", GUILayout.Width(200)))
            {
                string path = EditorUtility.OpenFilePanel("Select Metallic Texture", "", "png");
                if (path.Length != 0)
                {
                    var fileContent = File.ReadAllBytes(path);
                    PantsMet.LoadImage(fileContent);
                    PantsMet.Apply();
                    mat.SetTexture("_MetallicGlossMap", PantsMet);
                    AssetDatabase.ImportAsset("Assets/Pants_Assets/Resources/Bundles/Items/Pants/Jeans_Work/Material.mat");
                    AssetDatabase.Refresh();
                }
                UnityEditor.AssetDatabase.Refresh();
            }
            EditorGUILayout.EndHorizontal();
            smoothness = EditorGUILayout.Slider("Smoothness", smoothness, 0, 1, GUILayout.Width(350));

            /*Honestly most of the following doesn't need explaining, it's just buttons and switches and sliders.
             * If you'd like to learn about how they work, I'd recommend searching "EditorGUILayout" and "GUILayout" and reading the unity documentation.
             * It's very helpful.
             * */
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset Emission", GUILayout.Width(173)))
            {
                mat.SetColor("_EmissionColor", Color.black);
                var tempFile = File.ReadAllBytes(Application.dataPath + "/ClothingCreator/Icons/transparent.png");
                PantsEm.LoadImage(tempFile);
                PantsEm.Apply();
            }
            if (GUILayout.Button("Reset Metallic", GUILayout.Width(173)))
            {
                var tempFile = File.ReadAllBytes(Application.dataPath + "/ClothingCreator/Icons/black.png");
                PantsMet.LoadImage(tempFile);
                PantsMet.Apply();
                mat.SetFloat("_Metallic", 0);
                AssetDatabase.ImportAsset("Assets/Pants_Assets/Resources/Bundles/Items/Pants/Jeans_Work/Material.mat");
                AssetDatabase.Refresh();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Texture Preview");
            GUILayout.Label("In-Game Preview", GUILayout.Width(150));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Box(AssetPreview.GetAssetPreview(PantsTex));
            GUILayout.Box(PantsScenePreview);
            EditorGUILayout.EndHorizontal();
            camRotation = EditorGUILayout.Slider("Rotate Preview", camRotation, 0, 360, GUILayout.Width(350));
        }
        bundleFold = EditorGUILayout.Foldout(bundleFold, "Bundler Settings");
        if (bundleFold)
        {
            generateDats = EditorGUILayout.BeginToggleGroup("Generate .DAT Files", generateDats);
            EditorGUILayout.HelpBox("These are the stats files for your item.", MessageType.Info);
            itemName        = EditorGUILayout.TextField("Item Name", itemName, GUILayout.Width(350));
            itemDescription = EditorGUILayout.TextField("Item Description", itemDescription, GUILayout.Width(350));
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("ID Number");
            itemID = EditorGUILayout.IntSlider(itemID, 2000, 65000, GUILayout.Width(200));
            EditorGUILayout.EndHorizontal();
            pantsRarity = (RARENESS)EditorGUILayout.EnumPopup("Item Rarity", pantsRarity, GUILayout.Width(350));

            /*
             * Currently unimplemented dynamic preview system for Width and Height of Item and storage size. Hopefully will be implemented at a later date.
             *
             * storageFold = EditorGUILayout.Foldout(storageFold, "Storage Preview");
             * sizeFold = EditorGUILayout.Foldout (sizeFold, "Size Preview");
             */
            fireResistant = EditorGUILayout.Toggle("Fire Resistant", fireResistant, GUILayout.Width(350));
            waterproof    = EditorGUILayout.Toggle("Waterproof", waterproof, GUILayout.Width(350));
            //Remind me to add a visual blueprint creator to this at some point
            standardBlueprints = EditorGUILayout.Toggle("Add Standard Blueprints", standardBlueprints, GUILayout.Width(350));
            EditorGUILayout.HelpBox("The Standard Blueprints option adds the blueprint to scrap the pants into cloth, and the blueprint to repair it with cloth.", MessageType.Info);
            customItemSize = EditorGUILayout.BeginToggleGroup("Custom Item Size", customItemSize);
            itemWidth      = EditorGUILayout.IntSlider("Custom Item Width", itemWidth, 1, 5, GUILayout.Width(350));
            itemHeight     = EditorGUILayout.IntSlider("Custom Item Height", itemHeight, 1, 5, GUILayout.Width(350));
            EditorGUILayout.HelpBox("This is how large in grid squares your item will take up. Disabling Custom Item Size will reset to the default size, 3 squares wide by 2 squares tall.", MessageType.Info);
            EditorGUILayout.EndToggleGroup();
            armor      = EditorGUILayout.BeginToggleGroup("Armor", armor);
            armorLevel = EditorGUILayout.IntSlider("Damage Absorption", armorLevel, 1, 100, GUILayout.Width(350));
            GUILayout.Label(armorLevel + "% of any damage to the torso will be absorbed.");
            EditorGUILayout.EndToggleGroup();
            GUILayout.Label("Item Storage Slots", EditorStyles.boldLabel);
            itemStorageWidth  = EditorGUILayout.IntSlider("Storage Width", itemStorageWidth, 1, 15, GUILayout.Width(350));
            itemStorageHeight = EditorGUILayout.IntSlider("Storage Height", itemStorageHeight, 1, 15, GUILayout.Width(350));
            EditorGUILayout.HelpBox("This is how large in grid squares your item's storage slots will be when equipped. A good average is around 4-5 squares wide and tall.", MessageType.Info);
            EditorGUILayout.EndToggleGroup();
            customNameString = EditorGUILayout.TextField("Custom File Name", customNameString, GUILayout.Width(350));
            EditorGUILayout.HelpBox("This option is for advanced users who want to customize the name of mod files created. The standard option automatically removes spaces from the item name and uses that. If you aren't happy with that name being used as the File Name, use this to change it to a more preferable option.", MessageType.Info);
            if (itemNameFlat.Contains(" "))
            {
                EditorGUILayout.HelpBox("Please note that any spaces added to the File Name input box will be automatically removed with spaces when processed.", MessageType.Warning);
            }
            KeepManifests = EditorGUILayout.Toggle("Keep Manifests", KeepManifests);
            cleanProject  = EditorGUILayout.Toggle("Clean Project After Bundle", cleanProject);
            EditorGUILayout.HelpBox("This option allows your project to be automatically set up for the next item, i.e removing any objects currently in scene and deleting the Pants_Assets file. Don't use this if you plan on making more pantss after this!", MessageType.Info);
            if (GUILayout.Button("Create Mod Files", GUILayout.Width(350)))
            {
                if (generateDats == false && customNameString == "" || itemName == "" && customNameString == "")
                {
                    EditorGUILayout.HelpBox("You must specify a name for the mod, if you choose not to generate .DAT files. Enter one in the Custom File Name slot.", MessageType.Warning);
                }
                else
                {
                    //The following line allows for the user inputted Item Name to have a dual purpose system, in which it is used to name the file and the in-game item. It removes any spaces with underlines, to maintain styling with SDG assets and to prevent any errors.
                    //itemNameFlat = itemName.Replace (" ", "_");

                    /* Because I opted for an ease of use system in which the armor slider is shown as a percentage of damage absorbed, I have to convert it to the method used in the dat files. Basically, in the dat files it uses a multiplier like 0.55, which would multiply any incoming damage by 0.55.
                     * This multiplier would essentially negate 45% of the damage. In order to make it easier to understand for inexperienced modders, I simply have to subtract
                     * the float value I created earlier out of 100 to get the percentage of armor negated, then divide by 100 to get a decimal. Oh, and since you're here and reading this, I just wanted to say congrats to you for either attempting to learn programming or wanting to see how this works. You're
                     * going to go far, kid. :)
                     * */
                    Debug.Log(100 - armorLevel);
                    actualArmor = (double)(100 - armorLevel) / 100;
                    if (customNameString != "")
                    {
                        itemNameFlat = customNameString.Replace(" ", "_");
                        Debug.Log("cust name:" + itemNameFlat);
                        Debug.Log(customNameString != "");
                        Debug.Log(customNameString != null);
                    }
                    else
                    {
                        itemNameFlat = itemName.Replace(" ", "_");
                    }
                    //This is the new weird and wonky Unity 5+ asset bundling system. While I've never coded in Unity 4, this system definitely seems more complex. The function below gets the path to the Pants_Assets folder and marks it as a "unity3d" bundle. This removes the need for user based renaming.
                    AssetImporter.GetAtPath("Assets/Pants_Assets").SetAssetBundleNameAndVariant("temp", "unity3d");
                    //Prompt for the user to select what folder they would like to save to. The window is called "Select Bundle Folder", the path is the string it returns, and "Mod Folder" is the default name shown when the window opens.
                    path = EditorUtility.SaveFolderPanel("Select Bundle Folder", path, "Mod Folder");
                    System.IO.Directory.CreateDirectory(Application.dataPath + "/" + itemNameFlat + "/test");
                    Debug.Log(Application.dataPath + "/" + itemNameFlat + "/test");
                    System.IO.Directory.Delete(Application.dataPath + "/" + itemNameFlat + "/test", true);
                    //Checking whether or not the user enabled creation of .dat files
                    if (generateDats)
                    {
                        using (StreamWriter sw = File.CreateText(Application.dataPath + "/" + itemNameFlat + "/" + itemNameFlat + ".dat")) {
                            Debug.Log(Application.dataPath + "/" + itemNameFlat + "/" + itemNameFlat + ".dat");
                            sw.WriteLine("Type Pants");
                            sw.WriteLine("Rarity " + pantsRarity);
                            sw.WriteLine("Useable Clothing");
                            sw.WriteLine("ID " + itemID);
                            //This is added to make it look more human, human written dat files feature some spaces between lines
                            sw.WriteLine(" ");
                            if (customItemSize)
                            {
                                sw.WriteLine("Size_X " + itemWidth);
                                sw.WriteLine("Size_Y " + itemHeight);
                                sw.WriteLine("Size_Z 0.6");
                            }
                            if (!customItemSize)
                            {
                                //If the user did not toggle custom item sizes, the default 3x2 will be used instead.
                                sw.WriteLine("Size_X 3");
                                sw.WriteLine("Size_Y 2");
                                sw.WriteLine("Size_Z 0.6");
                            }
                            sw.WriteLine(" ");
                            sw.WriteLine("Width " + itemStorageWidth);
                            sw.WriteLine("Height " + itemStorageHeight);
                            sw.WriteLine(" ");
                            if (armor)
                            {
                                sw.WriteLine("Armor " + actualArmor);
                                sw.WriteLine(" ");
                            }
                            if (fireResistant)
                            {
                                sw.WriteLine("Proof_Fire");
                            }
                            if (waterproof)
                            {
                                sw.WriteLine("Proof_Water");
                            }
                            if (standardBlueprints)
                            {
                                sw.WriteLine(" ");
                                sw.WriteLine("Blueprints 2");
                                sw.WriteLine("Blueprint_0_Type Apparel");
                                sw.WriteLine("Blueprint_0_Supply_0_ID 1421");
                                sw.WriteLine("Blueprint_0_Product 66");
                                sw.WriteLine("Blueprint_0_Products 3");
                                sw.WriteLine("Blueprint_0_Build 32");
                                sw.WriteLine("Blueprint_1_Type Repair");
                                sw.WriteLine("Blueprint_1_Supplies 1");
                                sw.WriteLine("Blueprint_1_Supply_0_ID 66");
                                sw.WriteLine("Blueprint_1_Supply_0_Amount 3");
                                sw.WriteLine("Blueprint_1_Build 32");
                            }
                        }
                        using (StreamWriter sx = File.CreateText(Application.dataPath + "/" + itemNameFlat + "/English.dat")) {
                            sx.WriteLine("Name " + itemName);
                            sx.WriteLine("Description " + itemDescription);
                        }

                        /*
                         * NOTICE: THIS IS THE BROKEN AND LEGACY WAY I ATTEMPTED TO WRITE TO DAT FILES WITH. IT DOES NOT WORK AND IS ONLY BEING SAVED FOR THE SAKE OF POSTERITY. DO NOT ATTEMPT TO USE AS IT IS COMPLETELY BROKEN.
                         * Basically, what I'm doing here is checking what the user requested to be added to any .dat files and writing it. The dat file is generated automatically if it doesn't exist (which it shouldn't) when the first WriteAllText is ran.
                         * System.IO.File.WriteAllText (path + "/English.dat", "Name " + itemName + "\n" + "Description " + itemDescription);
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "\nType Pants \n Rarity " + pantsRarity + "\n Useable Clothing \n ID " + itemID + "\n");
                         * if (customItemSize) {
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "Size_X " + itemWidth + "\n Size_Y " + itemHeight + "\n Size_Z 0.6 \n");
                         * }
                         * if (!customItemSize) {
                         * //If the user did not toggle custom item sizes, the default 3x2 will be used instead.
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "Size_X 3\n Size_Y 2\n Size_Z 0.6 \n");
                         * }
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "Width " + itemStorageWidth + "\n Height " + itemHeight);
                         * if (armor)
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "\n Armor " + actualArmor);
                         * if (fireResistant)
                         * //In case you're wondering, \n is what's called an Escape Sequence. Basically, it allows you to escape the quotes and add extra stuff. I.e you can use \n to make a new line, \" to add a quote, and "\ " to add spaces when not in quotes.
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "\n Proof_Fire");
                         * if (waterproof)
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "\n Proof_Water");
                         * if (standardBlueprints) {
                         * System.IO.File.WriteAllText (path + "/" + itemNameFlat + ".dat", "\nBlueprints 2 \nBlueprint_0_Type Apparel\nBlueprint_0_Supply_0_ID 1421\nBlueprint_0_Product 66\nBlueprint_0_Products 3\nBlueprint_0_Build 32\nBlueprint_1_Type Repair\nBlueprint_1_Supplies 1\nBlueprint_1_Supply_0_ID 66\nBlueprint_1_Supply_0_Amount 3\nBlueprint_1_Build 32\n");
                         * }
                         */
                    }
                    //Bundle the Unity3d file and place it in the same path folder mentioned early marked path. This isn't a reusable script as it doesn't carry over the parameters like a reusable void would, i.e getting the local class variable rather than bundleAssets(String path);
                    bundleAssets();
                    UnityEditor.AssetDatabase.Refresh();
                    File.Delete(Application.dataPath + "/" + itemNameFlat + ".meta");
                    File.Move(Application.dataPath + "/" + itemNameFlat + "/temp.unity3d", Application.dataPath + "/" + itemNameFlat + "/" + itemNameFlat + ".unity3d");
                    File.Move(Application.dataPath + "/" + itemNameFlat, path + "/" + itemNameFlat);
                    File.Delete(path + "/" + itemNameFlat + "/English.dat.meta");
                    File.Delete(path + "/" + itemNameFlat + "/temp.unity3d.manifest");
                    File.Delete(path + "/" + itemNameFlat + "/temp.unity3d.manifest.meta");
                    File.Delete(path + "/" + itemNameFlat + "/temp.unity3d.meta");
                    File.Delete(path + "/" + itemNameFlat + "/" + itemNameFlat);
                    File.Delete(path + "/" + itemNameFlat + "/" + itemNameFlat + ".manifest");
                    File.Delete(path + "/" + itemNameFlat + "/" + itemNameFlat + ".meta");
                    File.Delete(path + "/" + itemNameFlat + "/" + itemNameFlat + ".manifest.meta");
                    File.Delete(path + "/" + itemNameFlat + "/" + itemNameFlat + ".dat.meta");
                }
            }
            if (generateDats == false && customNameString == "" || itemName == "" && customNameString == "")
            {
                EditorGUILayout.HelpBox("You must specify a name for the mod, in either the Item Name slot or in the Custom Name slot if you have chosen not to generate .DATs", MessageType.Error);
            }
        }
        devFold = EditorGUILayout.Foldout(devFold, "Dev Tests");
        if (devFold)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Clean Tags/Layers", GUILayout.Width(150)))
            {
                RemoveTag("Logic");
                RemoveTag("Enemy");
                RemoveTag("Viewmodel");
                RemoveTag("Debris");
                RemoveTag("Item");
                RemoveTag("Resource");
                RemoveTag("Large");
                RemoveTag("Medium");
                RemoveTag("Small");
                RemoveTag("Sky");
                RemoveTag("Environment");
                RemoveTag("Water");
                RemoveTag("Ground");
                RemoveTag("Clip");
                RemoveTag("Navmesh");
                RemoveTag("Zombie");
                RemoveTag("Agent");
                RemoveTag("Ladder");
                RemoveTag("Vehicle");
                RemoveTag("Barricade");
                RemoveTag("Structure");
                RemoveTag("Tire");
                RemoveTag("Trap");
                RemoveTag("Ground2");
                RemoveTag("Animal");
                RemoveTag("UI");
                RemoveTag("Border");
                RemoveLayer("Logic");
                RemoveLayer("Player");
                RemoveLayer("Enemy");
                RemoveLayer("Viewmodel");
                RemoveLayer("Debris");
                RemoveLayer("Item");
                RemoveLayer("Resource");
                RemoveLayer("Large");
                RemoveLayer("Medium");
                RemoveLayer("Small");
                RemoveLayer("Sky");
                RemoveLayer("Environment");
                RemoveLayer("Ground");
                RemoveLayer("Clip");
                RemoveLayer("Navmesh");
                RemoveLayer("Zombie");
                RemoveLayer("Agent");
                RemoveLayer("Ladder");
                RemoveLayer("Vehicle");
                RemoveLayer("Barricade");
                RemoveLayer("Structure");
                RemoveLayer("Tire");
                RemoveLayer("Trap");
                RemoveLayer("Ground2");
                RemoveLayer("Animal");
                RemoveLayer("UI");
                RemoveLayer("Border");
                RemoveLayer("Entity");
            }
            if (GUILayout.Button("Create Tags/Layers", GUILayout.Width(150)))
            {
                AddTag("Logic");
                AddTag("Enemy");
                AddTag("Viewmodel");
                AddTag("Debris");
                AddTag("Item");
                AddTag("Resource");
                AddTag("Large");
                AddTag("Medium");
                AddTag("Small");
                AddTag("Sky");
                AddTag("Environment");
                AddTag("Water");
                AddTag("Ground");
                AddTag("Clip");
                AddTag("Navmesh");
                AddTag("Zombie");
                AddTag("Agent");
                AddTag("Ladder");
                AddTag("Vehicle");
                AddTag("Barricade");
                AddTag("Structure");
                AddTag("Tire");
                AddTag("Trap");
                AddTag("Ground2");
                AddTag("Animal");
                AddTag("UI");
                AddTag("Border");
                AddLayer("Logic");
                AddLayer("Player");
                AddLayer("Enemy");
                AddLayer("Viewmodel");
                AddLayer("Debris");
                AddLayer("Item");
                AddLayer("Resource");
                AddLayer("Large");
                AddLayer("Medium");
                AddLayer("Small");
                AddLayer("Sky");
                AddLayer("Environment");
                AddLayer("Ground");
                AddLayer("Clip");
                AddLayer("Navmesh");
                AddLayer("Zombie");
                AddLayer("Agent");
                AddLayer("Ladder");
                AddLayer("Vehicle");
                AddLayer("Barricade");
                AddLayer("Structure");
                AddLayer("Tire");
                AddLayer("Trap");
                AddLayer("Ground2");
                AddLayer("Animal");
                AddLayer("UI");
                AddLayer("Border");
                AddLayer("Entity");
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset Scene", GUILayout.Width(150)))
            {
                AssetDatabase.DeleteAsset("Assets/Pants_Assets");
                GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();
                foreach (GameObject go in allObjects)
                {
                    if (go.activeInHierarchy && (go.name != "Main Camera") && (go.name != "Directional Light"))
                    {
                        DestroyImmediate(go);
                    }
                }
                Debug.Log("Forgot to tell you, this crashes the window. Just reopen it, and ignore any errors.");
                window.Close();
                UnityEditor.AssetDatabase.Refresh();
            }
            if (GUILayout.Button("Reimport PKGs", GUILayout.Width(150)))
            {
                AssetDatabase.ImportPackage("Assets/ClothingCreator/Pants.unitypackage", importdialog);
            }
            EditorGUILayout.EndHorizontal();;
            importdialog  = EditorGUILayout.ToggleLeft("Import Dialogue", importdialog);
            displayErrors = EditorGUILayout.ToggleLeft("Display Errors", displayErrors);
        }
    }
예제 #2
0
        private void DrawCustomTextField(EditorWindow editorWindow, Rect windowRect)
        {
            bool flag5;

            if (!this.m_Data.m_AllowCustom)
            {
                return;
            }
            Event  current = Event.current;
            bool   enableAutoCompletion = this.m_Data.m_EnableAutoCompletion;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            string label = this.CurrentDisplayedText();

            if (current.type == EventType.KeyDown)
            {
                KeyCode keyCode = current.keyCode;
                switch (keyCode)
                {
                case KeyCode.Backspace:
                    goto Label_0136;

                case KeyCode.Tab:
                case KeyCode.Return:
                    break;

                default:
                    switch (keyCode)
                    {
                    case KeyCode.UpArrow:
                        this.ChangeSelectedCompletion(-1);
                        flag3 = true;
                        goto Label_017A;

                    case KeyCode.DownArrow:
                        this.ChangeSelectedCompletion(1);
                        flag3 = true;
                        goto Label_017A;

                    case KeyCode.None:
                        if ((current.character == ' ') || (current.character == ','))
                        {
                            flag3 = true;
                        }
                        goto Label_017A;

                    case KeyCode.Space:
                    case KeyCode.Comma:
                        break;

                    case KeyCode.Delete:
                        goto Label_0136;

                    default:
                        goto Label_017A;
                    }
                    break;
                }
                if (label != string.Empty)
                {
                    if (this.m_Data.m_OnSelectCallback != null)
                    {
                        this.m_Data.m_OnSelectCallback(this.m_Data.NewOrMatchingElement(label));
                    }
                    if ((current.keyCode == KeyCode.Tab) || (current.keyCode == KeyCode.Comma))
                    {
                        flag4 = true;
                    }
                    if (this.m_Data.m_CloseOnSelection || (current.keyCode == KeyCode.Return))
                    {
                        flag2 = true;
                    }
                }
                flag3 = true;
            }
            goto Label_017A;
Label_0136:
            enableAutoCompletion = false;
Label_017A:
            flag5 = false;
            Rect position = new Rect(windowRect.x + 5f, windowRect.y + ((this.m_Gravity != Gravity.Top) ? ((windowRect.height - 16f) - 5f) : 5f), (windowRect.width - 10f) - 14f, 16f);

            GUI.SetNextControlName(s_TextFieldName);
            EditorGUI.FocusTextInControl(s_TextFieldName);
            int id = GUIUtility.GetControlID(s_TextFieldHash, FocusType.Keyboard, position);

            if (flag3)
            {
                current.Use();
            }
            if (GUIUtility.keyboardControl == 0)
            {
                GUIUtility.keyboardControl = id;
            }
            string str2  = EditorGUI.DoTextField(s_RecycledEditor, id, position, label, s_Styles.customTextField, null, out flag5, false, false, false);
            Rect   rect2 = position;

            rect2.x    += position.width;
            rect2.width = 14f;
            if ((GUI.Button(rect2, GUIContent.none, !(str2 != string.Empty) ? s_Styles.customTextFieldCancelButtonEmpty : s_Styles.customTextFieldCancelButton) && (str2 != string.Empty)) || flag4)
            {
                string str3 = string.Empty;
                s_RecycledEditor.text = str3;
                str2 = EditorGUI.s_OriginalText = str3;
                s_RecycledEditor.cursorIndex = 0;
                s_RecycledEditor.selectIndex = 0;
                enableAutoCompletion         = false;
            }
            if (label != str2)
            {
                this.m_EnteredText = ((0 > s_RecycledEditor.cursorIndex) || (s_RecycledEditor.cursorIndex >= str2.Length)) ? str2 : str2.Substring(0, s_RecycledEditor.cursorIndex);
                if (enableAutoCompletion)
                {
                    this.UpdateCompletion();
                }
                else
                {
                    this.SelectNoCompletion();
                }
            }
            if (flag2)
            {
                editorWindow.Close();
            }
        }
예제 #3
0
        private void DrawCustomTextField(EditorWindow editorWindow, Rect windowRect)
        {
            if (this.m_Data.m_AllowCustom)
            {
                Event  current = Event.current;
                bool   flag    = this.m_Data.m_EnableAutoCompletion;
                bool   flag2   = false;
                bool   flag3   = false;
                bool   flag4   = false;
                string text    = this.CurrentDisplayedText();
                if (current.type == EventType.KeyDown)
                {
                    KeyCode keyCode = current.keyCode;
                    switch (keyCode)
                    {
                    case KeyCode.Backspace:
                        goto IL_12F;

                    case KeyCode.Tab:
                    case KeyCode.Return:
                        goto IL_AC;

                    case (KeyCode)10:
                    case (KeyCode)11:
                    case KeyCode.Clear:
IL_6D:
                        if (keyCode == KeyCode.UpArrow)
                        {
                            this.ChangeSelectedCompletion(-1);
                            flag3 = true;
                            goto IL_173;
                        }
                        if (keyCode == KeyCode.DownArrow)
                        {
                            this.ChangeSelectedCompletion(1);
                            flag3 = true;
                            goto IL_173;
                        }
                        if (keyCode == KeyCode.None)
                        {
                            if (current.character == ' ' || current.character == ',')
                            {
                                flag3 = true;
                            }
                            goto IL_173;
                        }
                        if (keyCode == KeyCode.Space || keyCode == KeyCode.Comma)
                        {
                            goto IL_AC;
                        }
                        if (keyCode != KeyCode.Delete)
                        {
                            goto IL_173;
                        }
                        goto IL_12F;
                    }
                    goto IL_6D;
IL_AC:
                    if (text != "")
                    {
                        if (this.m_Data.m_OnSelectCallback != null)
                        {
                            this.m_Data.m_OnSelectCallback(this.m_Data.NewOrMatchingElement(text));
                        }
                        if (current.keyCode == KeyCode.Tab || current.keyCode == KeyCode.Comma)
                        {
                            flag4 = true;
                        }
                        if (this.m_Data.m_CloseOnSelection || current.keyCode == KeyCode.Return)
                        {
                            flag2 = true;
                        }
                    }
                    flag3 = true;
                    goto IL_173;
IL_12F:
                    flag = false;
                    IL_173 :;
                }
                bool flag5 = false;
                Rect rect  = new Rect(windowRect.x + 5f, windowRect.y + ((this.m_Gravity != PopupList.Gravity.Top) ? (windowRect.height - 16f - 5f) : 5f), windowRect.width - 10f - 14f, 16f);
                GUI.SetNextControlName(PopupList.s_TextFieldName);
                EditorGUI.FocusTextInControl(PopupList.s_TextFieldName);
                int controlID = GUIUtility.GetControlID(PopupList.s_TextFieldHash, FocusType.Keyboard, rect);
                if (flag3)
                {
                    current.Use();
                }
                if (GUIUtility.keyboardControl == 0)
                {
                    GUIUtility.keyboardControl = controlID;
                }
                string text2    = EditorGUI.DoTextField(PopupList.s_RecycledEditor, controlID, rect, text, PopupList.s_Styles.customTextField, null, out flag5, false, false, false);
                Rect   position = rect;
                position.x    += rect.width;
                position.width = 14f;
                if ((GUI.Button(position, GUIContent.none, (!(text2 != "")) ? PopupList.s_Styles.customTextFieldCancelButtonEmpty : PopupList.s_Styles.customTextFieldCancelButton) && text2 != "") || flag4)
                {
                    string text3 = "";
                    PopupList.s_RecycledEditor.text = text3;
                    text2 = (EditorGUI.s_OriginalText = text3);
                    PopupList.s_RecycledEditor.cursorIndex = 0;
                    PopupList.s_RecycledEditor.selectIndex = 0;
                    flag = false;
                }
                if (text != text2)
                {
                    this.m_EnteredText = ((0 > PopupList.s_RecycledEditor.cursorIndex || PopupList.s_RecycledEditor.cursorIndex >= text2.Length) ? text2 : text2.Substring(0, PopupList.s_RecycledEditor.cursorIndex));
                    if (flag)
                    {
                        this.UpdateCompletion();
                    }
                    else
                    {
                        this.SelectNoCompletion();
                    }
                }
                if (flag2)
                {
                    editorWindow.Close();
                }
            }
        }
예제 #4
0
        private void DrawList(EditorWindow editorWindow, Rect windowRect)
        {
            Event current = Event.current;
            int   index   = -1;
            IEnumerator <ListElement> enumerator = this.m_Data.GetFilteredList(this.m_EnteredText).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    ListElement element = enumerator.Current;
                    index++;
                    Rect      position = new Rect(windowRect.x, ((windowRect.y + 10f) + (index * 16f)) + (((this.m_Gravity != Gravity.Top) || !this.m_Data.m_AllowCustom) ? 0f : 16f), windowRect.width, 16f);
                    EventType type     = current.type;
                    switch (type)
                    {
                    case EventType.MouseDown:
                    {
                        if (((Event.current.button == 0) && position.Contains(Event.current.mousePosition)) && element.enabled)
                        {
                            if (this.m_Data.m_OnSelectCallback != null)
                            {
                                this.m_Data.m_OnSelectCallback(element);
                            }
                            current.Use();
                            if (this.m_Data.m_CloseOnSelection)
                            {
                                editorWindow.Close();
                            }
                        }
                        continue;
                    }

                    case EventType.MouseMove:
                        break;

                    default:
                    {
                        if (type == EventType.Repaint)
                        {
                            GUIStyle style            = !element.partiallySelected ? s_Styles.menuItem : s_Styles.menuItemMixed;
                            bool     on               = element.selected || element.partiallySelected;
                            bool     hasKeyboardFocus = false;
                            bool     isHover          = index == this.m_SelectedCompletionIndex;
                            bool     isActive         = on;
                            EditorGUI.BeginDisabledGroup(!element.enabled);
                            GUIContent content = element.m_Content;
                            style.Draw(position, content, isHover, isActive, on, hasKeyboardFocus);
                            EditorGUI.EndDisabledGroup();
                        }
                        continue;
                    }
                    }
                    if (position.Contains(Event.current.mousePosition))
                    {
                        this.SelectCompletionWithIndex(index);
                        current.Use();
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
        }