using UnityEngine; using UnityEngine.UI; using DG.Tweening; using Assets.Scripts.UI.Control; using System; using UnityEngine.EventSystems; using UnityEngine.Events; public class Confirm : PFUIPanel { private PFUIText _title; private PFUIText _content; private PfUIButton _ok; private UnityAction _callback; public UnityAction _cancelCallback; private PfUIButton _cancel; protected override void Awake() { //var rect = this.gameObject.AddComponent(); //var layout = this.gameObject.AddComponent(); //layout.spacing = 20f; //layout.childAlignment = TextAnchor.MiddleCenter; var wrap = this.transform.Find("GameObject"); _title = wrap.Find("Title").GetComponent(); _content = wrap.Find("Content").GetComponent(); //text.transform.SetParent(layout.transform); //text.text = "阿斯达克法拉盛地方"; ///text = layout.transform.GetChild(0).gameObject.AddComponent(); //text = GetComponentInChildren().gameObject.AddComponent(); _ok = wrap.Find("Ok").GetComponent(); _cancel = wrap.Find("Cancel").GetComponent(); //button.onClick.AddListener(() => //{ // this.Close(); // //this.Destroy(true); // //DestroyImmediate(this); //}); UIManager.AddEvent(_ok.gameObject, EventTriggerType.PointerClick, (e) => { if(_callback != null) { _callback(); } }); UIManager.AddEvent(_cancel.gameObject, EventTriggerType.PointerClick, (e) => { if (_cancelCallback != null) { _cancelCallback(); } this.Close(); }); } // Start is called before the first frame update protected override void Start() { } public void Set(string title, string content, UnityAction callback,UnityAction cancelCallback) { //if(text == null) //{ // return; //} //text.text = txt; _title.Text = App.GetLocalString(title); _content.Text = App.GetLocalString(content); _callback = callback; _cancelCallback = cancelCallback; } public void SetType(int type) { string ok = "Ok",cancel = "Cancel"; if (type == 2) { ok = "Yes"; cancel = "No"; } ok = App.GetLocalString(ok); cancel = App.GetLocalString(cancel); _ok.transform.Find("Text").GetComponent().text = ok; _cancel.transform.Find("Text").GetComponent().text = cancel; } // Update is called once per frame void Update() { } public override void Show() { var panel = this.transform.Find("Panel"); var bg = panel.GetComponent(); //bg.alphaHitTestMinimumThreshold var color = bg.color; color.a = 0.6f; bg.color = color; base.Show(); } public override void Close() { var panel = this.transform.Find("Panel"); var bg = panel.GetComponent(); bg.DOFade(0, 0.2f).OnComplete(() => { this.gameObject.SetActive(false); }); } }