121 lines
3.2 KiB
C#
121 lines
3.2 KiB
C#
|
|
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<RectTransform>();
|
|
//var layout = this.gameObject.AddComponent<VerticalLayoutGroup>();
|
|
//layout.spacing = 20f;
|
|
//layout.childAlignment = TextAnchor.MiddleCenter;
|
|
|
|
var wrap = this.transform.Find("GameObject");
|
|
_title = wrap.Find("Title").GetComponent<PFUIText>();
|
|
_content = wrap.Find("Content").GetComponent<PFUIText>();
|
|
//text.transform.SetParent(layout.transform);
|
|
//text.text = "阿斯达克法拉盛地方";
|
|
///text = layout.transform.GetChild(0).gameObject.AddComponent<Text>();
|
|
|
|
//text = GetComponentInChildren<Transform>().gameObject.AddComponent<Text>();
|
|
|
|
_ok = wrap.Find("Ok").GetComponent<PfUIButton>();
|
|
_cancel = wrap.Find("Cancel").GetComponent<PfUIButton>();
|
|
//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 = title;
|
|
_content.Text = content;
|
|
_callback = callback;
|
|
_cancelCallback = cancelCallback;
|
|
}
|
|
|
|
public void SetType(int type)
|
|
{
|
|
string ok = "Ok",cancel = "Cancel";
|
|
if (type == 2)
|
|
{
|
|
ok = "Yes";
|
|
cancel = "No";
|
|
}
|
|
_ok.transform.Find("Text").GetComponent<Text>().text = ok;
|
|
_cancel.transform.Find("Text").GetComponent<Text>().text = cancel;
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public override void Show()
|
|
{
|
|
var panel = this.transform.Find("Panel");
|
|
var bg = panel.GetComponent<Image>();
|
|
//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<Image>();
|
|
|
|
bg.DOFade(0, 0.2f).OnComplete(() =>
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
}
|