Files
HDRobotics/Assets/Scripts/View/PopupView.cs

132 lines
4.3 KiB
C#

using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public enum PopupResponse
{
InsConfirm, // 기록 확정
ModConfirm, // 수정 확정
Move, // 여기로 이동
Delete, // 삭제
DelConfirm, // 삭제 확정
Cancel // 취소
}
public class PopupView : MonoBehaviour
{
public event Action<PopupResponse> OnPopupResponse;
[SerializeField] private GameObject confirmPopupPanel;
[SerializeField] private GameObject modifyPopupPanel;
[SerializeField] private GameObject deletePopupPanel;
[SerializeField] private GameObject optionPopupPanel;
[SerializeField] private GameObject errorAlert;
[SerializeField] private Button ins_confirmButton; // '기록확정' 버튼
[SerializeField] private Button mod_confirmButton; // '수정확정' 버튼
[SerializeField] private Button moveButton; // '이동' 버튼
[SerializeField] private Button deleteButton; // '삭제' 버튼
[SerializeField] private Button del_confirmButton; // '삭제확정' 버튼
[SerializeField] private Button[] cancelButton; // '취소' 버튼
private Coroutine autoHideCoroutine;
void Start()
{
ins_confirmButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.InsConfirm));
mod_confirmButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.ModConfirm));
moveButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Move));
deleteButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Delete));
del_confirmButton.onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.DelConfirm));
for (int i = 0; i < cancelButton.Length; i++)
cancelButton[i].onClick.AddListener(() => OnPopupResponse?.Invoke(PopupResponse.Cancel));
confirmPopupPanel.SetActive(false);
modifyPopupPanel.SetActive(false);
deletePopupPanel.SetActive(false);
optionPopupPanel.SetActive(false);
}
public void ShowConfirmPopupFromRobot(Transform popPose)
{
//confirmPopupPanel.transform.position = popPose.position;
//confirmPopupPanel.transform.LookAt(Camera.main.transform);
//confirmPopupPanel.transform.Rotate(0, 180, 0);
confirmPopupPanel.SetActive(true);
}
public void ShowConfirmPopupFromPoint(Vector3 popPose)
{
//confirmPopupPanel.transform.position = popPose;
//confirmPopupPanel.transform.LookAt(Camera.main.transform);
//confirmPopupPanel.transform.Rotate(0, 180, 0);
confirmPopupPanel.SetActive(true);
}
public void ShowModifyPopup(Vector3 popPose)
{
//modifyPopupPanel.transform.position = popPose;
//modifyPopupPanel.transform.LookAt(Camera.main.transform);
//modifyPopupPanel.transform.Rotate(0, 180, 0);
modifyPopupPanel.SetActive(true);
}
public void ShowDeletePopup(Vector3 popPose)
{
//deletePopupPanel.transform.position = popPose;
//deletePopupPanel.transform.LookAt(Camera.main.transform);
//deletePopupPanel.transform.Rotate(0, 180, 0);
deletePopupPanel.SetActive(true);
}
public void ShowOptionPopup(Vector3 popPose)
{
optionPopupPanel.transform.position = popPose;
//optionPopupPanel.transform.LookAt(Camera.main.transform);
//optionPopupPanel.transform.Rotate(0, 180, 0);
optionPopupPanel.SetActive(true);
}
public void ShowErrorAlert(bool show, float duration = 2.0f)
{
if (autoHideCoroutine != null)
{
StopCoroutine(autoHideCoroutine);
autoHideCoroutine = null;
}
if (errorAlert != null)
{
errorAlert.SetActive(show);
}
if (show && duration > 0)
{
autoHideCoroutine = StartCoroutine(AutoHideCoroutine(duration));
}
}
// 지정된 시간 뒤에 팝업을 끄는 코루틴
private IEnumerator AutoHideCoroutine(float delay)
{
yield return new WaitForSeconds(delay);
if (errorAlert != null)
{
errorAlert.SetActive(false);
}
autoHideCoroutine = null;
}
public void HidePopup()
{
confirmPopupPanel.SetActive(false);
modifyPopupPanel.SetActive(false);
deletePopupPanel.SetActive(false);
optionPopupPanel.SetActive(false);
errorAlert.SetActive(false);
}
}