Beispiel #1
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }

            this.condition           = (ICondition)target;
            this.condition.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
            this.condition.OnEnableEditor(this.condition);

            Type   conditionType = this.condition.GetType();
            string conditionName = (string)conditionType.GetField("NAME", BINDING_FLAGS).GetValue(null);

            FieldInfo customIconsFieldInfo = conditionType.GetField(
                SelectTypePanel.CUSTOM_ICON_PATH_VARIABLE,
                BINDING_FLAGS
                );

            string iconsPath = SelectTypePanel.ICONS_CONDITIONS_PATH;

            if (customIconsFieldInfo != null)
            {
                string customIconsPath = (string)customIconsFieldInfo.GetValue(null);
                if (!string.IsNullOrEmpty(customIconsPath))
                {
                    iconsPath = customIconsPath;
                }
            }

            string conditionIconPath = Path.Combine(
                iconsPath,
                SelectTypePanel.GetName(conditionName) + ".png"
                );

            this.icon = AssetDatabase.LoadAssetAtPath <Texture2D>(conditionIconPath);
            if (icon == null)
            {
                icon = AssetDatabase.LoadAssetAtPath <Texture2D>(Path.Combine(iconsPath, "Default.png"));
            }
            if (icon == null)
            {
                icon = EditorGUIUtility.FindTexture("GameObject Icon");
            }
        }
Beispiel #2
0
        private void CreateList()
        {
            NodeData rootData = new NodeData(this.rootName);

            this.categorizedTree   = new TreeNode <NodeData>(this.rootName, rootData);
            this.uncategorizedList = new List <TreeNode <NodeData> >(
                new TreeNode <NodeData>(this.rootName, rootData)
                );

            List <Type> types     = this.GetAllClassTypesOf(this.baseType);
            int         typesSize = types.Count;

            for (int i = 0; i < typesSize; ++i)
            {
                string   actionName = (string)types[i].GetField("NAME", BINDING_FLAGS).GetValue(null);
                string[] categories = SelectTypePanel.GetCategories(actionName);

                TreeNode <NodeData> node = this.categorizedTree;
                for (int j = 0; j < categories.Length; ++j)
                {
                    if (node.HasChild(categories[j]))
                    {
                        node = node.GetChild(categories[j]);
                    }
                    else
                    {
                        NodeData            nodeData = new NodeData(categories[j]);
                        TreeNode <NodeData> treeNode = new TreeNode <NodeData>(categories[j], nodeData);
                        node = node.AddChild(treeNode);
                    }
                }

                NodeData leafData = new NodeData(actionName, types[i]);
                node.AddChild(new TreeNode <NodeData>(actionName, leafData));
                this.uncategorizedList.Add(new TreeNode <NodeData>(actionName, leafData));
            }

            this.currentBranch = this.categorizedTree;
            this.pathTrace     = new Stack <TreeNode <NodeData> >();
        }
Beispiel #3
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();
        }
Beispiel #4
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;
                }
            }
        }