public void RunExampleOne() { // Get the ActionList component ActionList actionList = CreateActionList(); // Make sure we're in gameplay and that no Actions are already running if (actionList.AreActionsRunning() || !Application.isPlaying) { Debug.LogWarning("Cannot run Actions at this time", this); return; } // Declare the Actions within it actionList.actions = new List <Action> { // Show a Console message ActionComment.CreateNew("Running Example 1 - move the player, say something, and add an inventory item"), // Move the Player to the Marker (note: uses pathfinding, so a NavMesh will need to be set up) ActionCharPathFind.CreateNew(KickStarter.player, markerToMoveTo), // Have the Player say something (Note: The 'translation ID' parameter is optional) ActionSpeech.CreateNew(KickStarter.player, playerSpeechText, playerSpeechTranslationID), // Add an item to the Player's inventory ActionInventorySet.CreateNew_Add(inventoryItemIDToAdd), // Show another Console message ActionComment.CreateNew("Example complete!"), }; // Run it actionList.Interact(); }
void SwitchToNone() { ShowNone.Interact(); GreenDoors.SetActive(false); PurpleDoors.SetActive(false); YellowDoors.SetActive(false); }
void SwitchToPurple() { ShowPurple.Interact(); GreenDoors.SetActive(false); PurpleDoors.SetActive(true); YellowDoors.SetActive(false); }
public void Resume() { if (actionListAsset != null) { // Destroy old list, but don't go through ActionListManager's Reset code, to bypass changing GameState etc KickStarter.actionListManager.DestroyAssetList(actionListAsset); actionList = AdvGame.RunActionListAsset(actionListAsset, startIndex, true); } else if (actionList != null) { actionList.Interact(startIndex, true); } }
/** * <summary>Resumes a previously-paused ActionList. If the ActionList is already running, nothing will happen.</summary> * <param name = "actionList">The ActionList to pause</param> * <param name = "rerunPausedActions">If True, then any Actions that were midway-through running when the ActionList was paused will be restarted. Otherwise, the Actions that follow them will be reun instead.</param> */ public void Resume(ActionList actionList, bool rerunPausedActions) { if (IsListRunning(actionList)) { return; } for (int i = 0; i < activeLists.Count; i++) { if (activeLists[i].IsFor(actionList)) { activeLists[i].Resume(null, rerunPausedActions); return; } } actionList.Interact(); }
/** * <summary>Resumes a previously-paused ActionList. If the ActionList is already running, nothing will happen.</summary> * <param name = "actionList">The ActionList to pause</param> */ public void Resume(ActionList actionList) { if (IsListRunning(actionList)) { return; } for (int i = 0; i < activeLists.Count; i++) { if (activeLists[i].IsFor(actionList)) { activeLists[i].Resume(); return; } } actionList.Interact(); }
/** * <summary>Attempts to resume a Conversation, if the associated ActionList overrides it's handling.</summary> * <returns>True if the ActionList was overriding a Conversation</returns> */ public bool ResumeConversationOverride() { if (isConversationOverride) { isConversationOverride = false; if (actionListAsset != null) { actionList = AdvGame.RunActionListAsset(actionListAsset, startIndex, true); } else if (actionList != null) { actionList.Interact(startIndex, true); } return(true); } return(false); }
private void RunExampleTwo() { // Get the ActionList component ActionList actionList = CreateActionList(); // Make sure we're in gameplay and that no Actions are already running if (actionList.AreActionsRunning() || !Application.isPlaying) { Debug.LogWarning("Cannot run Actions at this time", this); return; } // Create the Actions, but this time with references to them so that we can later modify their 'After running' options // Check if a global bool variable is True or False ActionVarCheck variableCheck = ActionVarCheck.CreateNew_Global(globalBoolVariableID); // Response if the variable is True ActionComment commentIfTrue = ActionComment.CreateNew("The bool variable is currently True!"); // Response if the variable is False ActionComment commentIfFalse = ActionComment.CreateNew("The bool variable is currently False!"); // Assign the Actions to the ActionList actionList.actions = new List <Action> { variableCheck, commentIfTrue, commentIfFalse, }; // Modify the 'Variable: Check' Action's 'After running' fields so that commentIfTrue is run if the condition is met, and commentIfFalse is run otherwise variableCheck.SetOutputs(new ActionEnd(commentIfTrue), new ActionEnd(commentIfFalse)); // Modify the two comment Actions so that their 'After running' fields are both set to Stop, so that the ActionList stops after either one is run commentIfTrue.SetOutput(new ActionEnd(true)); commentIfFalse.SetOutput(new ActionEnd(true)); // Run the ActionList actionList.Interact(); }
protected void DrawSharedElements(ActionList _target) { if (PrefabUtility.GetPrefabType(_target) == PrefabType.Prefab) { EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info); return; } int numActions = 0; if (_target.source != ActionListSource.AssetFile) { numActions = _target.actions.Count; if (numActions < 1) { numActions = 1; AC.Action newAction = ActionList.GetDefaultAction(); _target.actions.Add(newAction); } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); if (_target.source == ActionListSource.AssetFile) { GUI.enabled = false; } 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; } } GUI.enabled = true; if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { if (_target.source == ActionListSource.AssetFile) { if (_target.assetFile != null) { ActionListEditorWindow.Init(_target.assetFile); } } else { ActionListEditorWindow.Init(_target); } } if (!Application.isPlaying) { GUI.enabled = false; } if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { _target.Interact(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (_target.source == ActionListSource.AssetFile) { return; } ActionListEditor.ResetList(_target); if (actionsManager == null) { EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning); OnEnable(); return; } if (!actionsManager.displayActionsInInspector) { EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info); return; } for (int i = 0; i < _target.actions.Count; i++) { if (_target.actions[i] == null) { ACDebug.LogWarning("An empty Action was found, and was deleted"); _target.actions.RemoveAt(i); continue; } EditorGUILayout.BeginVertical("Button"); EditorGUILayout.BeginHorizontal(); int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]); string actionLabel = " (" + (i).ToString() + ") " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel(); _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f)); } if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f))) { ActionSideMenu(i); } _target.actions[i].isAssetFile = false; EditorGUILayout.EndHorizontal(); if (_target.actions[i].isBreakPoint) { EditorGUILayout.HelpBox("Break point", MessageType.None); } if (_target.actions[i].isDisplayed) { GUI.enabled = _target.actions[i].isEnabled; if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString())) { EditorGUILayout.HelpBox("This Action type has been disabled 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"); _target.actions[i] = ActionListEditor.RebuildAction(_target.actions[i], newTypeIndex, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene); } if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0) { _target.actions[i].ShowGUI(_target.parameters); } else { _target.actions[i].ShowGUI(null); } } } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } GUI.enabled = true; EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new action")) { Undo.RecordObject(_target, "Create action"); numActions += 1; } _target.actions = ActionListEditor.ResizeList(_target.actions, numActions); }
override public float Run() { if (!isRunning) { Upgrade(); isRunning = true; runtimeActionList = null; if (listSource == ListSource.InScene && 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.parameters, true); } else { SendParameters(actionList.parameters, false); } } else if (actionList.source == ActionListSource.InScene && actionList.useParameters) { SendParameters(actionList.parameters, false); } if (runFromStart) { actionList.Interact(0, !isSkippable); } else { actionList.Interact(GetSkipIndex(actionList.actions), !isSkippable); } } else if (listSource == ListSource.AssetFile && invActionList != null && !invActionList.actions.Contains(this)) { if (!invActionList.canRunMultipleInstances) { KickStarter.actionListAssetManager.EndAssetList(invActionList); } if (invActionList.useParameters) { SendParameters(invActionList.parameters, true); } if (runFromStart) { runtimeActionList = AdvGame.RunActionListAsset(invActionList, 0, !isSkippable); } else { runtimeActionList = AdvGame.RunActionListAsset(invActionList, GetSkipIndex(invActionList.actions), !isSkippable); } } if (!runInParallel || (runInParallel && willWait)) { return(defaultPauseTime); } } else { if (listSource == ListSource.InScene && actionList != null) { if (KickStarter.actionListManager.IsListRunning(actionList)) { return(defaultPauseTime); } else { isRunning = false; } } else if (listSource == ListSource.AssetFile && invActionList != null) { if (invActionList.canRunMultipleInstances) { if (runtimeActionList != null && KickStarter.actionListManager.IsListRunning(runtimeActionList)) { return(defaultPauseTime); } isRunning = false; } else { if (KickStarter.actionListAssetManager.IsListRunning(invActionList)) { return(defaultPauseTime); } isRunning = false; } } } return(0f); }
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); }
protected void DrawSharedElements(ActionList _target) { if (IsActionListPrefab(_target)) { //EditorGUILayout.HelpBox ("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info); //return; } int numActions = 0; if (_target.source != ActionListSource.AssetFile) { numActions = _target.actions.Count; if (numActions < 1) { numActions = 1; AddAction(ActionsManager.GetDefaultAction(), -1, _target); } } EditorGUILayout.Space(); if (_target.source == ActionListSource.InScene) { ActionListEditor.ResetList(_target); } actionsManager = AdvGame.GetReferences().actionsManager; if (actionsManager == null) { EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning); OnEnable(); return; } if (!actionsManager.displayActionsInInspector || _target.source == ActionListSource.AssetFile) { if (Application.isPlaying) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Edit Actions", GUILayout.Height(40f))) { ActionListEditorWindow.OpenForActionList(_target); } bool isRunning = false; if (Application.isPlaying) { if (KickStarter.actionListManager != null) { isRunning = KickStarter.actionListManager.IsListRunning(_target); } } if (isRunning) { if (GUILayout.Button("Stop", GUILayout.Height(40f))) { _target.Kill(); } } else { if (GUILayout.Button("Run now", GUILayout.Height(40f))) { _target.Interact(); } } EditorGUILayout.EndHorizontal(); } else { if (GUILayout.Button("Edit Actions", GUILayout.Height(40f))) { ActionListEditorWindow.OpenForActionList(_target); } } return; } else { EditorGUILayout.BeginHorizontal(); GUI.enabled = (_target.source == ActionListSource.InScene); 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; } } GUI.enabled = true; if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid)) { ActionListEditorWindow.OpenForActionList(_target); } GUI.enabled = Application.isPlaying; if (GUILayout.Button("Run now", EditorStyles.miniButtonRight)) { _target.Interact(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } for (int i = 0; i < _target.actions.Count; i++) { if (_target.actions[i] == null) { ACDebug.LogWarning("An empty Action was found, and was deleted", _target); _target.actions.RemoveAt(i); numActions--; continue; } _target.actions[i].AssignParentList(_target); CustomGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]); string actionLabel = " (" + i.ToString() + ") " + 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) + "..)"; } _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel); if (!_target.actions[i].isEnabled) { EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f)); } if (GUILayout.Button("", CustomStyles.IconCog)) { ActionSideMenu(i); } _target.actions[i].isAssetFile = false; EditorGUILayout.EndHorizontal(); if (_target.actions[i].isBreakPoint) { EditorGUILayout.HelpBox("Break point", MessageType.None); } if (_target.actions[i].isDisplayed) { GUI.enabled = _target.actions[i].isEnabled; 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"); _target.actions[i] = RebuildAction(_target.actions[i], newTypeIndex, _target, -1, _end); } if (_target.NumParameters > 0) { _target.actions[i].ShowGUI(_target.parameters); } else { _target.actions[i].ShowGUI(null); } } } if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel) { _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed); } GUI.enabled = true; CustomGUILayout.EndVertical(); EditorGUILayout.Space(); } if (GUILayout.Button("Add new action")) { Undo.RecordObject(_target, "Create action"); numActions += 1; } _target = ActionListEditor.ResizeList(_target, numActions); }
private void RunActionLists() { switch (actionListSource) { case ActionListSource.InScene: if (actionList != null) { if (setParameters) { AssignParameterValues(actionList); } if (actionList.IsSkippable() && runInstantly) { actionList.Skip(); } else { actionList.Interact(); } } break; case ActionListSource.AssetFile: if (actionListAsset != null) { if (setParameters && runMultipleTimes) { if (actionListAsset.canRunMultipleInstances) { for (int i = 0; i < successiveGUIData.Length + 1; i++) { AssignParameterValues(actionListAsset, i); if (actionListAsset.IsSkippable() && runInstantly) { AdvGame.SkipActionListAsset(actionListAsset); } else { actionListAsset.Interact(); } } } else { ACDebug.LogWarning("Cannot set run multiple parameter configurations because the ActionList asset '" + actionListAsset + "' has 'Can run multiple instances?' unchecked.", actionListAsset); } return; } if (setParameters) { AssignParameterValues(actionListAsset); } if (actionListAsset.IsSkippable() && runInstantly) { AdvGame.SkipActionListAsset(actionListAsset); } else { actionListAsset.Interact(); } } break; } }
public void Start() { bridge = DialogueManager.Instance.GetComponent<AdventureCreatorBridge>(); actionListManager = KickStarter.actionListManager; string actionListSpecifier = GetParameter(0); bool wait = !string.Equals(GetParameter(1), "nowait"); int startAt = GetParameterAsInt(2); bool addToSkipQueue = true; // Look for a GameObject in the scene matching the specified name: GameObject actionListObject = GameObject.Find(actionListSpecifier); if (actionListObject != null) { actionList = actionListObject.GetComponent<ActionList>(); if (actionList != null) { if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AC({1},{2},startAt={3}) starting action list", DialogueDebug.Prefix, actionListSpecifier, (wait ? "wait" : "nowait"), startAt), actionListObject); if (bridge != null && DialogueManager.IsConversationActive) bridge.SyncLuaToAdventureCreator(); if (startAt == 0) { actionList.Interact(); } else { actionList.Interact(startAt, addToSkipQueue); } } } // Failing that, look for other GameObjects in the scene matching the name: if (actionList == null) { foreach (GameObject go in GameObject.FindObjectsOfType<GameObject>()) { if (string.Equals(go.name, actionListSpecifier)) { actionList = go.GetComponent<ActionList>(); if (actionList != null) { if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AC({1},{2},startAt={3}) starting action list", DialogueDebug.Prefix, actionListSpecifier, (wait ? "wait" : "nowait"), startAt), go); if (bridge != null && DialogueManager.IsConversationActive) bridge.SyncLuaToAdventureCreator(); if (startAt == 0) { actionList.Interact(); } else { actionList.Interact(startAt, addToSkipQueue); } break; } } } } // Failing that, try Resources.Load: if (actionList == null) { var actionListAsset = Resources.Load(actionListSpecifier) as ActionListAsset; if (actionListAsset) { if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AC({1},{2},startAt={3}) starting action list asset", DialogueDebug.Prefix, actionListSpecifier, (wait ? "wait" : "nowait"), startAt)); if (bridge != null && DialogueManager.IsConversationActive) bridge.SyncLuaToAdventureCreator(); if (startAt == 0) { actionList = AdvGame.RunActionListAsset(actionListAsset); } else { actionList = AdvGame.RunActionListAsset(actionListAsset, startAt, addToSkipQueue); } } } // Failing that, look for an ActionListAsset in all resources of the project: if (actionList == null) { foreach (ActionListAsset actionListAsset in Resources.FindObjectsOfTypeAll(typeof(ActionListAsset)) as ActionListAsset[]) { if (string.Equals(actionListSpecifier, actionListAsset.name, System.StringComparison.OrdinalIgnoreCase)) { if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AC({1},{2},startAt={3}) starting action list asset", DialogueDebug.Prefix, actionListSpecifier, (wait ? "wait" : "nowait"), startAt)); if (bridge != null && DialogueManager.IsConversationActive) bridge.SyncLuaToAdventureCreator(); if (startAt == 0) { actionList = AdvGame.RunActionListAsset(actionListAsset); } else { actionList = AdvGame.RunActionListAsset(actionListAsset, startAt, addToSkipQueue); } break; } } } if (actionList == null) { if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AC(): Can't find action list '{1}'", DialogueDebug.Prefix, actionListSpecifier)); Stop(); } if (!wait) Stop(); }