1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public class MessageBoxController : MonoBehaviour
- {
- // Start is called before the first frame update
- //void Start()
- //{
-
- //}
- // Update is called once per frame
- //void Update()
- //{
-
- //}
- /*功能:跳出提示框。点击OK后消失
- msg: 提示内容
- callbackAction 绑定OK按键对应的函数*/
- public static void ShowMessage(string msg, Action callbackAction=null)
- {
- GameObject messageBox = Resources.Load<GameObject>("MessageBox/MessageBox");
- Instantiate(messageBox);
- if (messageBox != null)
- {
- GameObject msgBodyObject = GameObject.Find("msgBody");
- GameObject btnOkObject = GameObject.Find("btn_OK");
- msgBodyObject.GetComponent<TextMeshProUGUI>().text = msg;
- Button btnOk = btnOkObject.GetComponent<Button>();
- btnOk.onClick.AddListener(DestoryMessageBox);
- btnOk.onClick.AddListener(delegate { callbackAction(); });
- //disable Y and N button
- GameObject btnDisable = GameObject.Find("btn_Y");
- Destroy(btnDisable);
- btnDisable = GameObject.Find("btn_N");
- Destroy(btnDisable);
- }
- }
- public static void YorN_Message(string msg, Action yesAction=null, Action noAction=null)
- {
- GameObject messageBox = Resources.Load<GameObject>("MessageBox/MessageBox");
- Instantiate(messageBox);
- if (messageBox != null)
- {
- GameObject msgBodyObject = GameObject.Find("msgBody");
- msgBodyObject.GetComponent<TextMeshProUGUI>().text = msg;
- // bundle Y button actions
- GameObject btnYObject = GameObject.Find("btn_Y");
- Button btnY = btnYObject.GetComponent<Button>();
- btnY.onClick.AddListener(DestoryMessageBox);
- btnY.onClick.AddListener(delegate { yesAction(); });
- // bundle N button actions
- GameObject btnNObject = GameObject.Find("btn_N");
- Button btnN = btnNObject.GetComponent<Button>();
- btnN.onClick.AddListener(DestoryMessageBox);
- btnN.onClick.AddListener(delegate { noAction(); });
- //disable OK button
- GameObject btnDisable = GameObject.Find("btn_OK");
- Destroy(btnDisable);
- }
- }
- public static void DestoryMessageBox()
- {
- Debug.Log("destrory message func start");
- GameObject messageBox = GameObject.Find("MessageBox(Clone)");
- Destroy(messageBox);
- }
- }
|