150 lines
4.4 KiB
C#
150 lines
4.4 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using TMPro;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.InputSystem;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class ProgramInfoView : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
// --- <20><><EFBFBD>α<CEB1> <20><><EFBFBD><EFBFBD> <20>г<EFBFBD> ---
|
|||
|
|
[SerializeField] private Transform leftControllerTransform;
|
|||
|
|
[SerializeField] private GameObject infoPanel;
|
|||
|
|
public InputActionReference showInfoPanel;
|
|||
|
|
public InputActionReference hideInfoPanel;
|
|||
|
|
public InputActionReference playProgram;
|
|||
|
|
private bool isPressingX = false;
|
|||
|
|
private bool isPressingB = 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<StepInfoItem> instantiatedStepItems = new List<StepInfoItem>();
|
|||
|
|
|
|||
|
|
public event Action OnResetClicked;
|
|||
|
|
public event Action OnStartClicked;
|
|||
|
|
public event Action OnStopClicked;
|
|||
|
|
public event Action<int> OnMinusClicked;
|
|||
|
|
public event Action<int> 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)
|
|||
|
|
{
|
|||
|
|
playProgram.action.Enable();
|
|||
|
|
playProgram.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)
|
|||
|
|
{
|
|||
|
|
playProgram.action.performed -= PlayProgram;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UpdateProgramInfo(RobotProgram program, List<RobotMoveStep> steps)
|
|||
|
|
{
|
|||
|
|
if (program == null) return;
|
|||
|
|
|
|||
|
|
foreach (Transform child in contentParent)
|
|||
|
|
{
|
|||
|
|
Destroy(child.gameObject);
|
|||
|
|
}
|
|||
|
|
instantiatedStepItems.Clear();
|
|||
|
|
|
|||
|
|
// <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
if (steps == null) return;
|
|||
|
|
|
|||
|
|
foreach (RobotMoveStep step in steps)
|
|||
|
|
{
|
|||
|
|
GameObject newPrefab = Instantiate(orderPrefab, contentParent);
|
|||
|
|
StepInfoItem stepItemUI = newPrefab.GetComponent<StepInfoItem>();
|
|||
|
|
|
|||
|
|
if (stepItemUI != null)
|
|||
|
|
{
|
|||
|
|
stepItemUI.SetData(step);
|
|||
|
|
instantiatedStepItems.Add(stepItemUI);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogError("orderPrefab<61><62> StepInfoItem.cs <20><>ũ<EFBFBD><C5A9>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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)
|
|||
|
|
{
|
|||
|
|
isPressingB = !isPressingB;
|
|||
|
|
if (!isPressingB)
|
|||
|
|
{
|
|||
|
|
OnStartClicked?.Invoke();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
OnStopClicked?.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|