备份CatanBuilding瘦身独立工程
This commit is contained in:
188
Assets/Scripts/AOTScripts/SimpleDialog.cs
Normal file
188
Assets/Scripts/AOTScripts/SimpleDialog.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class SimpleDialog : MonoBehaviour
|
||||
{
|
||||
public class Context
|
||||
{
|
||||
public Action okAction;
|
||||
public Action closeAction;
|
||||
public string message;
|
||||
|
||||
public string message2;
|
||||
public string formatMessage;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Button btn_ok;
|
||||
|
||||
[SerializeField]
|
||||
private Button btn_close;
|
||||
|
||||
[SerializeField]
|
||||
TMP_Text message;
|
||||
|
||||
[SerializeField]
|
||||
TMP_Text message2;
|
||||
|
||||
public string DefaultMessage {get; private set;}
|
||||
|
||||
private Action onOk;
|
||||
|
||||
private Action onClose;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(message != null)
|
||||
{
|
||||
DefaultMessage = message.text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
btn_ok.onClick.AddListener(OnOkClicked);
|
||||
|
||||
if(btn_close != null)
|
||||
btn_close.onClick.AddListener(OnCloseClicked);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
btn_ok.onClick.RemoveAllListeners();
|
||||
|
||||
if(btn_close != null)
|
||||
btn_close.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
public async void Config(Context context)
|
||||
{
|
||||
this.onOk = context.okAction;
|
||||
this.onClose = context.closeAction;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
|
||||
await Awaiters.NextFrame;
|
||||
|
||||
if(message != null)
|
||||
{
|
||||
message.text = context.message;
|
||||
}
|
||||
|
||||
if(message2!=null)
|
||||
{
|
||||
message2.text = context.message2;;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseClicked()
|
||||
{
|
||||
onClose?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnOkClicked()
|
||||
{
|
||||
onOk?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
private void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
if(message != null) message.text = DefaultMessage;
|
||||
onOk = null;
|
||||
onClose = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public class SimpleDialog : MonoBehaviour
|
||||
{
|
||||
public class Context
|
||||
{
|
||||
public string title;
|
||||
public string message;
|
||||
public string okBtnText;
|
||||
public Action okAction;
|
||||
public Action closeAction;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Text tile;
|
||||
|
||||
[SerializeField]
|
||||
private Text message;
|
||||
|
||||
[SerializeField]
|
||||
private Button btn_ok;
|
||||
|
||||
[SerializeField]
|
||||
private Text btn_ok_text;
|
||||
|
||||
[SerializeField]
|
||||
private Button btn_close;
|
||||
|
||||
private Action onOk;
|
||||
|
||||
private Action onClose;
|
||||
|
||||
private string defaultOkBtnText;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
defaultOkBtnText = btn_ok_text.text;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
btn_ok.onClick.AddListener(OnOkClicked);
|
||||
btn_close.onClick.AddListener(OnCloseClicked);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
btn_ok.onClick.RemoveAllListeners();
|
||||
btn_close.onClick.RemoveAllListeners();
|
||||
}
|
||||
|
||||
public void Config(Context context)
|
||||
{
|
||||
this.tile.text = context.title ?? string.Empty;
|
||||
this.message.text = context.message ?? string.Empty;
|
||||
this.btn_ok_text.text = context.okBtnText ?? defaultOkBtnText;
|
||||
this.onOk = context.okAction;
|
||||
this.onClose = context.closeAction;
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnCloseClicked()
|
||||
{
|
||||
onClose?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OnOkClicked()
|
||||
{
|
||||
onOk?.Invoke();
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
private void Close()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
tile.text = string.Empty;
|
||||
message.text = string.Empty;
|
||||
btn_ok_text.text = defaultOkBtnText;
|
||||
onOk = null;
|
||||
onClose = null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user