Exemplo n.º 1
0
        public static void ShowPropertiesGUI(ActionListAsset _target)
        {
            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Asset properties", EditorStyles.boldLabel);
            _target.actionListType = (ActionListType)EditorGUILayout.EnumPopup("When running:", _target.actionListType);
            if (_target.actionListType == ActionListType.PauseGameplay)
            {
                _target.isSkippable        = EditorGUILayout.Toggle("Is skippable?", _target.isSkippable);
                _target.unfreezePauseMenus = EditorGUILayout.Toggle("Unfreeze 'pause' Menus?", _target.unfreezePauseMenus);
            }
            _target.canRunMultipleInstances = EditorGUILayout.Toggle("Can run multiple instances?", _target.canRunMultipleInstances);
            if (!_target.IsSkippable())
            {
                _target.canSurviveSceneChanges = EditorGUILayout.Toggle("Can survive scene changes?", _target.canSurviveSceneChanges);
            }
            _target.useParameters = EditorGUILayout.Toggle("Use parameters?", _target.useParameters);
            if (_target.useParameters)
            {
                _target.revertToDefaultParametersAfterRunning = EditorGUILayout.ToggleLeft("Revert to default parameter values after running?", _target.revertToDefaultParametersAfterRunning);
            }

            EditorGUILayout.EndVertical();

            if (_target.useParameters)
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.LabelField("Parameters", EditorStyles.boldLabel);
                ActionListEditor.ShowParametersGUI(null, _target, _target.GetParameters());
                EditorGUILayout.EndVertical();
            }

            _target.tagID = ActionListEditor.ShowTagUI(_target.actions.ToArray(), _target.tagID);
        }
Exemplo n.º 2
0
 /**
  * <summary>Updates an ActionList asset's parameter values with its own</summary>
  * <param name = "_actionListAsset">The ActionList asset to update</param>
  */
 protected void AssignParameterValues(ActionListAsset _actionListAsset, int runIndex = 0)
 {
     if (_actionListAsset != null && _actionListAsset.NumParameters > 0)
     {
         BulkAssignParameterValues(_actionListAsset.GetParameters(), GetFromParameters(runIndex), false, true);
     }
 }
Exemplo n.º 3
0
        /**
         * <summary>Downloads and runs the settings and Actions stored within an ActionListAsset.</summary>
         * <param name = "actionListAsset">The ActionListAsset to copy Actions from and run</param>
         * <param name = "endConversation">If set, the supplied Conversation will be run when the AcionList ends</param>
         * <param name = "i">The index number of the first Action to run</param>
         * <param name = "doSkip">If True, then the Actions will be skipped, instead of run normally</param>
         * <param name = "addToSkipQueue">If True, the ActionList will be skippable when the user presses 'EndCutscene'</param>
         * <param name = "dontRun">If True, the Actions will not be run once transferred from the ActionListAsset</param>
         */
        public void DownloadActions(ActionListAsset actionListAsset, Conversation endConversation, int i, bool doSkip, bool addToSkipQueue, bool dontRun = false)
        {
            assetSource   = actionListAsset;
            useParameters = actionListAsset.useParameters;

            parameters = new List <ActionParameter>();

            List <ActionParameter> assetParameters = actionListAsset.GetParameters();

            if (assetParameters != null)
            {
                foreach (ActionParameter assetParameter in assetParameters)
                {
                    parameters.Add(new ActionParameter(assetParameter, true));
                }
            }

            unfreezePauseMenus = actionListAsset.unfreezePauseMenus;

            actionListType = actionListAsset.actionListType;
            if (actionListAsset.actionListType == ActionListType.PauseGameplay)
            {
                isSkippable = actionListAsset.isSkippable;
            }
            else
            {
                isSkippable = false;
            }

            conversation = endConversation;
            actions.Clear();

            foreach (AC.Action action in actionListAsset.actions)
            {
                if (action != null)
                {
                    ActionEnd _lastResult = action.lastResult;

                    // Really we should re-instantiate all Actions, but this is 'safer'
                    Action newAction = (actionListAsset.canRunMultipleInstances)
                                                                                ? (Object.Instantiate(action) as Action)
                                                                                : action;

                    if (doSkip)
                    {
                        newAction.lastResult = _lastResult;
                    }

                    actions.Add(newAction);
                }
                else
                {
                    actions.Add(null);
                }
            }

            /*if (!useParameters)
             * {
             *      foreach (Action action in actions)
             *      {
             *              action.AssignValues (null);
             *      }
             * }*/

            actionListAsset.AfterDownloading();


            if (!dontRun)
            {
                if (doSkip)
                {
                    Skip(i);
                }
                else
                {
                    Interact(i, addToSkipQueue);
                }
            }

            if (actionListAsset.canSurviveSceneChanges && !actionListAsset.IsSkippable())
            {
                DontDestroyOnLoad(gameObject);
            }
        }
Exemplo n.º 4
0
        public override float Run()
        {
            if (!isRunning)
            {
                Upgrade();

                isRunning         = true;
                runtimeActionList = null;

                switch (listSource)
                {
                case ListSource.InScene:
                    if (actionList != null && !actionList.actions.Contains(this))
                    {
                        KickStarter.actionListManager.EndList(actionList);

                        if (actionList.source == ActionListSource.AssetFile && actionList.assetFile != null && actionList.assetFile.useParameters)
                        {
                            if (actionList.syncParamValues)
                            {
                                SendParameters(actionList.assetFile.GetParameters(), true);
                            }
                            else
                            {
                                SendParameters(actionList.parameters, false);
                            }
                            if (runMode == RunMode.SetParametersOnly)
                            {
                                isRunning = false;
                                return(0f);
                            }
                        }
                        else if (actionList.source == ActionListSource.InScene && actionList.useParameters)
                        {
                            SendParameters(actionList.parameters, false);
                            if (runMode == RunMode.SetParametersOnly)
                            {
                                isRunning = false;
                                return(0f);
                            }
                        }

                        if (runFromStart)
                        {
                            actionList.Interact(0, !isSkippable);
                        }
                        else
                        {
                            actionList.Interact(GetSkipIndex(actionList.actions), !isSkippable);
                        }
                    }
                    else
                    {
                        LogWarning("Could not find ActionList to run.");
                        isRunning = false;
                        return(0f);
                    }
                    break;

                case ListSource.AssetFile:
                    if (invActionList != null && !invActionList.actions.Contains(this))
                    {
                        if (invActionList.useParameters)
                        {
                            SendParameters(invActionList.GetParameters(), true);
                            if (runMode == RunMode.SetParametersOnly)
                            {
                                isRunning = false;
                                return(0f);
                            }
                        }

                        if (!invActionList.canRunMultipleInstances)
                        {
                            KickStarter.actionListAssetManager.EndAssetList(invActionList);
                        }

                        if (runFromStart)
                        {
                            runtimeActionList = AdvGame.RunActionListAsset(invActionList, 0, !isSkippable);
                        }
                        else
                        {
                            runtimeActionList = AdvGame.RunActionListAsset(invActionList, GetSkipIndex(invActionList.actions), !isSkippable);
                        }
                    }
                    else
                    {
                        LogWarning("Could not find ActionList asset to run");
                        isRunning = false;
                        return(0f);
                    }
                    break;

                default:
                    break;
                }

                if (!runInParallel || (runInParallel && willWait))
                {
                    return(defaultPauseTime);
                }
            }
            else
            {
                switch (listSource)
                {
                case ListSource.InScene:
                    if (actionList)
                    {
                        if (KickStarter.actionListManager.IsListRunning(actionList))
                        {
                            return(defaultPauseTime);
                        }
                        else
                        {
                            isRunning = false;
                        }
                    }
                    break;

                case ListSource.AssetFile:
                    if (invActionList)
                    {
                        if (invActionList.canRunMultipleInstances)
                        {
                            if (runtimeActionList != null && KickStarter.actionListManager.IsListRunning(runtimeActionList))
                            {
                                return(defaultPauseTime);
                            }
                            isRunning = false;
                        }
                        else
                        {
                            if (KickStarter.actionListAssetManager.IsListRunning(invActionList))
                            {
                                return(defaultPauseTime);
                            }
                            isRunning = false;
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            return(0f);
        }
Exemplo n.º 5
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;
                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;

                EditorGUILayout.BeginVertical("Button");

                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);
                }

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

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

            UnityVersionHandler.CustomSetDirty(_target);
        }