Esempio n. 1
0
        // INITIALIZERS: -----------------------------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            this.instance           = (Clause)this.target;
            this.instance.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;

            this.handleDragRect = Rect.zero;
            this.clauseRect     = Rect.zero;

            this.spDescription    = serializedObject.FindProperty(PROP_DESCRIPTION);
            this.spConditionsList = serializedObject.FindProperty(PROP_CONDITIONSLIST);
            this.spActions        = serializedObject.FindProperty(PROP_ACTION);

            if (this.instance.actions != null)
            {
                this.actionsEditor = Editor.CreateEditor(this.instance.actions) as ActionsEditor;
            }

            if (this.instance.conditionsList == null)
            {
                IConditionsList cList = this.instance.gameObject.AddComponent <IConditionsList>();
                this.spConditionsList.objectReferenceValue = cList;
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            this.conditionsListEditor = Editor.CreateEditor(this.instance.conditionsList) as IConditionsListEditor;
        }
Esempio n. 2
0
        // ACTIONS CREATOR: -----------------------------------------------------------------------

        public static Return PaintActionsGUI(
            GameObject parent,
            SerializedProperty spParentActions,
            ActionsEditor parentActionsEditor)
        {
            KeyValuePair <bool, Actions> returnActions = ActionsEditor.PaintHeader(
                parent, spParentActions, parentActionsEditor
                );

            if (returnActions.Key)
            {
                spParentActions.objectReferenceValue = returnActions.Value;

                if (returnActions.Value == null)
                {
                    parentActionsEditor = null;
                }
                else
                {
                    parentActionsEditor = Editor.CreateEditor(returnActions.Value) as ActionsEditor;
                    parentActionsEditor.serializedObject.Update();
                    parentActionsEditor.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                }

                return(new Return
                {
                    spParentActions = spParentActions,
                    parentActionsEditor = parentActionsEditor
                });
            }

            return(null);
        }
Esempio n. 3
0
        protected override void OnEnable()
        {
            base.OnEnable();

            SerializedProperty spActions = serializedObject.FindProperty("actions");

            if (spActions.objectReferenceValue != null)
            {
                this.editorActions = Editor.CreateEditor(
                    spActions.objectReferenceValue
                    ) as ActionsEditor;
            }
        }
Esempio n. 4
0
        public void OnClauseGUI()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            serializedObject.Update();

            EditorGUILayout.PropertyField(this.spDescription);

            GUIContent gcIf   = ClausesUtilities.Get(ClausesUtilities.Icon.If);
            Rect       rectIf = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectIf, gcIf, EditorStyles.boldLabel);

            this.conditionsListEditor.OnInspectorGUI();
            EditorGUILayout.Space();

            GUIContent gcThen   = ClausesUtilities.Get(ClausesUtilities.Icon.Then);
            Rect       rectThen = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectThen, gcThen, EditorStyles.boldLabel);

            ActionsEditor.Return returnActions = ActionsEditor.PaintActionsGUI(
                this.parentConditions.gameObject,
                this.spActions,
                this.actionsEditor
                );

            if (returnActions != null)
            {
                this.spActions     = returnActions.spParentActions;
                this.actionsEditor = returnActions.parentActionsEditor;

                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
Esempio n. 5
0
        public void OnInteractionGUI()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            serializedObject.Update();

            EditorGUILayout.PropertyField(this.spDescription);

            GUIContent gcIf   = InteractionUtilities.Get(InteractionUtilities.Icon.If);
            Rect       rectIf = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectIf, gcIf, EditorStyles.boldLabel);

            this.conditionsListEditor.OnInspectorGUI();
            EditorGUILayout.Space();

            GUIContent gcThen   = InteractionUtilities.Get(InteractionUtilities.Icon.Then);
            Rect       rectThen = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectThen, gcThen, EditorStyles.boldLabel);

            ActionsEditor.Return returnActions = ActionsEditor.PaintActionsGUI(
                this.parentEvent.gameObject,
                this.spActions,
                this.actionsEditor
                );

            if (returnActions != null)
            {
                this.spActions     = returnActions.spParentActions;
                this.actionsEditor = returnActions.parentActionsEditor;

                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
            }

            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 6
0
        // INITIALIZERS: -----------------------------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            this.forceInitialize = true;

            this.instance         = (Event)target;
            this.spInteractions   = serializedObject.FindProperty(PROP_INTERACTIONS);
            this.spDefaultActions = serializedObject.FindProperty(PROP_DEFREAC);

            if (this.instance.defaultActions != null)
            {
                this.actionsEditor = Editor.CreateEditor(this.instance.defaultActions) as ActionsEditor;
            }

            serializedObject.ApplyModifiedProperties();
            serializedObject.Update();

            this.UpdateSubEditors(this.instance.interactions);
            this.editorSortableList = new EditorSortableList();
        }
Esempio n. 7
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            this.forceInitialize = true;

            this.instance         = (Conditions)target;
            this.spClauses        = serializedObject.FindProperty(PROP_CLAUSES);
            this.spDefaultActions = serializedObject.FindProperty(PROP_DEFREAC);

            if (this.instance.defaultActions != null)
            {
                this.actionsEditor = Editor.CreateEditor(this.instance.defaultActions) as ActionsEditor;
            }

            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            serializedObject.Update();

            this.UpdateSubEditors(this.instance.clauses);
            this.editorSortableList = new EditorSortableList();
        }
Esempio n. 8
0
        private void PaintEvent()
        {
            if (this.spInteractions != null && this.spInteractions.arraySize > 0)
            {
                this.PaintInteractions();
            }
            else
            {
                EditorGUILayout.HelpBox(MSG_EMTPY_EVENTS, MessageType.None);
            }

            float widthAddInteraction = 100f;
            Rect  rectControls        = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());
            Rect  rectAddInteraction  = new Rect(
                rectControls.x + (rectControls.width / 2.0f) - (widthAddInteraction + 25f) / 2.0f,
                rectControls.y,
                widthAddInteraction,
                rectControls.height
                );

            Rect rectPaste = new Rect(
                rectAddInteraction.x + rectAddInteraction.width,
                rectControls.y,
                25f,
                rectControls.height
                );

            if (GUI.Button(rectAddInteraction, "Add Interaction", CoreGUIStyles.GetButtonLeft()))
            {
                Interaction interactionCreated = this.instance.gameObject.AddComponent <Interaction>();

                int interactionCreatedIndex = this.spInteractions.arraySize;
                this.spInteractions.InsertArrayElementAtIndex(interactionCreatedIndex);
                this.spInteractions.GetArrayElementAtIndex(interactionCreatedIndex).objectReferenceValue = interactionCreated;

                this.AddSubEditorElement(interactionCreated, -1, true);

                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
            }

            GUIContent gcPaste = InteractionUtilities.Get(InteractionUtilities.Icon.Paste);

            EditorGUI.BeginDisabledGroup(CLIPBOARD_INTERACTION == null);
            if (GUI.Button(rectPaste, gcPaste, CoreGUIStyles.GetButtonRight()))
            {
                Interaction copy = this.instance.gameObject.AddComponent <Interaction>();
                EditorUtility.CopySerialized(CLIPBOARD_INTERACTION, copy);

                if (copy.conditionsList != null)
                {
                    IConditionsList conditionsListSource = copy.conditionsList;
                    IConditionsList conditionsListCopy   = this.instance.gameObject.AddComponent <IConditionsList>();

                    EditorUtility.CopySerialized(conditionsListSource, conditionsListCopy);
                    EventEditor.DuplicateIConditionList(conditionsListSource, conditionsListCopy);

                    SerializedObject soCopy = new SerializedObject(copy);
                    soCopy.FindProperty(InteractionEditor.PROP_CONDITIONSLIST).objectReferenceValue = conditionsListCopy;
                    soCopy.ApplyModifiedProperties();
                    soCopy.Update();
                }

                int interactionIndex = this.spInteractions.arraySize;
                this.spInteractions.InsertArrayElementAtIndex(interactionIndex);
                this.spInteractions.GetArrayElementAtIndex(interactionIndex).objectReferenceValue = copy;

                this.AddSubEditorElement(copy, -1, true);

                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();

                DestroyImmediate(CLIPBOARD_INTERACTION.gameObject, true);
                CLIPBOARD_INTERACTION = null;

                /*
                 * int srcIndex = duplicateInteractionIndex;
                 * int dstIndex = duplicateInteractionIndex + 1;
                 *
                 * Interaction source = (Interaction)this.subEditors[srcIndex].target;
                 * Interaction copy = (Interaction)this.instance.gameObject.AddComponent(source.GetType());
                 * EditorUtility.CopySerialized(source, copy);
                 *
                 * if (copy.conditionsList != null)
                 * {
                 *  IConditionsList conditionsListSource = copy.conditionsList;
                 *  IConditionsList conditionsListCopy = this.instance.gameObject.AddComponent<IConditionsList>();
                 *
                 *  EditorUtility.CopySerialized(conditionsListSource, conditionsListCopy);
                 *  EventEditor.DuplicateIConditionList(conditionsListSource, conditionsListCopy);
                 *
                 *  SerializedObject soCopy = new SerializedObject(copy);
                 *  soCopy.FindProperty(InteractionEditor.PROP_CONDITIONSLIST).objectReferenceValue = conditionsListCopy;
                 *  soCopy.ApplyModifiedProperties();
                 *  soCopy.Update();
                 * }
                 *
                 * this.spInteractions.InsertArrayElementAtIndex(dstIndex);
                 * this.spInteractions.GetArrayElementAtIndex(dstIndex).objectReferenceValue = copy;
                 *
                 * this.spInteractions.serializedObject.ApplyModifiedProperties();
                 * this.spInteractions.serializedObject.Update();
                 *
                 * this.AddSubEditorElement(copy, dstIndex, true);
                 */
            }
            EditorGUI.EndDisabledGroup();

            GUIContent gcElse   = InteractionUtilities.Get(InteractionUtilities.Icon.Else);
            Rect       rectElse = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectElse, gcElse, EditorStyles.boldLabel);

            ActionsEditor.Return returnActions = ActionsEditor.PaintActionsGUI(
                this.instance.gameObject,
                this.spDefaultActions,
                this.actionsEditor
                );

            if (returnActions != null)
            {
                this.spDefaultActions = returnActions.spParentActions;
                this.actionsEditor    = returnActions.parentActionsEditor;

                serializedObject.ApplyModifiedProperties();
                serializedObject.Update();
            }

            EditorGUILayout.Space();
        }
Esempio n. 9
0
        private static KeyValuePair <bool, Actions> PaintHeader(
            GameObject parent,
            SerializedProperty spParentActions,
            ActionsEditor parentActionsEditor)
        {
            KeyValuePair <bool, Actions> returnActions = new KeyValuePair <bool, Actions>(false, null);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Create Actions", EditorStyles.miniButton))
            {
                int option = 2;
                if (parentActionsEditor != null)
                {
                    option = EditorUtility.DisplayDialogComplex(
                        MSG_OVERWRITE_TITLE,
                        MSG_OVERWRITE_DESCR,
                        "Replace",
                        "Cancel",
                        "Keep both"
                        );
                }

                if (option == 0)
                {
                    DestroyImmediate(parentActionsEditor.instance.gameObject);
                    parentActionsEditor = null;
                }

                if (option != 1)
                {
                    returnActions = new KeyValuePair <bool, Actions>(
                        true, ActionsEditor.CreateActions(parent, "Actions")
                        );
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(spParentActions, GUIContent.none);
            if (EditorGUI.EndChangeCheck())
            {
                returnActions = new KeyValuePair <bool, Actions>(
                    true,
                    spParentActions.objectReferenceValue as Actions
                    );
            }

            EditorGUILayout.EndHorizontal();

            if (parentActionsEditor == null)
            {
                EditorGUILayout.HelpBox(
                    MSG_EMPTY_ACTIONS,
                    MessageType.None
                    );

                return(returnActions);
            }

            parentActionsEditor.OnInspectorGUI();
            return(returnActions);
        }
Esempio n. 10
0
        private void PaintConditions()
        {
            if (this.spClauses != null && this.spClauses.arraySize > 0)
            {
                this.PaintClauses();
            }
            else
            {
                EditorGUILayout.HelpBox(MSG_EMTPY_CONDITIONS, MessageType.None);
            }

            float widthAddClause = 100f;
            Rect  rectControls   = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());
            Rect  rectAddClause  = new Rect(
                rectControls.x + (rectControls.width / 2.0f) - (widthAddClause + 25f) / 2.0f,
                rectControls.y,
                widthAddClause,
                rectControls.height
                );

            Rect rectPaste = new Rect(
                rectAddClause.x + rectAddClause.width,
                rectControls.y,
                25f,
                rectControls.height
                );

            if (GUI.Button(rectAddClause, "Add Clause", CoreGUIStyles.GetButtonLeft()))
            {
                Clause clauseCreated = this.instance.gameObject.AddComponent <Clause>();

                int clauseCreatedIndex = this.spClauses.arraySize;
                this.spClauses.InsertArrayElementAtIndex(clauseCreatedIndex);
                this.spClauses.GetArrayElementAtIndex(clauseCreatedIndex).objectReferenceValue = clauseCreated;

                this.AddSubEditorElement(clauseCreated, -1, true);

                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            GUIContent gcPaste = ClausesUtilities.Get(ClausesUtilities.Icon.Paste);

            EditorGUI.BeginDisabledGroup(CLIPBOARD_CLAUSE == null);
            if (GUI.Button(rectPaste, gcPaste, CoreGUIStyles.GetButtonRight()))
            {
                Clause copy = this.instance.gameObject.AddComponent <Clause>();
                EditorUtility.CopySerialized(CLIPBOARD_CLAUSE, copy);

                if (copy.conditionsList != null)
                {
                    IConditionsList conditionsListSource = copy.conditionsList;
                    IConditionsList conditionsListCopy   = this.instance.gameObject.AddComponent <IConditionsList>();

                    EditorUtility.CopySerialized(conditionsListSource, conditionsListCopy);
                    ConditionsEditor.DuplicateIConditionList(conditionsListSource, conditionsListCopy);

                    SerializedObject soCopy = new SerializedObject(copy);
                    soCopy.FindProperty(ClauseEditor.PROP_CONDITIONSLIST).objectReferenceValue = conditionsListCopy;
                    soCopy.ApplyModifiedPropertiesWithoutUndo();
                    soCopy.Update();
                }

                int clauseIndex = this.spClauses.arraySize;
                this.spClauses.InsertArrayElementAtIndex(clauseIndex);
                this.spClauses.GetArrayElementAtIndex(clauseIndex).objectReferenceValue = copy;

                this.AddSubEditorElement(copy, -1, true);

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();

                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
                DestroyImmediate(CLIPBOARD_CLAUSE.gameObject, true);
                CLIPBOARD_CLAUSE = null;
            }
            EditorGUI.EndDisabledGroup();

            GUIContent gcElse   = ClausesUtilities.Get(ClausesUtilities.Icon.Else);
            Rect       rectElse = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.boldLabel);

            EditorGUI.LabelField(rectElse, gcElse, EditorStyles.boldLabel);

            ActionsEditor.Return returnActions = ActionsEditor.PaintActionsGUI(
                this.instance.gameObject,
                this.spDefaultActions,
                this.actionsEditor
                );

            if (returnActions != null)
            {
                this.spDefaultActions = returnActions.spParentActions;
                this.actionsEditor    = returnActions.parentActionsEditor;

                serializedObject.ApplyModifiedPropertiesWithoutUndo();
                serializedObject.Update();
            }

            EditorGUILayout.Space();
        }