powerfun-unity/Assets/Scenes/Ride/Scripts/MessagePanelScript.cs
lishuo 8f0598580d 骑行页面消息通知
在线用户和影子选手用图片显示,缩放等功能按钮微调
2021-05-11 18:21:32 +08:00

77 lines
2.1 KiB
C#

using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
namespace Assets.Scenes.Ride.Scripts
{
public class MessagePanelScript : MonoBehaviour
{
CanvasGroup canvas;
Text text;
RawImage head;
string Name ="";
string url ="";
bool run = false;
private void Awake()
{
canvas = transform.GetComponent<CanvasGroup>();
EventQueueSystem.AddListener<JoinMessageEvent>(JoinHandler);
text = transform.Find("Name").GetComponent<Text>();
head = transform.Find("RawImage").GetComponent<RawImage>();
}
private void JoinHandler(JoinMessageEvent e)
{
Name = e.name;
url = e.url;
}
float timer = 1f;
private void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)//定时器 一秒执行一次
{
if (!string.IsNullOrEmpty(Name))
{
text.text = Name;
canvas.alpha = 1;
Name = string.Empty;
}
else
{
canvas.DOFade(0, 1);
}
if (!string.IsNullOrEmpty(url))
{
Utils.DisplayImage(head, url, false);
url = string.Empty;
}
//dic.
//foreach (var item in dic)
//{
// text.text = item.Key;
// Utils.DisplayImage(head, item.Value, true);
// dic.Remove(item.Key);
// break;
//}
timer = 1.0f;
}
}
}
public class JoinMessageEvent : GameEvent
{
public string name;//人物名称
public string url;//头像地址
public JoinMessageEvent(string name,string url)
{
this.name = name;
this.url = url;
}
}
}