using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; public class ProgramInfoView : MonoBehaviour { // --- ÇÁ·Î±×·¥ Á¤º¸ ÆÐ³Î --- [SerializeField] private Transform leftControllerTransform; [SerializeField] private GameObject infoPanel; public InputActionReference showInfoPanel; public InputActionReference hideInfoPanel; public InputActionReference[] playProgram; private bool isPressingX = false; private bool isPressingAorB = false; [SerializeField] public TextMeshProUGUI jobName; [SerializeField] public TextMeshProUGUI jobSpeed; [SerializeField] private GameObject orderPrefab; [SerializeField] private GameObject endPrefab; [SerializeField] private Transform contentParent; [SerializeField] private Button resetBtn; [SerializeField] private Button startBtn; [SerializeField] private Button stopBtn; [SerializeField] private Button minusBtn; [SerializeField] private Button plusBtn; private List instantiatedStepItems = new List(); public event Action OnResetClicked; public event Action OnStartClicked; public event Action OnStopClicked; public event Action OnMinusClicked; public event Action OnPlusClicked; void Start() { infoPanel.SetActive(false); if (showInfoPanel != null) { showInfoPanel.action.Enable(); showInfoPanel.action.performed += ShowProgramInfoPanel; } if (hideInfoPanel != null) { hideInfoPanel.action.Enable(); hideInfoPanel.action.performed += HideProgramInfoPanel; } if (playProgram != null) { for (int i = 0; i < playProgram.Length; i++) { playProgram[i].action.Enable(); playProgram[i].action.performed += PlayProgram; } } resetBtn.onClick.AddListener(() => OnResetClicked?.Invoke()); startBtn.onClick.AddListener(() => OnStartClicked?.Invoke()); stopBtn.onClick.AddListener(() => OnStopClicked?.Invoke()); minusBtn.onClick.AddListener(() => OnMinusClicked?.Invoke(-1)); plusBtn.onClick.AddListener(() => OnPlusClicked?.Invoke(1)); } private void OnDestroy() { if (showInfoPanel != null) { showInfoPanel.action.performed -= ShowProgramInfoPanel; } if (hideInfoPanel != null) { hideInfoPanel.action.performed -= HideProgramInfoPanel; } if (playProgram != null) { for (int i = 0; i < playProgram.Length; i++) { playProgram[i].action.performed -= PlayProgram; } } } public void UpdateProgramInfo(RobotProgram program, List steps) { if (program == null) return; foreach (Transform child in contentParent) { Destroy(child.gameObject); } instantiatedStepItems.Clear(); // »õ ½ºÅÜ ¸ñ·Ï »ý¼º if (steps == null) return; foreach (RobotMoveStep step in steps) { GameObject newPrefab = Instantiate(orderPrefab, contentParent); StepInfoItem stepItemUI = newPrefab.GetComponent(); if (stepItemUI != null) { stepItemUI.SetData(step); instantiatedStepItems.Add(stepItemUI); } else { Debug.LogError("orderPrefab¿¡ StepInfoItem.cs ½ºÅ©¸³Æ®°¡ ¾ø½À´Ï´Ù"); } if (jobSpeed.text == "0%") jobSpeed.text = $"{step.Speed}%"; } Instantiate(endPrefab, contentParent); } private void ShowProgramInfoPanel(InputAction.CallbackContext obj) { isPressingX = !isPressingX; if (isPressingX) { infoPanel.transform.SetParent(leftControllerTransform); infoPanel.transform.localPosition = new Vector3(0f, 0.2f, 0f); infoPanel.transform.localRotation = Quaternion.Euler(0, 180, 0); infoPanel.SetActive(true); } else { infoPanel.SetActive(false); } } private void HideProgramInfoPanel(InputAction.CallbackContext obj) { infoPanel.SetActive(false); } private void PlayProgram(InputAction.CallbackContext obj) { isPressingAorB = !isPressingAorB; if (isPressingAorB) { OnStartClicked?.Invoke(); } else { OnStopClicked?.Invoke(); } } }