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(); EventQueueSystem.AddListener(JoinHandler); text = transform.Find("Name").GetComponent(); head = transform.Find("RawImage").GetComponent(); } 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.DOFade(1, 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; } } }