Beispiel #1
0
        public static Keyword KeywordField(Rect position, Keyword keyword, KeywordsConfig keywordsConfig, bool selectionOnly = false)
        {
            List <KeywordCategory> config = keywordsConfig.keyWordCategories;

            Init(keywordsConfig);

            int originalIndentLevel = UnityEditor.EditorGUI.indentLevel;

            UnityEditor.EditorGUI.indentLevel = 0;

            if (selectionOnly)
            {
                position.width -= 16;
            }
            else
            {
                position.width -= 48;
            }

            string temp = "";

            if (isAddingString)
            {
                position.height = UnityEditor.EditorGUIUtility.singleLineHeight;

                currentCategory = UnityEditor.EditorGUI.Popup(position, currentCategory, categories[keywordsConfig].ToArray());

                position.y += position.height;

                UnityEditor.EditorGUI.BeginChangeCheck();

                temp = UnityEditor.EditorGUI.TextField(position, newValue);

                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    RecordChange();
                    newValue = temp;
                }
            }
            else
            {
                temp = keyword.fullPath;

                if (temp == "")
                {
                    temp = "None";
                }

                Color originalColor = GUI.color;
                int   index         = keywords[keywordsConfig].IndexOf(temp);

                if (index < 0)
                {
                    index = keywords[keywordsConfig].Count;
                    keywords[keywordsConfig].Add(temp + " (Missing)");
                    GUI.color = Color.red;
                }

                UnityEditor.EditorGUI.BeginChangeCheck();

                index = UnityEditor.EditorGUI.Popup(position, index, keywords[keywordsConfig].ToArray());

                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    RecordChange();
                    temp = keywords[keywordsConfig][index];
                }

                if (temp == "None")
                {
                    temp = "";
                }

                GUI.color = originalColor;
            }

            position.y    += 1;
            position.x    += position.width;
            position.width = 16;

            if (!selectionOnly)
            {
                if (GUI.Button(position, olPlus, "Label"))
                {
                    if (temp.Contains(" (Missing)"))
                    {
                        KeywordCategory tempCategory = (from c in config where c.name == keyword.category select c).FirstOrDefault();

                        if (tempCategory == null)
                        {
                            config.Add(new KeywordCategory(keyword.category));
                            config.Last().keywords.Add(keyword);
                        }
                        else
                        {
                            tempCategory.keywords.Add(keyword);
                        }
                        UnityEditor.EditorUtility.SetDirty(keywordsConfig);
                        PopulateLists(keywordsConfig);
                        Debug.Log("Missing");
                    }
                    else
                    {
                        if (isAddingString)
                        {
                            config[currentCategory].keywords.Add(newValue);
                            UnityEditor.EditorUtility.SetDirty(keywordsConfig);

                            keywords[keywordsConfig].Add(config[currentCategory].name + (currentCategory == 0 ? "" : "/") + newValue);

                            config[currentCategory].keywords.Sort();
                            keywords[keywordsConfig].RemoveAt(0);
                            keywords[keywordsConfig].Sort();
                            keywords[keywordsConfig].Insert(0, "None");

                            temp = (Keyword)(config[currentCategory].name + (currentCategory == 0 ? "" : "/") + newValue);
                        }

                        isAddingString = !isAddingString;
                    }
                }

                position.x += 16;

                if (GUI.Button(position, olMinus, "Label"))
                {
                    if (isAddingString)
                    {
                        newValue       = "";
                        isAddingString = false;
                    }
                    else
                    {
                        if (UnityEditor.EditorUtility.DisplayDialog("Remove string?", string.Format("Are you sure you want to remove {0} from the string list?", temp), "Yes", "No"))
                        {
                            keywords[keywordsConfig].Remove(temp);

                            if (temp.Contains('/'))
                            {
                                (from c in config where c.name == temp.Substring(0, temp.LastIndexOf('/')) select c.keywords).ToList().FirstOrDefault().Remove(keyword);
                            }
                            else
                            {
                                config[0].keywords.Remove(keyword);
                            }

                            UnityEditor.EditorUtility.SetDirty(keywordsConfig);
                        }
                    }
                }

                position.x += 16;
            }
            position.y      -= 1;
            position.width  += 2;
            position.height += 2;

            if (GUI.Button(position, olRefresh, "Label"))
            {
                PopulateLists(keywordsConfig);
            }

            if (temp != null && temp.Contains(" (Missing)"))
            {
                temp = temp.Replace(" (Missing)", "");
            }

            UnityEditor.EditorGUI.indentLevel = originalIndentLevel;

            return((Keyword)temp);
        }
Beispiel #2
0
        public static Keyword KeywordField(Rect position, string label, Keyword keyword, KeywordsConfig keywordsConfig, bool selectionOnly = false)
        {
            position = UnityEditor.EditorGUI.PrefixLabel(position, UnityEditor.EditorGUIUtility.GetControlID(FocusType.Passive), new GUIContent(label));

            return(KeywordField(position, keyword, keywordsConfig, selectionOnly));
        }