Пример #1
0
        private static void PaintNormal(GlobalID globalID)
        {
            Rect rect = GUILayoutUtility.GetRect(
                0f, 9999f,
                HEIGHT + PADDING,
                HEIGHT + PADDING
                );

            Rect rectInfo = new Rect(
                rect.x,
                rect.y,
                INFO_WIDTH,
                HEIGHT
                );

            Rect rectContent = new Rect(
                rectInfo.x + rectInfo.width,
                rectInfo.y,
                rect.width - INFO_WIDTH - EDIT_WIDTH,
                HEIGHT
                );

            Rect rectEdit = new Rect(
                rectContent.x + rectContent.width,
                rectContent.y,
                EDIT_WIDTH,
                HEIGHT
                );

            GUI.enabled = false;
            EditorGUI.LabelField(rectInfo, "ID", CoreGUIStyles.GetButtonLeft());
            GUI.enabled = true;


            GUI.enabled = false;
            EditorGUI.LabelField(rectContent, globalID.GetID(), CoreGUIStyles.GetButtonMid());
            GUI.enabled = true;

            if (GUI.Button(rectEdit, "Edit", CoreGUIStyles.GetButtonRight()))
            {
                IS_EDITING = true;
            }
        }
Пример #2
0
        private void PaintSidebar(int currentSidebarIndex)
        {
            this.scrollSidebar = EditorGUILayout.BeginScrollView(
                this.scrollSidebar,
                this.styleSidebar,
                GUILayout.MinWidth(SIDEBAR_WIDTH),
                GUILayout.MaxWidth(SIDEBAR_WIDTH),
                GUILayout.ExpandHeight(true)
                );

            for (int i = DATABASES.Count - 1; i >= 0; --i)
            {
                if (DATABASES[i].data == null)
                {
                    DATABASES.RemoveAt(i);
                }
            }

            for (int i = 0; i < DATABASES.Count; ++i)
            {
                Rect itemRect = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetItemPreferencesSidebar());

                if (UnityEngine.Event.current.type == EventType.MouseDown &&
                    itemRect.Contains(UnityEngine.Event.current.mousePosition))
                {
                    this.ChangeSidebarIndex(i);
                }

                bool isActive = (currentSidebarIndex == i);

                if (UnityEngine.Event.current.type == EventType.Repaint)
                {
                    string text = DATABASES[i].name;
                    CoreGUIStyles.GetItemPreferencesSidebar().Draw(itemRect, text, isActive, isActive, false, false);
                }
            }

            EditorGUILayout.EndScrollView();

            Rect borderRect = GUILayoutUtility.GetRect(1f, 1f, GUILayout.ExpandHeight(true), GUILayout.Width(1f));

            EditorGUI.DrawTextureAlpha(borderRect, Texture2D.blackTexture);
        }
Пример #3
0
        public static GUIStyle GetDropZoneActive()
        {
            if (CoreGUIStyles.dropZoneActive == null)
            {
                CoreGUIStyles.dropZoneActive = new GUIStyle(CoreGUIStyles.GetDropZoneNormal());
                Texture2D bgActive = AssetDatabase.LoadAssetAtPath <Texture2D>(DROPZONE_ACTIVE_PATH);

                CoreGUIStyles.dropZoneActive.normal.background  = bgActive;
                CoreGUIStyles.dropZoneActive.focused.background = bgActive;
                CoreGUIStyles.dropZoneActive.active.background  = bgActive;
                CoreGUIStyles.dropZoneActive.hover.background   = bgActive;

                CoreGUIStyles.dropZoneActive.normal.textColor  = Color.black;
                CoreGUIStyles.dropZoneActive.focused.textColor = Color.black;
                CoreGUIStyles.dropZoneActive.active.textColor  = Color.black;
                CoreGUIStyles.dropZoneActive.hover.textColor   = Color.black;
            }

            return(CoreGUIStyles.dropZoneActive);
        }
Пример #4
0
        private bool PaintTitle(string title, bool backButton)
        {
            bool goBack = false;

            EditorGUILayout.BeginHorizontal(this.headerBoxStyle);

            if (backButton && this.keyPressedBack)
            {
                UnityEngine.Event.current.Use();
            }

            if (backButton && (GUILayout.Button(title, this.headerTitleStyle) || this.keyPressedBack))
            {
                this.listIndex = 0;
                goBack         = true;
            }
            else if (!backButton)
            {
                EditorGUILayout.LabelField(title, this.headerTitleStyle);
            }

            if (UnityEngine.Event.current.type == EventType.Repaint && backButton)
            {
                Rect buttonRect = GUILayoutUtility.GetLastRect();
                CoreGUIStyles.GetButtonLeftArrow().Draw(
                    new Rect(
                        buttonRect.x,
                        buttonRect.y + buttonRect.height / 2.0f - ARROW_SIZE / 2.0f,
                        ARROW_SIZE, ARROW_SIZE
                        ),
                    false, false, false, false
                    );
            }

            EditorGUILayout.EndHorizontal();
            return(goBack);
        }
Пример #5
0
        // INSPECTOR: -----------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            serializedObject.Update();
            this.UpdateSubEditors(this.instance.conditions);

            int  removConditionIndex     = -1;
            int  duplicateConditionIndex = -1;
            int  copyConditionIndex      = -1;
            bool forceRepaint            = false;
            bool conditionsCollapsed     = true;

            int spConditionsSize = this.spConditions.arraySize;

            for (int i = 0; i < spConditionsSize; ++i)
            {
                bool forceSortRepaint = this.editorSortableList.CaptureSortEvents(this.handleRect[i], i);
                forceRepaint = forceSortRepaint || forceRepaint;

                GUILayout.BeginVertical();
                ItemReturnOperation returnOperation = this.PaintConditionsHeader(i);
                if (returnOperation.removeIndex)
                {
                    removConditionIndex = i;
                }
                if (returnOperation.duplicateIndex)
                {
                    duplicateConditionIndex = i;
                }
                if (returnOperation.copyIndex)
                {
                    copyConditionIndex = i;
                }

                conditionsCollapsed &= this.isExpanded[i].target;
                using (var group = new EditorGUILayout.FadeGroupScope(this.isExpanded[i].faded))
                {
                    if (group.visible)
                    {
                        EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded());
                        if (this.subEditors[i] != null)
                        {
                            this.subEditors[i].OnInspectorGUI();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox(MSG_UNDEF_CONDITION_1, MessageType.Warning);
                            EditorGUILayout.HelpBox(MSG_UNDEF_CONDITION_2, MessageType.None);
                        }
                        EditorGUILayout.EndVertical();
                    }
                }

                GUILayout.EndVertical();

                if (UnityEngine.Event.current.type == EventType.Repaint)
                {
                    this.objectRect[i] = GUILayoutUtility.GetLastRect();
                }

                this.editorSortableList.PaintDropPoints(this.objectRect[i], i, spConditionsSize);
            }

            Rect rectControls      = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());
            Rect rectAddConditions = new Rect(
                rectControls.x,
                rectControls.y,
                SelectTypePanel.WINDOW_WIDTH,
                rectControls.height
                );

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

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

            Rect rectCollapse = new Rect(
                rectPlay.x - 25f,
                rectPlay.y,
                25f,
                rectPlay.height
                );

            Rect rectUnused = new Rect(
                rectPaste.x + rectPaste.width,
                rectControls.y,
                rectControls.width - ((rectPaste.x + rectPaste.width) - rectControls.x) - rectPlay.width - rectCollapse.width,
                rectControls.height
                );

            if (GUI.Button(rectAddConditions, "Add Condition", CoreGUIStyles.GetToggleButtonLeftAdd()))
            {
                SelectTypePanel selectTypePanel = new SelectTypePanel(this.AddNewCondition, "Conditions", typeof(ICondition));
                PopupWindow.Show(this.addConditionsButtonRect, selectTypePanel);
            }

            if (UnityEngine.Event.current.type == EventType.Repaint)
            {
                this.addConditionsButtonRect = rectAddConditions;
            }

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

            EditorGUI.BeginDisabledGroup(CLIPBOARD_ICONDITION == null);
            if (GUI.Button(rectPaste, gcPaste, CoreGUIStyles.GetButtonMid()))
            {
                ICondition conditionCreated = (ICondition)this.instance.gameObject.AddComponent(CLIPBOARD_ICONDITION.GetType());
                EditorUtility.CopySerialized(CLIPBOARD_ICONDITION, conditionCreated);

                this.spConditions.AddToObjectArray(conditionCreated);
                this.AddSubEditorElement(conditionCreated, -1, true);

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

            GUI.Label(rectUnused, "", CoreGUIStyles.GetToggleButtonMidOn());

            GUIContent gcToggle = (conditionsCollapsed
               ? ClausesUtilities.Get(ClausesUtilities.Icon.Collapse)
               : ClausesUtilities.Get(ClausesUtilities.Icon.Expand)
                                   );

            EditorGUI.BeginDisabledGroup(this.instance.conditions.Length == 0);
            if (GUI.Button(rectCollapse, gcToggle, CoreGUIStyles.GetButtonMid()))
            {
                for (int i = 0; i < this.subEditors.Length; ++i)
                {
                    this.SetExpand(i, !conditionsCollapsed);
                }
            }
            EditorGUI.EndDisabledGroup();

            GUIContent gcPlay = ClausesUtilities.Get(ClausesUtilities.Icon.Play);

            EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);
            if (GUI.Button(rectPlay, gcPlay, CoreGUIStyles.GetButtonRight()))
            {
                Debug.LogFormat("<b>Conditions Evaluation:</b> {0}", this.instance.Check(null));
            }
            EditorGUI.EndDisabledGroup();

            if (removConditionIndex >= 0)
            {
                ICondition source = (ICondition)this.spConditions.GetArrayElementAtIndex(removConditionIndex).objectReferenceValue;

                this.spConditions.RemoveFromObjectArrayAt(removConditionIndex);
                this.RemoveSubEditorsElement(removConditionIndex);
                DestroyImmediate(source, true);
                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
            }

            if (duplicateConditionIndex >= 0)
            {
                int srcIndex = duplicateConditionIndex;
                int dstIndex = duplicateConditionIndex + 1;

                ICondition source = (ICondition)this.subEditors[srcIndex].target;
                ICondition copy   = (ICondition)this.instance.gameObject.AddComponent(source.GetType());

                this.spConditions.InsertArrayElementAtIndex(dstIndex);
                this.spConditions.GetArrayElementAtIndex(dstIndex).objectReferenceValue = copy;

                EditorUtility.CopySerialized(source, copy);
                this.AddSubEditorElement(copy, dstIndex, true);
                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
            }

            if (copyConditionIndex >= 0)
            {
                ICondition source = (ICondition)this.subEditors[copyConditionIndex].target;

                GameObject conditionInstance = new GameObject();
                conditionInstance.hideFlags = HideFlags.HideAndDontSave;

                CLIPBOARD_ICONDITION = (ICondition)conditionInstance.AddComponent(source.GetType());
                EditorUtility.CopySerialized(source, CLIPBOARD_ICONDITION);
            }

            EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes();
            if (swapIndexes != null)
            {
                this.spConditions.MoveArrayElement(swapIndexes.src, swapIndexes.dst);
                this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst);
                if (!Application.isPlaying)
                {
                    EditorSceneManager.MarkSceneDirty(this.instance.gameObject.scene);
                }
            }

            if (EditorApplication.isPlaying)
            {
                forceRepaint = true;
            }
            if (forceRepaint)
            {
                this.Repaint();
            }
            serializedObject.ApplyModifiedProperties();
        }
Пример #6
0
        private ItemReturnOperation PaintConditionsHeader(int i)
        {
            ItemReturnOperation returnOperation = new ItemReturnOperation();

            Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());

            this.PaintDragHandle(i, rectHeader);

            Texture2D conditionIcon = (i < this.subEditors.Length && this.subEditors[i] != null ?
                                       this.subEditors[i].GetIcon()
                : null
                                       );

            string conditionName = (this.isExpanded[i].target ? " ▾ " : " ▸ ");

            conditionName += (this.instance.conditions[i] != null
                     ? this.instance.conditions[i].GetNodeTitle()
                                : "<i>Undefined Condition</i>"
                              );

            GUIStyle style = (this.isExpanded[i].target
                                ? CoreGUIStyles.GetToggleButtonMidOn()
                                : CoreGUIStyles.GetToggleButtonMidOff()
                              );

            Rect rectDelete = new Rect(
                rectHeader.x + rectHeader.width - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectDuplicate = new Rect(
                rectDelete.x - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectCopy = new Rect(
                rectDuplicate.x - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectMain = new Rect(
                rectHeader.x + 25f,
                rectHeader.y,
                rectHeader.width - (25f * 4f),
                rectHeader.height
                );

            if (GUI.Button(rectMain, new GUIContent(conditionName, conditionIcon), style))
            {
                this.ToggleExpand(i);
            }

            GUIContent gcCopy      = ClausesUtilities.Get(ClausesUtilities.Icon.Copy);
            GUIContent gcDuplicate = ClausesUtilities.Get(ClausesUtilities.Icon.Duplicate);
            GUIContent gcDelete    = ClausesUtilities.Get(ClausesUtilities.Icon.Delete);

            if (this.instance.conditions[i] != null && GUI.Button(rectCopy, gcCopy, CoreGUIStyles.GetButtonMid()))
            {
                returnOperation.copyIndex = true;
            }

            if (this.instance.conditions[i] != null && GUI.Button(rectDuplicate, gcDuplicate, CoreGUIStyles.GetButtonMid()))
            {
                returnOperation.duplicateIndex = true;
            }

            if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight()))
            {
                returnOperation.removeIndex = true;
            }

            return(returnOperation);
        }
Пример #7
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();
        }
Пример #8
0
        private void PaintInteractions()
        {
            int removeInteractionIndex    = -1;
            int duplicateInteractionIndex = -1;
            int copyInteractionIndex      = -1;

            bool forceRepaint     = false;
            int  interactionsSize = this.spInteractions.arraySize;

            for (int i = 0; i < interactionsSize; ++i)
            {
                if (this.subEditors == null || i >= this.subEditors.Length || this.subEditors[i] == null)
                {
                    continue;
                }

                bool repaint = this.editorSortableList.CaptureSortEvents(this.subEditors[i].handleDragRect, i);
                forceRepaint = repaint || forceRepaint;

                EditorGUILayout.BeginVertical();
                Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());
                this.PaintDragHandle(i, rectHeader);

                EditorGUIUtility.AddCursorRect(this.subEditors[i].handleDragRect, MouseCursor.Pan);
                string   name  = (this.isExpanded[i].target ? "▾ " : "▸ ") + this.instance.interactions[i].description;
                GUIStyle style = (this.isExpanded[i].target
                                        ? CoreGUIStyles.GetToggleButtonMidOn()
                                        : CoreGUIStyles.GetToggleButtonMidOff()
                                  );

                Rect rectDelete = new Rect(
                    rectHeader.x + rectHeader.width - 25f,
                    rectHeader.y,
                    25f,
                    rectHeader.height
                    );

                Rect rectDuplicate = new Rect(
                    rectDelete.x - 25f,
                    rectHeader.y,
                    25f,
                    rectHeader.height
                    );

                Rect rectCopy = new Rect(
                    rectDuplicate.x - 25f,
                    rectHeader.y,
                    25f,
                    rectHeader.height
                    );

                Rect rectMain = new Rect(
                    rectHeader.x + 25f,
                    rectHeader.y,
                    rectHeader.width - (25f * 4f),
                    rectHeader.height
                    );

                if (GUI.Button(rectMain, name, style))
                {
                    this.ToggleExpand(i);
                }

                GUIContent gcCopy      = InteractionUtilities.Get(InteractionUtilities.Icon.Copy);
                GUIContent gcDuplicate = InteractionUtilities.Get(InteractionUtilities.Icon.Duplicate);
                GUIContent gcDelete    = InteractionUtilities.Get(InteractionUtilities.Icon.Delete);

                if (GUI.Button(rectCopy, gcCopy, CoreGUIStyles.GetButtonMid()))
                {
                    copyInteractionIndex = i;
                }

                if (GUI.Button(rectDuplicate, gcDuplicate, CoreGUIStyles.GetButtonMid()))
                {
                    duplicateInteractionIndex = i;
                }

                if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight()))
                {
                    if (EditorUtility.DisplayDialog(MSG_REMOVE_TITLE, MSG_REMOVE_DESCR, "Yes", "Cancel"))
                    {
                        removeInteractionIndex = i;
                    }
                }

                using (var group = new EditorGUILayout.FadeGroupScope(this.isExpanded[i].faded))
                {
                    if (group.visible)
                    {
                        EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded());
                        this.subEditors[i].OnInteractionGUI();
                        EditorGUILayout.EndVertical();
                    }
                }

                EditorGUILayout.EndVertical();
                if (UnityEngine.Event.current.type == EventType.Repaint)
                {
                    this.subEditors[i].interactionRect = GUILayoutUtility.GetLastRect();
                }

                this.editorSortableList.PaintDropPoints(this.subEditors[i].interactionRect, i, interactionsSize);
            }

            if (copyInteractionIndex >= 0)
            {
                Interaction source       = (Interaction)this.subEditors[copyInteractionIndex].target;
                GameObject  copyInstance = EditorUtility.CreateGameObjectWithHideFlags(
                    "Interaction (Copy)",
                    HideFlags.HideAndDontSave
                    );

                CLIPBOARD_INTERACTION = (Interaction)copyInstance.AddComponent(source.GetType());
                EditorUtility.CopySerialized(source, CLIPBOARD_INTERACTION);

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

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

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

            if (duplicateInteractionIndex >= 0)
            {
                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);
            }

            if (removeInteractionIndex >= 0)
            {
                this.subEditors[removeInteractionIndex].OnDestroyInteraction();
                Interaction rmInteraction = (Interaction)this.spInteractions
                                            .GetArrayElementAtIndex(removeInteractionIndex).objectReferenceValue;

                this.spInteractions.DeleteArrayElementAtIndex(removeInteractionIndex);
                this.spInteractions.RemoveFromObjectArrayAt(removeInteractionIndex);
                DestroyImmediate(rmInteraction, true);
            }

            EditorSortableList.SwapIndexes swapIndexes = this.editorSortableList.GetSortIndexes();
            if (swapIndexes != null)
            {
                this.spInteractions.MoveArrayElement(swapIndexes.src, swapIndexes.dst);
                this.MoveSubEditorsElement(swapIndexes.src, swapIndexes.dst);
            }

            if (forceRepaint)
            {
                this.Repaint();
            }
        }
Пример #9
0
        private void PaintElements(TreeNode <NodeData> branch, bool backButton)
        {
            if (this.PaintTitle(branch.GetID(), backButton))
            {
                this.currentBranch = this.pathTrace.Pop();
                this.listIndex     = this.currentBranch.GetData().listIndex;
            }

            this.scroll = EditorGUILayout.BeginScrollView(this.scroll, GUIStyle.none, GUI.skin.verticalScrollbar);
            int elemIndex = 0;

            foreach (TreeNode <NodeData> element in branch)
            {
                NodeData nodeData = element.GetData();

                bool mouseEnter = this.listIndex == elemIndex && UnityEngine.Event.current.type == EventType.MouseDown;

                Rect buttonRect = GUILayoutUtility.GetRect(nodeData.content, this.elementSelectorStyle);

                bool buttonHasFocus = this.listIndex == elemIndex;
                if (UnityEngine.Event.current.type == EventType.Repaint)
                {
                    if (this.listIndex == elemIndex)
                    {
                        this.listSelectedRect = buttonRect;
                    }

                    this.elementSelectorStyle.Draw(
                        buttonRect,
                        nodeData.content,
                        buttonHasFocus,
                        buttonHasFocus,
                        false,
                        false
                        );

                    if (nodeData.component == null)
                    {
                        CoreGUIStyles.GetButtonRightArrow().Draw(
                            new Rect(
                                buttonRect.x + buttonRect.width - ARROW_SIZE,
                                buttonRect.y + buttonRect.height / 2.0f - ARROW_SIZE / 2.0f,
                                ARROW_SIZE, ARROW_SIZE
                                ),
                            false, false, false, false
                            );
                    }
                }

                if (buttonHasFocus)
                {
                    if (nodeData.component == null)
                    {
                        if (mouseEnter || this.keyPressedRight || this.keyPressedEnter)
                        {
                            if (this.keyPressedRight)
                            {
                                UnityEngine.Event.current.Use();
                            }
                            if (this.keyPressedEnter)
                            {
                                UnityEngine.Event.current.Use();
                            }

                            this.currentBranch.GetData().listIndex = this.listIndex;
                            this.pathTrace.Push(this.currentBranch);

                            this.currentBranch = this.currentBranch.GetChild(element.GetID());
                            this.listIndex     = 0;
                        }
                    }
                    else
                    {
                        if (mouseEnter || this.keyPressedEnter)
                        {
                            if (this.keyPressedEnter)
                            {
                                UnityEngine.Event.current.Use();
                            }
                            if (this.callback != null)
                            {
                                this.callback(nodeData.component);
                            }
                            this.editorWindow.Close();
                        }
                    }
                }

                if (UnityEngine.Event.current.type == EventType.MouseMove &&
                    GUILayoutUtility.GetLastRect().Contains(UnityEngine.Event.current.mousePosition))
                {
                    this.listIndex = elemIndex;
                    this.currentBranch.GetData().listIndex = this.listIndex;
                }

                ++elemIndex;
            }

            if (this.keyPressedDown && this.listIndex < elemIndex - 1)
            {
                this.listIndex++;
                this.currentBranch.GetData().listIndex = this.listIndex;
                UnityEngine.Event.current.Use();
            }
            else if (this.keyPressedUp && this.listIndex > 0)
            {
                this.listIndex--;
                this.currentBranch.GetData().listIndex = this.listIndex;
                UnityEngine.Event.current.Use();
            }

            EditorGUILayout.EndScrollView();
            float scrollHeight = GUILayoutUtility.GetLastRect().height;

            if (UnityEngine.Event.current.type == EventType.Repaint && this.keyFlagVerticalMoved)
            {
                this.keyFlagVerticalMoved = false;
                if (this.listSelectedRect != Rect.zero)
                {
                    if (this.scroll.y > this.listSelectedRect.y)
                    {
                        this.scroll = Vector2.up * (this.listSelectedRect.position.y);
                        this.editorWindow.Repaint();
                    }
                    else if (this.scroll.y + scrollHeight < this.listSelectedRect.position.y + this.listSelectedRect.size.y)
                    {
                        float positionY = this.listSelectedRect.y + this.listSelectedRect.height - scrollHeight;
                        this.scroll = Vector2.up * positionY;
                        this.editorWindow.Repaint();
                    }
                }
            }
        }
Пример #10
0
        private ItemReturnOperation PaintActionHeader(int i)
        {
            ItemReturnOperation returnOperation = new ItemReturnOperation();

            Color defaultBackgroundColor = GUI.backgroundColor;

            if (this.spExecutingIndex.intValue == i)
            {
                GUI.backgroundColor = COLOR_EXECUTING_ACTION;
            }

            Rect rectHeader = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOn());

            this.PaintDragHandle(i, rectHeader);

            Texture2D icon = this.subEditors[i].GetIcon();
            string    name = (this.isExpanded[i].target ? " ▾ " : " ▸ ");

            name += (this.instance.actions[i] != null
                ? this.instance.actions[i].GetNodeTitle()
                : "<i>Undefined Action</i>"
                     );

            GUIStyle style = (this.isExpanded[i].target
                ? CoreGUIStyles.GetToggleButtonMidOn()
                : CoreGUIStyles.GetToggleButtonMidOff()
                              );

            float opacity = 1.0f;

            if (this.subEditors[i] != null && this.subEditors[i].action != null)
            {
                opacity = this.subEditors[i].action.GetOpacity();
            }

            Color tempColor = style.normal.textColor;

            style.normal.textColor = new Color(
                style.normal.textColor.r,
                style.normal.textColor.g,
                style.normal.textColor.b,
                opacity
                );

            Rect rectDelete = new Rect(
                rectHeader.x + rectHeader.width - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectDuplicate = new Rect(
                rectDelete.x - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectCopy = new Rect(
                rectDuplicate.x - 25f,
                rectHeader.y,
                25f,
                rectHeader.height
                );

            Rect rectMain = new Rect(
                rectHeader.x + 25f,
                rectHeader.y,
                rectHeader.width - (25f * 4f),
                rectHeader.height
                );

            if (GUI.Button(rectMain, new GUIContent(name, icon), style))
            {
                this.ToggleExpand(i);
            }

            style.normal.textColor = tempColor;

            GUIContent gcCopy      = InteractionUtilities.Get(InteractionUtilities.Icon.Copy);
            GUIContent gcDuplicate = InteractionUtilities.Get(InteractionUtilities.Icon.Duplicate);
            GUIContent gcDelete    = InteractionUtilities.Get(InteractionUtilities.Icon.Delete);

            if (this.instance.actions[i] != null && GUI.Button(rectCopy, gcCopy, CoreGUIStyles.GetButtonMid()))
            {
                returnOperation.copyIndex = true;
            }

            if (this.instance.actions[i] != null && GUI.Button(rectDuplicate, gcDuplicate, CoreGUIStyles.GetButtonMid()))
            {
                returnOperation.duplicateIndex = true;
            }

            if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight()))
            {
                returnOperation.removeIndex = true;
            }

            GUI.backgroundColor = defaultBackgroundColor;

            return(returnOperation);
        }
Пример #11
0
        private void DoLayoutListOptions(ReorderableList list, string itemType)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Create " + itemType, CoreGUIStyles.GetButtonLeft()))
            {
                if (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab)
                {
                    int itemIndex = list.count;
                    list.serializedProperty.InsertArrayElementAtIndex(itemIndex);
                    SerializedProperty spNewItem = list.serializedProperty.GetArrayElementAtIndex(itemIndex);
                    list.index = itemIndex;

                    if (itemType == "Event")
                    {
                        spNewItem.objectReferenceValue = CreatePrefabObject.AddGameObjectToPrefab <Event>(
                            PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                            itemType
                            );
                    }
                    else if (itemType == "Actions")
                    {
                        spNewItem.objectReferenceValue = CreatePrefabObject.AddGameObjectToPrefab <Actions>(
                            PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                            itemType
                            );
                    }

                    this.serializedObject.ApplyModifiedProperties();
                    this.serializedObject.Update();
                }
                else
                {
                    this.CreateTriggerOption(list, itemType);
                }
            }

            if (GUILayout.Button("+", CoreGUIStyles.GetButtonMid(), GUILayout.MaxWidth(30f)))
            {
                int insertIndex = list.count;
                list.serializedProperty.InsertArrayElementAtIndex(insertIndex);
                list.serializedProperty.GetArrayElementAtIndex(insertIndex).objectReferenceValue = null;
            }

            if (GUILayout.Button("-", CoreGUIStyles.GetButtonRight(), GUILayout.MaxWidth(30f)))
            {
                bool indexInRange = (list.index >= 0 && list.index < list.count);
                if (indexInRange)
                {
                    SerializedProperty spItem = list.serializedProperty.GetArrayElementAtIndex(list.index);
                    if (spItem.objectReferenceValue != null)
                    {
                        if (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab)
                        {
                            CreatePrefabObject.RemoveGameObjectFromPrefab(
                                PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                                ((MonoBehaviour)spItem.objectReferenceValue).gameObject
                                );

                            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(this.trigger.gameObject));
                        }
                        else
                        {
                            Undo.DestroyObjectImmediate(((MonoBehaviour)spItem.objectReferenceValue).gameObject);
                        }
                    }

                    list.serializedProperty.RemoveFromObjectArrayAt(list.index);
                }

                if (list.index < 0)
                {
                    list.index = 0;
                }
                if (list.index >= list.count)
                {
                    list.index = list.count - 1;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Пример #12
0
        private void DoLayoutConfigurationOptions()
        {
            int removeIndex = -1;

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.BeginHorizontal();

            int ignitersIndex = GUILayout.Toolbar(this.ignitersIndex, IGNITERS_PLATFORM_NAMES);

            if (ignitersIndex != this.ignitersIndex)
            {
                this.ignitersIndex = ignitersIndex;
                EditorPrefs.SetInt(KEY_IGNITER_INDEX_PREF, this.ignitersIndex);
            }

            if (GUILayout.Button("+", CoreGUIStyles.GetButtonLeft(), GUILayout.Width(30f)))
            {
                this.SelectPlatformMenu();
            }

            EditorGUI.BeginDisabledGroup(this.ignitersIndex == 0);
            if (GUILayout.Button("-", CoreGUIStyles.GetButtonRight(), GUILayout.Width(30f)))
            {
                removeIndex = this.ignitersIndex;
            }

            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PrefixLabel(this.ignitersCache[this.ignitersIndex].name, EditorStyles.miniBoldLabel);
            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Change Trigger", GUILayout.Width(SelectTypePanel.WINDOW_WIDTH)))
            {
                SelectTypePanel selectTypePanel = new SelectTypePanel(this.SelectNewIgniter, "Triggers", typeof(Igniter));
                PopupWindow.Show(this.selectIgniterButtonRect, selectTypePanel);
            }

            if (UnityEngine.Event.current.type == EventType.Repaint)
            {
                this.selectIgniterButtonRect = GUILayoutUtility.GetLastRect();
            }

            EditorGUILayout.EndHorizontal();

            if (this.ignitersCache[this.ignitersIndex].serializedObject != null)
            {
                string comment = this.ignitersCache[this.ignitersIndex].comment;
                if (!string.IsNullOrEmpty(comment))
                {
                    EditorGUILayout.HelpBox(comment, MessageType.Info);
                }

                Igniter.PaintEditor(this.ignitersCache[this.ignitersIndex].serializedObject);
            }

            if (this.ignitersCache[this.ignitersIndex].requiresCollider)
            {
                Collider collider = this.trigger.GetComponent <Collider>();
                if (!collider)
                {
                    this.PaintNoCollider();
                }
            }

            EditorGUILayout.EndVertical();

            if (removeIndex > 0)
            {
                UnityEngine.Object obj = this.spIgnitersValues.GetArrayElementAtIndex(removeIndex).objectReferenceValue;
                this.spIgnitersValues.GetArrayElementAtIndex(removeIndex).objectReferenceValue = null;

                this.spIgnitersKeys.DeleteArrayElementAtIndex(removeIndex);
                this.spIgnitersValues.DeleteArrayElementAtIndex(removeIndex);

                if (obj != null)
                {
                    DestroyImmediate(obj, true);
                }

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

                this.updateIgnitersPlatforms = true;
                if (this.ignitersIndex >= this.spIgnitersKeys.arraySize)
                {
                    this.ignitersIndex = this.spIgnitersKeys.arraySize - 1;
                }
            }
        }
Пример #13
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();
        }
Пример #14
0
        private void PaintItems()
        {
            int  itemsCount   = this.spItems.arraySize;
            int  removeIndex  = -1;
            bool forceRepaint = false;

            GUIContent gcDelete = ClausesUtilities.Get(ClausesUtilities.Icon.Delete);

            for (int i = 0; i < itemsCount; ++i)
            {
                SerializedProperty spItem        = this.spItems.GetArrayElementAtIndex(i);
                SerializedProperty spIOption     = spItem.FindPropertyRelative(PROP_OPTION);
                SerializedProperty spIActions    = spItem.FindPropertyRelative(PROP_ACTIONS);
                SerializedProperty spIConditions = spItem.FindPropertyRelative(PROP_CONDITIONS);

                Rect rectItem = GUILayoutUtility.GetRect(GUIContent.none, CoreGUIStyles.GetToggleButtonNormalOff());

                Rect rectHandle = new Rect(
                    rectItem.x,
                    rectItem.y,
                    25f,
                    rectItem.height
                    );

                Rect rectToggle = new Rect(
                    rectHandle.x + rectHandle.width,
                    rectHandle.y,
                    25f,
                    rectHandle.height
                    );

                Rect rectDelete = new Rect(
                    rectItem.x + (rectItem.width - 25f),
                    rectToggle.y,
                    25f,
                    rectToggle.height
                    );

                Rect rectCont = new Rect(
                    rectToggle.x + rectToggle.width,
                    rectToggle.y,
                    rectItem.width - (rectHandle.width + rectToggle.width + rectDelete.width),
                    rectToggle.height
                    );

                GUI.Label(rectHandle, "=", CoreGUIStyles.GetButtonLeft());
                bool forceSortRepaint = this.sortableList.CaptureSortEvents(rectHandle, i);
                forceRepaint = forceSortRepaint || forceRepaint;

                EditorGUIUtility.AddCursorRect(rectHandle, MouseCursor.Pan);

                GUIContent gcToggle = null;
                if (spIOption.intValue == (int)Trigger.ItemOpts.Actions)
                {
                    gcToggle = GC_ACTIONS;
                }
                if (spIOption.intValue == (int)Trigger.ItemOpts.Conditions)
                {
                    gcToggle = GC_CONDITIONS;
                }

                if (GUI.Button(rectToggle, gcToggle, CoreGUIStyles.GetButtonMid()))
                {
                    switch (spIOption.intValue)
                    {
                    case (int)Trigger.ItemOpts.Actions:
                        spIOption.intValue = (int)Trigger.ItemOpts.Conditions;
                        break;

                    case (int)Trigger.ItemOpts.Conditions:
                        spIOption.intValue = (int)Trigger.ItemOpts.Actions;
                        break;
                    }
                }

                GUI.Label(rectCont, string.Empty, CoreGUIStyles.GetButtonMid());
                Rect rectField = new Rect(
                    rectCont.x + 2f,
                    rectCont.y + (rectCont.height / 2f - EditorGUIUtility.singleLineHeight / 2f),
                    rectCont.width - 7f,
                    EditorGUIUtility.singleLineHeight
                    );

                switch (spIOption.intValue)
                {
                case (int)Trigger.ItemOpts.Actions:
                    EditorGUI.PropertyField(rectField, spIActions, GUIContent.none, true);
                    break;

                case (int)Trigger.ItemOpts.Conditions:
                    EditorGUI.PropertyField(rectField, spIConditions, GUIContent.none, true);
                    break;
                }


                if (GUI.Button(rectDelete, gcDelete, CoreGUIStyles.GetButtonRight()))
                {
                    removeIndex = i;
                }

                this.sortableList.PaintDropPoints(rectItem, i, itemsCount);
            }

            if (removeIndex != -1 && removeIndex < this.spItems.arraySize)
            {
                SerializedProperty spItem        = this.spItems.GetArrayElementAtIndex(removeIndex);
                SerializedProperty spIOption     = spItem.FindPropertyRelative(PROP_OPTION);
                SerializedProperty spIActions    = spItem.FindPropertyRelative(PROP_ACTIONS);
                SerializedProperty spIConditions = spItem.FindPropertyRelative(PROP_CONDITIONS);
                UnityEngine.Object @object       = null;
                switch (spIOption.intValue)
                {
                case (int)Trigger.ItemOpts.Actions: @object = spIActions.objectReferenceValue; break;

                case (int)Trigger.ItemOpts.Conditions: @object = spIConditions.objectReferenceValue; break;
                }

                this.spItems.DeleteArrayElementAtIndex(removeIndex);
            }

            EditorSortableList.SwapIndexes swapIndexes = this.sortableList.GetSortIndexes();
            if (swapIndexes != null)
            {
                this.spItems.MoveArrayElement(swapIndexes.src, swapIndexes.dst);
            }

            if (forceRepaint)
            {
                this.Repaint();
            }
        }
Пример #15
0
        private void PaintItemsToolbar()
        {
            Rect rectItem = GUILayoutUtility.GetRect(
                GUIContent.none, CoreGUIStyles.GetToggleButtonOff()
                );

            Rect rectItem1 = new Rect(
                rectItem.x,
                rectItem.y,
                ITEMS_TOOLBAR_WIDTH,
                rectItem.height
                );
            Rect rectItem2 = new Rect(
                rectItem1.x + rectItem1.width,
                rectItem1.y,
                rectItem1.width,
                rectItem1.height
                );
            Rect rectItem3 = new Rect(
                rectItem2.x + rectItem2.width,
                rectItem2.y,
                rectItem2.width,
                rectItem2.height
                );
            Rect rectItemH = new Rect(
                //rectItem.x + (rectItem.width - ITEMS_TOOLBAR_WIDTH),
                rectItem3.x + rectItem3.width + 5f,
                rectItem2.y,
                ITEMS_TOOLBAR_WIDTH,
                rectItem2.height
                );

            if (GUI.Button(rectItem1, GC_ACTIONS, CoreGUIStyles.GetButtonLeft()))
            {
                int index = this.spItems.arraySize;
                this.spItems.InsertArrayElementAtIndex(index);

                SerializedProperty spItem = this.spItems.GetArrayElementAtIndex(index);
                spItem.FindPropertyRelative(PROP_OPTION).intValue = (int)Trigger.ItemOpts.Actions;
                spItem.FindPropertyRelative(PROP_ACTIONS).objectReferenceValue    = this.CreateSubObject <Actions>();
                spItem.FindPropertyRelative(PROP_CONDITIONS).objectReferenceValue = null;
            }

            if (GUI.Button(rectItem2, GC_CONDITIONS, CoreGUIStyles.GetButtonMid()))
            {
                int index = this.spItems.arraySize;
                this.spItems.InsertArrayElementAtIndex(index);

                SerializedProperty spItem = this.spItems.GetArrayElementAtIndex(index);
                spItem.FindPropertyRelative(PROP_OPTION).intValue = (int)Trigger.ItemOpts.Conditions;
                spItem.FindPropertyRelative(PROP_ACTIONS).objectReferenceValue    = null;
                spItem.FindPropertyRelative(PROP_CONDITIONS).objectReferenceValue = this.CreateSubObject <Conditions>();
            }

            if (GUI.Button(rectItem3, "+", CoreGUIStyles.GetButtonRight()))
            {
                int index = this.spItems.arraySize;
                this.spItems.InsertArrayElementAtIndex(index);

                SerializedProperty spItem = this.spItems.GetArrayElementAtIndex(index);
                spItem.FindPropertyRelative(PROP_OPTION).intValue = (int)Trigger.ItemOpts.Actions;
                spItem.FindPropertyRelative(PROP_ACTIONS).objectReferenceValue    = null;
                spItem.FindPropertyRelative(PROP_CONDITIONS).objectReferenceValue = null;
            }

            EditorGUI.BeginDisabledGroup(this.trigger.gameObject.GetComponent <Hotspot>() != null);
            if (GUI.Button(rectItemH, GC_HOTSPOT))
            {
                Undo.AddComponent <Hotspot>(this.trigger.gameObject);
            }
            EditorGUI.EndDisabledGroup();
        }