106 lines
3.2 KiB
C#
106 lines
3.2 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
public class Promptmgr : MonoBehaviour
|
|||
|
{
|
|||
|
public static Promptmgr Instance;
|
|||
|
public GameObject PromptPrefab;
|
|||
|
private GameObject PromptWhiltePrefab;
|
|||
|
private float movedistance = 400f;//<2F>ƶ<EFBFBD><C6B6>ľ<EFBFBD><C4BE><EFBFBD>
|
|||
|
private float moveDuration = 1f;//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
public GameObject canvs;
|
|||
|
public Text protext;
|
|||
|
|
|||
|
private float timer;
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
|
|||
|
Instance = this;
|
|||
|
DontDestroyOnLoad(this);
|
|||
|
PromptPrefab = (GameObject)Resources.Load("Popups");
|
|||
|
protext=PromptPrefab.transform.Find("Text").GetComponent<Text>();
|
|||
|
//PromptWhiltePrefab = (GameObject)Resources.Load("Prefabs/PromptWhite");
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
//timer += Time.deltaTime;
|
|||
|
//if (timer>3f)
|
|||
|
//{
|
|||
|
// Destroy(this.transform.gameObject);
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
public void PromptBubble(string message)
|
|||
|
{
|
|||
|
PromptBubble(message, Color.black, Color.white);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="message"><3E><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
|
|||
|
/// <param name="textColor"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ĭ<EFBFBD>ϰ<EFBFBD>ɫ</param>
|
|||
|
/// <param name="backgroundColor"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>Ĭ<EFBFBD>Ϻ<EFBFBD>ɫ</param>
|
|||
|
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<Text>();
|
|||
|
protext.text = message;
|
|||
|
protext.color = textColor; // <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫ
|
|||
|
|
|||
|
// <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
Image backgroundImage = proobj.GetComponent<Image>();
|
|||
|
if (backgroundImage != null)
|
|||
|
{
|
|||
|
backgroundImage.color = backgroundColor; // <20><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
}
|
|||
|
}
|
|||
|
public void PromptWhilteBubble(string message)
|
|||
|
{
|
|||
|
GameObject proobj = Instantiate(PromptWhiltePrefab);
|
|||
|
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<Text>(); ;
|
|||
|
protext.text = message;
|
|||
|
}
|
|||
|
|
|||
|
IEnumerator MoveUpandDestory(GameObject obj)
|
|||
|
{
|
|||
|
RectTransform uielement = obj.GetComponent<RectTransform>();
|
|||
|
Vector3 startPosition = uielement.anchoredPosition;
|
|||
|
Vector3 endPosition = startPosition + new Vector3(0, movedistance, 0);
|
|||
|
|
|||
|
float elapsedTime = 0f;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
while (elapsedTime < moveDuration)
|
|||
|
{
|
|||
|
uielement.anchoredPosition = Vector3.Lerp(startPosition, endPosition, (elapsedTime / moveDuration));
|
|||
|
elapsedTime += Time.deltaTime;
|
|||
|
yield return null; // <20>ȴ<EFBFBD><C8B4><EFBFBD>һ֡
|
|||
|
}
|
|||
|
|
|||
|
uielement.anchoredPosition = endPosition; // ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ȷ
|
|||
|
|
|||
|
|
|||
|
if (uielement != null && uielement.gameObject != null)
|
|||
|
{
|
|||
|
Destroy(uielement.gameObject); // <20><><EFBFBD><EFBFBD>UIԪ<49><D4AA>
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|