using SO; using SO.Channels; using TMPro; using UnityEngine; using UnityEngine.Serialization; public class MainScreenController : MonoBehaviour { [SerializeField] private StepChangeChannelSO stepChangeChannel; [SerializeField] private MachineChangeChannelSO machineChangeChannel; [SerializeField] private TextMeshProUGUI machineNameText; [SerializeField] private TextMeshProUGUI processNameText; [SerializeField] private TextMeshProUGUI stepNameText; [SerializeField] private TextMeshProUGUI stepDescriptionText; [SerializeField] private SimpleChannelSO documentChannel, videoChannel; [SerializeField] private GameObject documentPanel; [SerializeField] private GameObject videoPanel; [SerializeField] private GameObject documentButton; [SerializeField] private GameObject videoButton; [SerializeField] private bool focusPanel = true; [SerializeField] private bool disablePanelsOnStepChange = true; private void OnEnable() { stepChangeChannel.OnStepChanged += OnStepChanged; machineChangeChannel.OnMachineChange += OnMachineChanged; documentChannel.OnEventRaised += OnDocumentButtonClicked; videoChannel.OnEventRaised += OnVideoButtonClicked; } private void OnDisable() { stepChangeChannel.OnStepChanged -= OnStepChanged; machineChangeChannel.OnMachineChange -= OnMachineChanged; documentChannel.OnEventRaised -= OnDocumentButtonClicked; videoChannel.OnEventRaised -= OnVideoButtonClicked; } private void OnMachineChanged(MachineSO machine) { SetMachineName(machine); SetProcessName(machine); OnStepChanged(machine.Process.Steps[0]); } private void OnStepChanged(StepSO currentStep) { SetStepName(currentStep); SetStepDescription(currentStep); if (disablePanelsOnStepChange) { SetActive(videoPanel, false); SetActive(videoButton, true); SetActive(documentPanel, false); SetActive(documentButton, true); } } private void SetMachineName(MachineSO machine) { if (machineNameText == null) { Debug.LogError($"{nameof(machineNameText)} is null...", this.gameObject); return; } machineNameText.text = machine.MachineName; } private void SetProcessName(MachineSO machine) { if (processNameText == null) { Debug.LogError($"{nameof(processNameText)} is null...", this.gameObject); return; } processNameText.text = machine.Process.ProcessName; } private void SetStepName(StepSO currentStep) { if (stepNameText == null) { Debug.LogError($"{nameof(stepNameText)} is null...", this.gameObject); return; } stepNameText.text = currentStep.StepName; } private void SetStepDescription(StepSO currentStep) { if (stepDescriptionText == null) { Debug.LogError($"{nameof(stepDescriptionText)} is null...", this.gameObject); return; } stepDescriptionText.text = currentStep.Description; } private void SetActive(GameObject go, bool activeState) { if (go is null) { Debug.LogError($"{nameof(go)} is null...", this.gameObject); return; } go.SetActive(activeState); } public void OnVideoButtonClicked() { if (focusPanel) { SetActive(documentPanel, false); SetActive(documentButton, true); } SetActive(videoPanel, !videoPanel.activeSelf); SetActive(videoButton, !videoPanel.activeSelf); } public void OnDocumentButtonClicked() { if (focusPanel) { SetActive(videoPanel, false); SetActive(videoButton, true); } SetActive(documentPanel, !documentPanel.activeSelf); SetActive(documentButton, !documentPanel.activeSelf); } }