/// <summary> /// Ends the dialog. /// </summary> private void EndStory() { if (debug) { this.Log($"The story {story.name} has ended at the knot '{story.latestKnot}'"); } // Dispatch the ended event var storyEnded = new StratusStory.EndedEvent() { reader = this, story = this.story }; this.gameObject.Dispatch <StratusStory.EndedEvent>(storyEnded); StratusScene.Dispatch <StratusStory.EndedEvent>(storyEnded); onStoryEnded?.Invoke(story); // Save the story if (saveOnEnd) { Save(); } // We are no longer reading a story currentlyReading = false; // If we are queuing stories and there's one queueud up, let's start it if (queueStories && storyQueue.Count > 0) { QueueNextStory(); } }
public void Deactivate() { if (state == State.Inactive) { this.LogError($"{this} is already inactive"); } // Send the deactivation event DeactivateEvent e = new DeactivateEvent(this); StratusScene.Dispatch <DeactivateEvent>(e); // If the deactivation was succesful if (e.valid) { OnDeactivate(); this.Log("Deactivated"); state = State.Inactive; onDeactivate?.Invoke(); } else { this.LogError($"Failed to deactivate {this}"); } }
protected override void OnWindowAwake() { lines = new StratusCircularBuffer <string>(lineCapacity); stringBuilder = new StringBuilder(); StratusScene.Connect <AddLineEvent>(OnAddLineEvent); OnLogWindowAwake(); }
public void Initialize() { OnInitialize(); initialized = true; this.Log($"Initialized {this}"); StratusScene.Dispatch <SpawnEvent>(new SpawnEvent(this)); }
//------------------------------------------------------------------------------------------/ // Methods: Parsing //------------------------------------------------------------------------------------------/ /// <summary> /// Starts the current dialog. /// </summary> void StartStory(bool resume = false) { // If a knot has been selected... if (story.startingKnot.Length > 0) { this.JumpToKnot(story.startingKnot); } // Inform the space that dialog has started var startedEvent = new StratusStory.StartedEvent() { reader = this, story = story }; // Dispatch to this gameobject and the scene this.gameObject.Dispatch <StratusStory.StartedEvent>(startedEvent); StratusScene.Dispatch <StratusStory.StartedEvent>(startedEvent); onStoryStarted?.Invoke(story); currentlyReading = true; // Update the first line of dialog this.ContinueStory(!resume); story.started = true; if (debug) { StratusDebug.Log($"The story {story.name} has started at the knot '{latestKnot}'"); } }
/// <summary> /// Jumps the player character onto the segment's checkpoint /// </summary> /// <param name="segment"></param> /// <param name="checkpointIndex"></param> public void Jump(StratusSegmentBehaviour segment, int checkpointIndex = 0) { Vector3 position = segment.checkpoints[checkpointIndex].transform.position; switch (mechanism) { case JumpMechanism.Translate: var navigation = targetTransform.GetComponent <NavMeshAgent>(); if (navigation != null) { navigation.Warp(position); } else { targetTransform.position = position; } break; case JumpMechanism.Callback: onJump?.Invoke(segment, checkpointIndex); break; case JumpMechanism.Event: StratusScene.Dispatch <JumpToSegmentEvent>(new JumpToSegmentEvent(segment, checkpointIndex, position) { episode = this }); break; default: break; } }
protected override void OnAwake() { switch (storyEvent) { case StratusStory.ReaderEventType.Loaded: if (eventScope == StratusEvent.Scope.GameObject) { reader.gameObject.Connect <StratusStory.LoadedEvent>(this.OnStoryLoadedEvent); } else { StratusScene.Connect <StratusStory.LoadedEvent>(this.OnStoryLoadedEvent); } break; case StratusStory.ReaderEventType.Started: if (eventScope == StratusEvent.Scope.GameObject) { reader.gameObject.Connect <StratusStory.StartedEvent>(this.OnStoryStartedEvent); } else { StratusScene.Connect <StratusStory.StartedEvent>(this.OnStoryStartedEvent); } break; case StratusStory.ReaderEventType.Continue: if (eventScope == StratusEvent.Scope.GameObject) { reader.gameObject.Connect <StratusStory.ContinueEvent>(this.OnStoryContinueEvent); } else { StratusScene.Connect <StratusStory.ContinueEvent>(this.OnStoryContinueEvent); } break; case StratusStory.ReaderEventType.Ended: if (eventScope == StratusEvent.Scope.GameObject) { reader.gameObject.Connect <StratusStory.EndedEvent>(this.OnStoryEndedEvent); } else { StratusScene.Connect <StratusStory.EndedEvent>(this.OnStoryEndedEvent); } break; case StratusStory.ReaderEventType.SelectChoice: if (eventScope == StratusEvent.Scope.GameObject) { reader.gameObject.Connect <StratusStory.SelectChoiceEvent>(this.OnSelectChoiceEvent); } else { StratusScene.Connect <StratusStory.SelectChoiceEvent>(this.OnSelectChoiceEvent); } break; } }
public void Activate() { if (!initialized) { this.LogError("Cannot activate before being initialized"); } // If already active if (state == State.Active) { this.LogError($"{this} is already active"); } // Send the activation event ActivateEvent activation = new ActivateEvent(this); StratusScene.Dispatch <ActivateEvent>(activation); // If the activation was successful if (activation.valid) { OnActivate(); this.Log("Activated"); state = State.Active; onActivate?.Invoke(); } else { this.LogError($"Failed to activate {this}"); } }
public static IEnumerator TestStratusEvent() { // Create the object, add the component GameObject go = new GameObject("Test"); EventsSample eventSample = go.AddComponent <EventsSample>(); Assert.AreEqual(0, eventSample.sampleEventsReceived); yield return(null); // Construct the event EventsSample.SampleEvent e = new EventsSample.SampleEvent() { number = 5 }; // Dispatch to game object eventSample.gameObject.Dispatch <EventsSample.SampleEvent>(e); Assert.AreEqual(1, eventSample.sampleEventsReceived); Assert.AreEqual(5, eventSample.latestEvent.number); // Dispatch to scene e.number = 14; StratusScene.Dispatch <EventsSample.SampleEvent>(e); Assert.AreEqual(2, eventSample.sampleEventsReceived); Assert.AreEqual(14, eventSample.latestEvent.number); yield return(null); }
/// <summary> /// Ends this episode /// </summary> public void End() { current = null; StratusScene.Dispatch <EndEvent>(new EndEvent() { episode = this }); }
/// <summary> /// Starts this trigger. /// </summary> /// <param name="space"></param> public void Start(StratusCombatController caster, Type type, float duration) { var startedEvent = new StartedEvent(); // Make a copy of this trigger ?? startedEvent.Instance = new StratusCombatTrigger.Instance(Copy(this), caster, type, duration); StratusScene.Dispatch <StartedEvent>(startedEvent); }
//------------------------------------------------------------------------------------------/ // Messages //------------------------------------------------------------------------------------------/ /// <summary> /// Initializes the script /// </summary> private void Start() { StratusScene.Connect <StratusStory.StartedEvent>(this.OnStoryStartedEvent); StratusScene.Connect <StratusStory.EndedEvent>(this.OnStoryEndedEvent); StratusScene.Connect <StratusStory.UpdateLineEvent>(this.OnStoryUpdateEvent); StratusScene.Connect <StratusStory.PresentChoicesEvent>(this.OnStoryPresentChoicesEvent); OnStoryDisplayStart(); }
public bool Instantiate() { if (instanced) { return(false); } StratusScene.Dispatch <InstantiateEvent>(new InstantiateEvent(this)); return(true); }
public static void FadeAction(float speed, Action action, bool endOnAction = true) { StratusScene.Dispatch <FadeEvent>(new FadeEvent() { speed = speed, onStarted = action, endOnAction = endOnAction }); }
//------------------------------------------------------------------------/ // Messages //------------------------------------------------------------------------/ private void Awake() { this.Subscribe(); this.OnCombatSystemSubscribe(); this.OnCombatSystemInitialize(); // Announce that the combat system has finished initializing StratusScene.Dispatch <InitializedEvent>(new InitializedEvent()); }
//------------------------------------------------------------------------/ // Methods: Static //------------------------------------------------------------------------/ public static void FadeOut(float speed, float duration = 0f, Action onStarted = null, Action onEnded = null) { StratusScene.Dispatch <FadeEvent>(new FadeEvent() { speed = speed, duration = duration, onStarted = onStarted, onEnded = onEnded }); }
/// <summary> /// Called upon to continue the story /// </summary> public void ContinueStory() { var continueEvent = new StratusStory.ContinueEvent() { reader = this.reader, story = this.story }; reader.gameObject.Dispatch <StratusStory.ContinueEvent>(continueEvent); StratusScene.Dispatch <StratusStory.ContinueEvent>(continueEvent); }
//------------------------------------------------------------------------/ // Messages //------------------------------------------------------------------------/ protected override void OnWindowAwake() { transitions = new Queue <TransitionAction>(); HideLoadingScreen(); HideOptions(); StratusScene.Connect <FadeEvent>(this.OnCrossFadeEvent); StratusScene.Connect <LoadingScreenEvent>(this.OnLoadingScreenEvent); StratusScene.Connect <MenuOptionsEvent>(this.OnMenuOptionsEvent); }
private void SampleEventToScene() { // Construct the event object SampleEvent eventObj = new SampleEvent { number = 15 }; // Dispatch the event StratusScene.Dispatch <SampleEvent>(eventObj); }
protected override void OnInitializeSingletonState() { this.sceneLinks = StratusScene.GetComponentsInAllActiveScenes <SceneLinkerEvent>(); int numScenes = StratusScene.activeScenes.Length; this.sceneBoundaries = new Bounds[numScenes]; for (int i = 0; i < numScenes; ++i) { this.sceneBoundaries[i] = StratusScene.activeScenes[i].visibleBoundaries; } }
//------------------------------------------------------------------------/ // Messages //------------------------------------------------------------------------/ protected override void OnAwake() { if (eventType == StratusSegmentBehaviour.EventType.Enter) { StratusScene.Connect <StratusSegmentBehaviour.EnteredEvent>(this.OnSegmentEnteredEvent); } else if (eventType == StratusSegmentBehaviour.EventType.Exit) { StratusScene.Connect <StratusSegmentBehaviour.ExitedEvent>(this.OnSegmentExitedEvent); } }
/// <summary> /// Presents choices at the current story node /// </summary> void PresentChoices() { if (debug) { this.Log("Presenting dialog choices!"); } var choicesEvent = new StratusStory.PresentChoicesEvent(); choicesEvent.choices = story.runtime.currentChoices.ToArray(x => new StratusStoryChoice(x)); StratusScene.Dispatch <StratusStory.PresentChoicesEvent>(choicesEvent); }
protected override void OnTrigger() { switch (eventScope) { case StratusEvent.Scope.GameObject: target.gameObject.Dispatch <StratusStatefulObject.StateEvent>(new StratusStatefulObject.StateEvent(eventType, state)); break; case StratusEvent.Scope.Scene: StratusScene.Dispatch <StratusStatefulObject.StateEvent>(new StratusStatefulObject.StateEvent(eventType, state)); break; } }
//------------------------------------------------------------------------/ // Methods: Public //------------------------------------------------------------------------/ /// <summary> /// Begins this episode /// </summary> public void Begin() { current = this; if (debugDisplay) { StratusDebug.Log($"Beginning this episode at {initialSegment.label}", this); } Enter(currentSegment, true); StratusScene.Dispatch <BeginEvent>(new BeginEvent() { episode = this }); }
/// <summary> /// Exits this segment /// </summary> public void Exit() { StratusScene.Dispatch <ExitedEvent>(new ExitedEvent(this)); if (onExited != null) { onExited?.Invoke(); } Toggle(false); state = State.Exited; if (debug) { StratusDebug.Log($"Exiting", this); } }
protected override void OnTrigger() { switch (scope) { case Scope.Target: reader.gameObject.Dispatch <StratusStory.LoadEvent>(storyEvent); break; case Scope.Scene: StratusScene.Dispatch <StratusStory.LoadEvent>(storyEvent); break; default: break; } }
//------------------------------------------------------------------------------------------/ // Events //------------------------------------------------------------------------------------------/ /// <summary> /// Connect to common events /// </summary> void Subscribe() { this.gameObject.Connect <StratusStory.LoadEvent>(this.OnLoadEvent); if (listeningToScene) { StratusScene.Connect <StratusStory.LoadEvent>(this.OnLoadEvent); } this.gameObject.Connect <StratusStory.ContinueEvent>(this.OnContinueEvent); this.gameObject.Connect <StratusStory.SelectChoiceEvent>(this.OnSelectChoiceEvent); this.gameObject.Connect <StratusStory.RetrieveVariableValueEvent>(this.OnRetrieveVariableValueEvent); this.gameObject.Connect <StratusStory.SetVariableValueEvent>(this.OnSetVariableValueEvent); this.gameObject.Connect <StratusStory.ObserveVariableEvent>(this.OnObserveVariableEvent); this.gameObject.Connect <StratusStory.ObserveVariablesEvent>(this.OnObserveVariablesEvent); this.gameObject.Connect <StratusStory.RemoveVariableObserverEvent>(this.OnRemoveVariableObserverEvent); }
protected override void OnTrigger() { switch (eventScope) { case StratusEvent.Scope.GameObject: foreach (var target in targets) { if (target) { target.Dispatch(eventInstance, type.Type); } } break; case StratusEvent.Scope.Scene: StratusScene.Dispatch(eventInstance, type.Type); break; } }
/// <summary> /// Called upon when a particular choice has been selected /// </summary> /// <param name="choice"></param> public void SelectChoice(StratusStoryChoice choice) { if (logging) { StratusDebug.Log(choice.text + " was selected", this); } // Inform the current conversation of the choice var choiceEvent = new StratusStory.SelectChoiceEvent() { story = this.story, reader = this.reader }; choiceEvent.choice = choice; reader.gameObject.Dispatch <StratusStory.SelectChoiceEvent>(choiceEvent); StratusScene.Dispatch <StratusStory.SelectChoiceEvent>(choiceEvent); // Now do any extra stuff OnChoiceSelected(); }
protected override void OnTrigger() { switch (type) { case Type.Load: scene.Load(loadingMode); break; case Type.Reload: StratusScene.Reload(); break; case Type.Unload: scene.Unload(); break; default: break; } }