From 80277e13ec4fbccce0695ddf573a2d927f42edba Mon Sep 17 00:00:00 2001 From: hyskai <2545507770@qq.com> Date: Wed, 30 Oct 2024 01:34:17 +0800 Subject: [PATCH] add --- meng_yao/Assets/script/Manager/Promptmgr.cs | 42 +++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/meng_yao/Assets/script/Manager/Promptmgr.cs b/meng_yao/Assets/script/Manager/Promptmgr.cs index 8b3098ad5..f81da7141 100644 --- a/meng_yao/Assets/script/Manager/Promptmgr.cs +++ b/meng_yao/Assets/script/Manager/Promptmgr.cs @@ -7,8 +7,10 @@ public class Promptmgr : MonoBehaviour public static Promptmgr Instance; private GameObject PromptPrefab; private GameObject PromptWhiltePrefab; - private float movedistance = 800f;//移动的距离 + private float movedistance = 400f;//移动的距离 private float moveDuration = 1f;//移动所需的时间 + public GameObject canvs; + // Start is called before the first frame update void Start() { @@ -17,22 +19,43 @@ public class Promptmgr : MonoBehaviour DontDestroyOnLoad(this); PromptPrefab = (GameObject)Resources.Load("Prefabs/Prompt"); PromptWhiltePrefab = (GameObject)Resources.Load("Prefabs/PromptWhite"); + } + public void PromptBubble(string message) { - GameObject proobj = Instantiate(PromptPrefab); - proobj.transform.SetParent(GameObject.Find("Canvas").transform); - proobj.transform.position =new Vector3(Screen.width/2,Screen.height/2+33,0); - StartCoroutine(MoveUpandDestory(proobj)); - Text protext = proobj.transform.Find("Prompttext").GetComponent(); - protext.text = message; + PromptBubble(message, Color.white, Color.black); } + /// + /// 显示弹窗 + /// + /// 显示的内容 + /// 文字颜色,默认白色 + /// 背景颜色,默认黑色 + public void PromptBubble(string message, Color textColor, Color backgroundColor) + { + GameObject proobj = Instantiate(PromptPrefab); + proobj.transform.SetParent(canvs.transform); + proobj.transform.position = new Vector3(Screen.width / 2, Screen.height / 2 + 33, 0); + StartCoroutine(MoveUpandDestory(proobj)); + + Text protext = proobj.transform.Find("Prompttext").GetComponent(); + protext.text = message; + protext.color = textColor; // 设置文本颜色 + + // 设置背景颜色 + Image backgroundImage = proobj.GetComponent(); + if (backgroundImage != null) + { + backgroundImage.color = backgroundColor; // 设置背景颜色 + } + } public void PromptWhilteBubble(string message) { GameObject proobj = Instantiate(PromptWhiltePrefab); - proobj.transform.SetParent(GameObject.Find("Canvas").transform); + proobj.transform.SetParent(canvs.transform); proobj.transform.position = new Vector3(Screen.width / 2, Screen.height / 2 + 33, 0); StartCoroutine(MoveUpandDestory(proobj)); Text protext = proobj.transform.Find("Prompttext").GetComponent(); ; @@ -65,7 +88,4 @@ public class Promptmgr : MonoBehaviour } - - - }