using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public enum TypePopup { YesOrNo, Yes, Msg } public class Popup : MonoBehaviour { [System.Serializable] public class SettingData { public List listString; public TypePopup type; public System.Action OnRecieveSelect; public SettingData(List listString, TypePopup type, System.Action OnRecieveSelect) { this.listString = listString; this.type = type; this.OnRecieveSelect = OnRecieveSelect; } } static Dictionary dicPopup = new Dictionary(); public static void Open(string path, Transform parent, SettingData data) { if (!dicPopup.ContainsKey(path)) { dicPopup.Add(path, Instantiate(Resources.Load(path) as GameObject).GetComponent()); #if DebugLog Debug.Log($"현재 생성되어 있는 팝업 : {dicPopup.Count}"); #endif } dicPopup[path].transform.SetParent(parent); dicPopup[path].Initialized(data); } public RectTransform rect; [Space(10)] public Animation anim; public string strClipShow; public string strClipHide; [Space(10)] public List listText; [Space(10)] public GameObject[] panel; [Space(10)] public Button btnYes; public Button btnNo; public Button btnBack; [Space(10)] public SettingData data; public void Initialized(SettingData data) { this.data = data; if (rect == null) rect = GetComponent(); rect.sizeDelta = Vector2.zero; rect.localPosition = Vector2.zero; for (var i = 0; i < listText.Count && i < data.listString.Count; i++) listText[i].text = data.listString[i]; FormSetting(data.type); Show(); } void FormSetting(TypePopup type) { switch(type) { case TypePopup.YesOrNo: btnYes.gameObject.SetActive(true); btnNo.gameObject.SetActive(true); btnBack.interactable = false; panel[2].SetActive(true); break; case TypePopup.Yes: btnYes.gameObject.SetActive(true); btnNo.gameObject.SetActive(false); btnBack.interactable = true; panel[2].SetActive(true); break; case TypePopup.Msg: btnYes.gameObject.SetActive(false); btnNo.gameObject.SetActive(false); btnBack.interactable = true; panel[2].SetActive(false); break; } } void Show() { gameObject.SetActive(true); anim.Play(strClipShow); } void Hide() { anim.Play(strClipHide); } public void OnClick(bool CHK) { Hide(); if (data.OnRecieveSelect != null) { data.OnRecieveSelect(CHK); } } public void EventShowEnd() { } public void EventHideEnd() { gameObject.SetActive(false); } }