示例#1
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Set up item picker:
            if (itemPicker == null)
            {
                itemPicker = new ItemPicker(EditorTools.FindInitialDatabase(), prop.stringValue, true);
            }

            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }
            if (ShowReferenceDatabase())
            {
                var dbPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
                position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, position.height - EditorGUIUtility.singleLineHeight);
                EditorTools.selectedDatabase = EditorGUI.ObjectField(dbPosition, itemPicker.database, typeof(DialogueDatabase), true) as DialogueDatabase;
            }
            if (EditorTools.selectedDatabase != itemPicker.database)
            {
                itemPicker.database = EditorTools.selectedDatabase;
                itemPicker.UpdateTitles();
            }

            itemPicker.Draw(position);
            prop.stringValue = itemPicker.currentItem;

            EditorGUI.EndProperty();
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Validate internal variables:
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }
            if (EditorTools.selectedDatabase == null)
            {
                usePicker = false;
            }
            if (usePicker && (titles == null))
            {
                UpdateTitles(prop.stringValue);
            }

            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Draw popup or plain text field:
            var rect = new Rect(position.x - 30, position.y, position.width, position.height);

            if (usePicker)
            {
                var newIndex = EditorGUI.Popup(rect, currentIndex, titles);
                if ((newIndex != currentIndex) && (0 <= newIndex && newIndex < titles.Length))
                {
                    currentIndex     = newIndex;
                    prop.stringValue = titles[currentIndex];
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                string value = EditorGUI.TextField(rect, prop.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    prop.stringValue = value;
                }
            }

            // Radio button toggle between popup and plain text field:
            rect = new Rect(position.x + position.width - 22, position.y, 22, position.height);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (EditorTools.selectedDatabase == null))
                {
                    EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
                }
                titles = null;
            }

            EditorGUI.EndProperty();
        }
示例#3
0
        public void OnEnable()
        {
            var trigger = target as QuestTrigger;

            if (trigger != null)
            {
                EditorTools.SetInitialDatabaseIfNull();
                luaScriptWizard = new LuaScriptWizard(EditorTools.selectedDatabase);
                questPicker     = new QuestPicker(trigger.selectedDatabase, trigger.questName, trigger.useQuestNamePicker);
            }
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            EditorTools.SetInitialDatabaseIfNull();
            var height = (EditorTools.selectedDatabase == null) ? EditorGUIUtility.singleLineHeight : (lastComputedHeight - EditorGUIUtility.singleLineHeight + 2f);

            if (ShowReferenceDatabase())
            {
                height += EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (string.IsNullOrEmpty(currentLuaWizardContent))
            {
                currentLuaWizardContent = property.stringValue;
            }

            EditorGUI.BeginProperty(position, label, property);
            try
            {
                EditorTools.SetInitialDatabaseIfNull();
                try
                {
                    if (ShowReferenceDatabase())
                    {
                        EditorTools.DrawReferenceDatabase(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight));
                        position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, position.height - EditorGUIUtility.singleLineHeight);
                    }
                    luaWizard.database = EditorTools.selectedDatabase;
                    if (luaWizard.database == null)
                    {
                        EditorGUI.PropertyField(position, property);
                    }
                    else
                    {
                        if (!luaWizard.IsOpen)
                        {
                            luaWizard.OpenWizard(currentLuaWizardContent);
                        }
                        lastComputedHeight      = luaWizard.GetHeight() + GUI.skin.textArea.CalcHeight(new GUIContent(currentLuaWizardContent), position.width);
                        currentLuaWizardContent = luaWizard.Draw(position, label, currentLuaWizardContent);
                        property.stringValue    = currentLuaWizardContent;
                        if (!luaWizard.IsOpen && !string.IsNullOrEmpty(currentLuaWizardContent))
                        {
                            property.stringValue = currentLuaWizardContent;
                            luaWizard.OpenWizard(currentLuaWizardContent);
                        }
                    }
                }
                catch (System.Exception)
                {
                    // Don't cause editor problems if Lua wizard has problems.
                }
            }
            finally
            {
                EditorGUI.EndProperty();
            }
        }
 public void OnEnable()
 {
     EditorTools.SetInitialDatabaseIfNull();
 }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            try
            {
                EditorGUI.BeginProperty(position, label, property);

                var rect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

                if (hideMainFoldout)
                {
                    EditorGUI.LabelField(rect, "Required conditions:");
                }
                else
                {
                    property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, "Condition");
                }

                // Show last evaluation result:
                if (Application.isPlaying)
                {
                    var lastEvalProperty = property.FindPropertyRelative("lastEvaluationValue");
                    if (lastEvalProperty != null)
                    {
                        var        originalColor  = GUI.color;
                        GUIContent evalGuiContent = null;
                        switch ((Condition.LastEvaluationValue)lastEvalProperty.enumValueIndex)
                        {
                        case Condition.LastEvaluationValue.True:
                            GUI.color      = Color.green;
                            evalGuiContent = new GUIContent("(Last Check: True)");
                            break;

                        case Condition.LastEvaluationValue.False:
                            GUI.color      = Color.red;
                            evalGuiContent = new GUIContent("(Last Check: False)");
                            break;

                        default:
                            evalGuiContent = new GUIContent("(Last Check: None)");
                            break;
                        }
                        var evalSize = GUI.skin.label.CalcSize(evalGuiContent);
                        EditorGUI.LabelField(new Rect(position.x + position.width - evalSize.x, position.y, evalSize.x, EditorGUIUtility.singleLineHeight), evalGuiContent);
                        GUI.color = originalColor;
                    }
                }

                if (property.isExpanded)
                {
                    position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), GUIContent.none);

                    var oldIndentLevel = EditorGUI.indentLevel;
                    EditorGUI.indentLevel = 1;

                    FindProperties(property);

                    // Debugging (make sure using correct database):
                    //EditorGUI.ObjectField(new Rect(position.x + 100, position.y, position.width - 100, EditorGUIUtility.singleLineHeight), EditorTools.selectedDatabase, typeof(DialogueDatabase));

                    // Set up positioning variables:
                    var x     = position.x;
                    var y     = position.y + EditorGUIUtility.singleLineHeight;
                    var width = position.width;

                    EditorTools.SetInitialDatabaseIfNull();

                    rect = new Rect(x, y, width, EditorGUIUtility.singleLineHeight + 2f);
                    y   += rect.height;
                    luaConditionsProperty.isExpanded = EditorGUI.Foldout(rect, luaConditionsProperty.isExpanded, "Lua Conditions");

                    if (luaConditionsProperty.isExpanded)
                    {
                        rect = new Rect(x + 16f, y, 80f, EditorGUIUtility.singleLineHeight + 2f);
                        EditorGUI.LabelField(rect, "Size");
                        rect = new Rect(x + 96f, y, width - 96f, EditorGUIUtility.singleLineHeight + 2f);
                        y   += rect.height;
                        var newArraySize = EditorGUI.IntField(rect, luaConditionsProperty.arraySize);
                        if (newArraySize != luaConditionsProperty.arraySize)
                        {
                            var oldSize = luaConditionsProperty.arraySize;
                            luaConditionsProperty.arraySize = newArraySize;
                            for (int i = oldSize; i < newArraySize; i++)
                            {
                                luaConditionsProperty.GetArrayElementAtIndex(i).stringValue = string.Empty;
                            }
                        }
                        for (int i = 0; i < luaConditionsProperty.arraySize; i++)
                        {
                            var labelGuiContent = new GUIContent("Element " + i);
                            EditorGUI.LabelField(new Rect(x + 16f, y, 80f, EditorGUIUtility.singleLineHeight), labelGuiContent);
                            luaFieldWidth = rect.width - 16f;
                            var element = luaConditionsProperty.GetArrayElementAtIndex(i);
                            var height  = EditorTools.textAreaGuiStyle.CalcHeight(new GUIContent(element.stringValue), luaFieldWidth) + 2f;
                            rect = new Rect(x + 96f, y, width - 96f, height);
                            y   += height;
                            element.stringValue = EditorGUI.TextArea(rect, element.stringValue);
                        }
                    }

                    // Show Lua wizard if Lua Conditions is expanded:
                    if (luaConditionsProperty.isExpanded)
                    {
                        try
                        {
                            rect = new Rect(x, y, width, luaConditionWizardHeight);
                            luaConditionWizard.database = EditorTools.selectedDatabase;
                            if (luaConditionWizard.database != null)
                            {
                                if (!luaConditionWizard.IsOpen)
                                {
                                    luaConditionWizard.OpenWizard(string.Empty);
                                }
                                currentLuaWizardContent = luaConditionWizard.Draw(rect, new GUIContent("Lua Condition Wizard", "Use to add Lua conditions below"), currentLuaWizardContent);
                                if (!luaConditionWizard.IsOpen && !string.IsNullOrEmpty(currentLuaWizardContent))
                                {
                                    luaConditionsProperty.arraySize++;
                                    var luaElement = luaConditionsProperty.GetArrayElementAtIndex(luaConditionsProperty.arraySize - 1);
                                    luaElement.stringValue  = currentLuaWizardContent;
                                    currentLuaWizardContent = string.Empty;
                                    luaConditionWizard.OpenWizard(string.Empty);
                                }
                            }
                            y += rect.height;
                        }
                        catch (System.Exception)
                        {
                            // Don't cause editor problems if Lua wizard has problems.
                        }
                    }

                    // Quest conditions:
                    rect = new Rect(x, y, width, GetArrayHeight(questConditionsProperty));
                    EditorGUI.PropertyField(rect, questConditionsProperty, true);
                    y += rect.height;

                    // Accepted tags:
                    rect = new Rect(x, y, width, GetArrayHeight(acceptedTagsProperty));
                    EditorGUI.PropertyField(rect, acceptedTagsProperty, true);
                    y += rect.height;

                    // Accepted GameObjects:
                    rect = new Rect(x, y, width, GetArrayHeight(acceptedGameObjectsProperty));
                    EditorGUI.PropertyField(rect, acceptedGameObjectsProperty, true);
                    y += rect.height;

                    EditorGUI.indentLevel = oldIndentLevel;
                }
            }
            catch (System.Exception)
            {
                // Don't throw error and cause problems with Unity editor.
            }
            finally
            {
                EditorGUI.EndProperty();
            }
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Show database field if specified:
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }

            // Set up titles array:
            var questProp = FindQuestProperty(prop);

            if (questProp != null && questProp.stringValue != currentQuestName)
            {
                currentQuestName = questProp.stringValue;
                names            = null;
            }
            if (names == null)
            {
                UpdateNames(questProp, prop);
            }

            // Update current index:
            var currentIndex = prop.intValue;

            // Draw popup or plain text field:
            var rect = new Rect(position.x, position.y, position.width - 30, position.height);

            if (usePicker)
            {
                var newIndex = EditorGUI.Popup(rect, currentIndex, names);
                if ((newIndex != currentIndex) && (0 <= newIndex && newIndex < names.Length))
                {
                    prop.intValue = newIndex;
                    GUI.changed   = true;
                }
            }
            else
            {
                EditorGUI.PropertyField(rect, prop, GUIContent.none, true);
            }

            // Radio button toggle between popup and plain text field:
            rect = new Rect(position.x + position.width - 22, position.y, 22, position.height);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (EditorTools.selectedDatabase == null))
                {
                    EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
                }
                names = null;
            }

            EditorGUI.EndProperty();
        }
示例#9
0
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            // Set up property drawer:
            EditorGUI.BeginProperty(position, GUIContent.none, prop);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            // Show database field if specified:
            showReferenceDatabase = (attribute as VariablePopupAttribute).showReferenceDatabase;
            if (EditorTools.selectedDatabase == null)
            {
                EditorTools.SetInitialDatabaseIfNull();
            }
            if (showReferenceDatabase)
            {
                var dbPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
                position = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, position.height - EditorGUIUtility.singleLineHeight);
                var newDatabase = EditorGUI.ObjectField(dbPosition, EditorTools.selectedDatabase, typeof(DialogueDatabase), true) as DialogueDatabase;
                if (newDatabase != EditorTools.selectedDatabase)
                {
                    EditorTools.selectedDatabase = newDatabase;
                    database = null;
                    names    = null;
                }
            }
            if (EditorTools.selectedDatabase == null)
            {
                usePicker = false;
            }

            // Set up titles array:
            if (names == null || database != EditorTools.selectedDatabase)
            {
                UpdateNames(prop.stringValue);
            }

            // Update current index:
            var currentIndex = GetIndex(prop.stringValue);

            // Draw popup or plain text field:
            var rect = new Rect(position.x, position.y, position.width - 48, position.height);

            if (usePicker)
            {
                var newIndex = EditorGUI.Popup(rect, currentIndex, names);
                if ((newIndex != currentIndex) && (0 <= newIndex && newIndex < names.Length))
                {
                    currentIndex     = newIndex;
                    prop.stringValue = names[currentIndex];
                    GUI.changed      = true;
                }
                if (GUI.Button(new Rect(position.x + position.width - 45, position.y, 18, 14), "x"))
                {
                    prop.stringValue = string.Empty;
                    currentIndex     = -1;
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                string value = EditorGUI.TextField(rect, prop.stringValue);
                if (EditorGUI.EndChangeCheck())
                {
                    prop.stringValue = value;
                }
            }

            // Radio button toggle between popup and plain text field:
            rect = new Rect(position.x + position.width - 22, position.y, 22, position.height);
            var newToggleValue = EditorGUI.Toggle(rect, usePicker, EditorStyles.radioButton);

            if (newToggleValue != usePicker)
            {
                usePicker = newToggleValue;
                if (usePicker && (EditorTools.selectedDatabase == null))
                {
                    EditorTools.selectedDatabase = EditorTools.FindInitialDatabase();
                }
                names = null;
            }

            EditorGUI.EndProperty();
        }