/// Initialise the StepGroup, setting up required external refs, and getting refs to all child steps
/// </summary>
publicoverridevoidInit(StepTimeline_stepTimeline)
{
// Setup necessary refs to parent timeline, and child steps (only 1 level deep to avoid getting children of StepSwitches etc)
attachedStepTimeline=_stepTimeline;
foreach(Transformtintransform)
{
if(t.GetComponent<Step>())
{
childSteps.Add(t.GetComponent<Step>());
}
}
// Init all child steps
foreach(varstepinchildSteps)
{
step.Init(attachedStepTimeline,this);
}
init=true;
}
/// <summary>
/// Initialise the StepGroup if StepController initialising
/// </summary>
publicoverridevoidInit(StepController_controller)
{
// Setup necessary refs to parent Controller, and child steps (only 1 level deep to avoid getting children of StepSwitches etc)
attachedController=_controller;
foreach(Transformtintransform)
{
if(t.GetComponent<Step>())
{
childSteps.Add(t.GetComponent<Step>());
}
}
// Init all child steps
foreach(varstepinchildSteps)
{
step.Init(attachedController,this);
}
init=true;
}
/// <summary>
/// Play this StepGroup. Starting with the first step in it.
/// </summary>
publicoverridevoidPlay()
{
// Set the index to start at the first step
activeChildStepIndex=0;
Debug.Log(name+" - Started");
wasCompleted=false;
isActive=true;
onGroupPlayEvent?.Invoke();
activeChildStep=childSteps[activeChildStepIndex];
activeChildStep.Play();
}
/// <summary>
/// Continue and play the next step in the group, unless we're at the end of the group
/// </summary>
publicoverridevoidContinue()
{
activeChildStepIndex++;
// Check we've not reached the end of the step group, before playing the next step (if there is one)
if(activeChildStepIndex>=childSteps.Count)
{
GroupCompleted();
}
else
{
activeChildStep=childSteps[activeChildStepIndex];
if(activeChildStepisStepSwitch)
activeChildStepIsSwitch=true;
activeChildStep.Play();
}
}
/// <summary>
/// Skip this entire step group
/// </summary>
publicoverridevoidSkip()
{
wasSkipped=true;
isActive=false;
// TODO: Check if currently active child step needs tidied up before skipping?
// TODO: Mark all steps within the step group not played before Skip was called as skipped also?
if(parentStepGroup)
{
parentStepGroup.Continue();
}
elseif(parentStepSwitch)
{
parentStepSwitch.Continue();
}
else
{
if(attachedStepTimeline!=null)
attachedStepTimeline.PlayNextStep();
else
attachedController.StepCompleted();
}
}
/// <summary>
/// Play a specific step which may not be the "next" one (may mean replaying an already played step or jumping to a future one), and update activeStepIndex to the desired one
/// </summary>
/// <param name="_step">Reference to the Step the timeline should now play, as part of the group</param>
publicvoidGoToStepAndPlay(Step_step)
{
// If group wasn't already active, we'll set it active now
if(!isActive)
{
isActive=true;
onGroupPlayEvent?.Invoke();
}
// If requested step has parent step groups above this one, make sure their status is set to active. Otherwise we're at the highest group in the hierarchy, so make sure this is active in the 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
// 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)
// 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)