mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-23 07:38:33 -05:00
85 lines
2.5 KiB
C#
Executable File
85 lines
2.5 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;
|
|
[SerializeField] private SimpleChannelSO resetStepChannel;
|
|
|
|
private void OnEnable()
|
|
{
|
|
nextStepChannel.OnEventRaised += NextStep;
|
|
previousStepChannel.OnEventRaised += PreviousStep;
|
|
machineChangeChannel.OnMachineChange += OnMachineChanged;
|
|
resetStepChannel.OnEventRaised += ResetCurrentStepIndex;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
nextStepChannel.OnEventRaised -= NextStep;
|
|
previousStepChannel.OnEventRaised -= PreviousStep;
|
|
machineChangeChannel.OnMachineChange -= OnMachineChanged;
|
|
resetStepChannel.OnEventRaised -= ResetCurrentStepIndex;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
private void ResetCurrentStepIndex()
|
|
{
|
|
CurrentStepIndex = 0;
|
|
OnCurrentStepChanged();
|
|
}
|
|
|
|
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--;
|
|
}
|
|
}
|
|
}
|