diff --git a/Scripts/StepSwitches/StepSwitch.cs b/Scripts/StepSwitches/StepSwitch.cs index 7b004b7..b75241f 100644 --- a/Scripts/StepSwitches/StepSwitch.cs +++ b/Scripts/StepSwitches/StepSwitch.cs @@ -47,7 +47,30 @@ namespace R0bbie.Timeline else attachedController.StepCompleted(); } + } + + + /// + /// When a child step is played using GoToStep, if that step was nested within multiple step groups and/or switches, this function may be called by a child step group to tell this switch that a step within it somewhere is active + /// + public void SetActiveOnGoToChild(Step _childStep) + { + // If group wasn't already active, we'll set it active now + if (!isActive) + { + isActive = true; + } + + // Set the active option + activeStepOption = _childStep; + // Then set any other parent step groups active too (all the way up the hierarchy, till we make it to the timeline, then till timeline to mark highest level group as active) + if (parentStepGroup) + parentStepGroup.SetActiveOnGoToChild(this); + if (parentStepSwitch) + parentStepSwitch.SetActiveOnGoToChild(this); + else + attachedStepTimeline.SetSpecifiedHighestStepActive(this); } diff --git a/Scripts/StepTimeline.cs b/Scripts/StepTimeline.cs index 10503b1..221ac63 100644 --- a/Scripts/StepTimeline.cs +++ b/Scripts/StepTimeline.cs @@ -244,12 +244,12 @@ namespace R0bbie.Timeline /// - /// Called via a child step group when a deeper child step group has been activated via GoToStep + /// Called via a child step group or switch when a deeper child step group has been activated via GoToStep /// - public void SetSpecifiedHighestStepGroupActive(StepGroup _group) + public void SetSpecifiedHighestStepActive(Step _step) { // Set the index in the timeline to that of new step's highest parent group - activeStepIndex = steps.IndexOf(_group); + activeStepIndex = steps.IndexOf(_step); SetActiveStep(activeStepIndex); } diff --git a/Scripts/Steps/StepGroup.cs b/Scripts/Steps/StepGroup.cs index eed99ae..e9fb3ad 100644 --- a/Scripts/Steps/StepGroup.cs +++ b/Scripts/Steps/StepGroup.cs @@ -170,7 +170,7 @@ namespace R0bbie.Timeline if (parentStepGroup) parentStepGroup.SetActiveOnGoToChild(this); else - attachedStepTimeline.SetSpecifiedHighestStepGroupActive(this); + attachedStepTimeline.SetSpecifiedHighestStepActive(this); // Set the index to the newly requested step activeChildStepIndex = childSteps.IndexOf(_step); @@ -184,7 +184,7 @@ namespace R0bbie.Timeline /// /// When a child step is played using GoToStep, if that step was nested within multiple step groups, this function may be called by a child step group to tell this step group that it's now active /// - private void SetActiveOnGoToChild(StepGroup _childStepGroup) + public void SetActiveOnGoToChild(StepGroup _childStepGroup) { // If group wasn't already active, we'll set it active now if (!isActive) @@ -200,8 +200,36 @@ namespace R0bbie.Timeline // Then set any other parent step groups active too (all the way up the hierarchy, till we make it to the timeline, then till timeline to mark highest level group as active) if (parentStepGroup) parentStepGroup.SetActiveOnGoToChild(this); + if (parentStepSwitch) + parentStepSwitch.SetActiveOnGoToChild(this); else - attachedStepTimeline.SetSpecifiedHighestStepGroupActive(this); + attachedStepTimeline.SetSpecifiedHighestStepActive(this); + } + + + /// + /// When a child step is played using GoToStep, allow for a child switch + /// + public void SetActiveOnGoToChild(StepSwitch _childStepSwitch) + { + // If group wasn't already active, we'll set it active now + if (!isActive) + { + isActive = true; + onGroupPlayEvent?.Invoke(); + } + + // Set the index and active step on this group + activeChildStepIndex = childSteps.IndexOf(_childStepSwitch); + activeChildStep = childSteps[activeChildStepIndex]; + + // Then set any other parent step groups active too (all the way up the hierarchy, till we make it to the timeline, then till timeline to mark highest level group as active) + if (parentStepGroup) + parentStepGroup.SetActiveOnGoToChild(this); + if (parentStepSwitch) + parentStepSwitch.SetActiveOnGoToChild(this); + else + attachedStepTimeline.SetSpecifiedHighestStepActive(this); }