Stratasys-450mc-VR/Assets/Scripts/Managers/CurrentStepManager.cs
2023-11-01 10:51:29 -04:00

82 lines
2.3 KiB
C#
Executable File

using SO;
using SO.Channels;
using UnityEngine;
namespace Managers
{
public class CurrentStepManager : MonoBehaviour
{
[SerializeField] private int currentStepIndex = 0;
[SerializeField] private MachineSO machine;
[SerializeField] private StepChangeChannelSO stepChangeChannel;
[SerializeField] private MachineChangeChannelSO machineChangeChannel;
[SerializeField] private SimpleChannelSO nextStepChannel;
[SerializeField] private SimpleChannelSO previousStepChannel;
private void OnEnable()
{
nextStepChannel.OnEventRaised += NextStep;
previousStepChannel.OnEventRaised += PreviousStep;
machineChangeChannel.OnMachineChange += OnMachineChanged;
}
private void OnDisable()
{
nextStepChannel.OnEventRaised -= NextStep;
previousStepChannel.OnEventRaised -= PreviousStep;
machineChangeChannel.OnMachineChange -= OnMachineChanged;
}
private void OnMachineChanged(MachineSO machine)
{
currentMachine = machine;
ResetCurrentStepIndex();
}
public MachineSO currentMachine
{
get => machine;
set => machine = value;
}
private StepSO currentStep
{
get => machine.Process.Steps[currentStepIndex];
}
private int CurrentStepIndex
{
get => currentStepIndex;
set
{
currentStepIndex = value;
OnCurrentStepChanged();
}
}
//this is just a reset of the current step index for when the machine changes
private void ResetCurrentStepIndex()
{
CurrentStepIndex = 0;
}
private void OnCurrentStepChanged()
{
stepChangeChannel.RaiseEvent(currentStep);
}
public void NextStep()
{
if (CurrentStepIndex >= machine.Process.Steps.Count - 1)return;
CurrentStepIndex++;
}
public void PreviousStep()
{
if (CurrentStepIndex - 1 < 0)return;
CurrentStepIndex--;
}
}
}