You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.2 KiB
128 lines
3.2 KiB
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<string> listString; |
|
public TypePopup type; |
|
public System.Action<bool> OnRecieveSelect; |
|
|
|
public SettingData(List<string> listString, TypePopup type, System.Action<bool> OnRecieveSelect) |
|
{ |
|
this.listString = listString; |
|
this.type = type; |
|
this.OnRecieveSelect = OnRecieveSelect; |
|
} |
|
} |
|
static Dictionary<string, Popup> dicPopup = new Dictionary<string, Popup>(); |
|
public static void Open(string path, Transform parent, SettingData data) |
|
{ |
|
if (!dicPopup.ContainsKey(path)) |
|
{ |
|
dicPopup.Add(path, Instantiate(Resources.Load(path) as GameObject).GetComponent<Popup>()); |
|
|
|
#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<Text> 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<RectTransform>(); |
|
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); |
|
} |
|
}
|
|
|