using UnityEngine; using TriInspector; namespace R0bbie.Timeline { /// /// Allow the selection of the next step based on a player action /// public abstract class StepSwitch : Step { protected enum Mode { Inactive, WaitingForEvent, PlayingChildStep } protected Mode activeMode; protected Step activeStepOption; /// /// Tell timeline to continue once step option associated with this Switch has completed /// public override void Continue() { Debug.Log(name + " - Completed"); isActive = false; activeMode = Mode.Inactive; wasCompleted = true; // Tell the timeline to play the next step (or step group, or controller) if (parentStepGroup) { parentStepGroup.Continue(); } else if (parentStepSwitch) { parentStepSwitch.Continue(); } else { if (attachedStepTimeline != null) attachedStepTimeline.PlayNextStep(); else attachedController.StepCompleted(); } } #if UNITY_EDITOR // ODIN INSPECTOR BUTTONS [Title("Add Option to Switch")] [Button("Add Step")] private void Editor_AddStepOption() { // Create new GameObject, and reparent it as a child of the StepSwitch parent object GameObject stepGo = new GameObject(); stepGo.transform.parent = transform; // Add Step component to this new GameObject Step step = stepGo.AddComponent(); // Rename object int parentStepNo = transform.GetSiblingIndex() + 1; int childStepNo = step.transform.GetSiblingIndex() + 1; step.gameObject.name = "#" + parentStepNo.ToString("00") + "." + childStepNo.ToString("00") + " - Switch Option - *ADD STEP NAME*"; } [Button("Add GoTo Step")] private void Editor_AddGoToStepOption() { // Create new GameObject, and reparent it as a child of the StepSwitch parent object GameObject stepGo = new GameObject(); stepGo.transform.parent = transform; // Add GoToStep component to this new GameObject GoToStep step = stepGo.AddComponent(); // Rename object int parentStepNo = transform.GetSiblingIndex() + 1; int childStepNo = step.transform.GetSiblingIndex() + 1; step.gameObject.name = "#" + parentStepNo.ToString("00") + "." + childStepNo.ToString("00") + " - GOTO - Switch Option - *ADD STEP NAME*"; } [Title("Editor Functions")] [Button("Rename Child Steps")] private void Editor_RenameChildren() { RenameChildren(); } // OTHER EDITOR HELPER FUNCTIONS public void RenameChildren() { foreach (Transform child in transform) { if (child.GetComponent()) child.GetComponent().UpdateStepName(); } } #endif } }