Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            ActionListAsset _target = (ActionListAsset)target;

            ShowPropertiesGUI(_target);
            EditorGUILayout.Space();

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                UnityVersionHandler.CustomSetDirty(_target);
                return;
            }

            if (actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
                {
                    Undo.RecordObject(_target, "Expand actions");
                    foreach (AC.Action action in _target.actions)
                    {
                        action.isDisplayed = true;
                    }
                }
                if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
                {
                    Undo.RecordObject(_target, "Collapse actions");
                    foreach (AC.Action action in _target.actions)
                    {
                        action.isDisplayed = false;
                    }
                }
                if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
                {
                    ActionListEditorWindow.Init(_target);
                }

                GUI.enabled = Application.isPlaying;

                bool isRunning = false;
                if (Application.isPlaying)
                {
                    if (KickStarter.actionListAssetManager != null)
                    {
                        isRunning = KickStarter.actionListAssetManager.IsListRunning(_target) && !_target.canRunMultipleInstances;
                    }
                }

                if (isRunning)
                {
                    if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
                    {
                        _target.KillAllInstances();
                    }
                }
                else
                {
                    if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
                    {
                        if (KickStarter.actionListAssetManager != null)
                        {
                            if (!_target.canRunMultipleInstances)
                            {
                                int numRemoved = KickStarter.actionListAssetManager.EndAssetList(_target);
                                if (numRemoved > 0)
                                {
                                    ACDebug.Log("Removed 1 instance of ActionList asset '" + _target.name + "' because it is set to only run one at a time.", _target);
                                }
                            }

                            AdvGame.RunActionListAsset(_target);
                        }
                        else
                        {
                            ACDebug.LogWarning("An AC PersistentEngine object must be present in the scene for ActionList assets to run.", _target);
                        }
                    }
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                if (Application.isPlaying)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.Init(_target);
                    }
                    if (GUILayout.Button("Run now", GUILayout.Height(40f)))
                    {
                        AdvGame.RunActionListAsset(_target);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.Init(_target);
                    }
                }
                UnityVersionHandler.CustomSetDirty(_target);
                return;
            }

            EditorGUILayout.Space();

            for (int i = 0; i < _target.actions.Count; i++)
            {
                int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]);

                if (_target.actions[i] == null)
                {
                    RebuildAction(_target.actions[i], typeIndex, _target, i);
                }

                _target.actions[i].isAssetFile = true;

                CustomGUILayout.BeginVertical();

                string actionLabel = " (" + i + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true);
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                EditorGUILayout.BeginHorizontal();
                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f));
                }

                if (GUILayout.Button("", CustomStyles.IconCog))
                {
                    ActionSideMenu(_target.actions[i]);
                }
                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isDisplayed)
                {
                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");

                            RebuildAction(_target.actions[i], newTypeIndex, _target, i, _end);
                        }

                        EditorGUILayout.Space();
                        GUI.enabled = _target.actions[i].isEnabled;

                        if (Application.isPlaying)
                        {
                            _target.actions[i].AssignValues(_target.GetParameters());
                        }

                        _target.actions[i].ShowGUI(_target.GetParameters());
                    }
                    GUI.enabled = true;
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                CustomGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new Action"))
            {
                Undo.RecordObject(_target, "Create action");
                AddAction(ActionsManager.GetDefaultAction(), _target.actions.Count, _target);
            }

            UnityVersionHandler.CustomSetDirty(_target);
        }