using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace vnxbqy.UI { public class GMNotify : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public override void Init() { GlobalTimeEvent.Instance.secondEvent += SecondEvent; } public override void UnInit() { } public void OnBeforePlayerDataInitialize() { gmNotifies.Clear(); serverInited = false; } public void OnPlayerLoginOk() { serverInited = true; } private List gmNotifies = new List(); private ArrayList infoArray = new ArrayList(); private bool serverInited = false; private void SecondEvent() { if (!serverInited) { return; } for (int i = 0; i < gmNotifies.Count; i++) { var _notify = gmNotifies[i]; if (!CheckNotify(_notify)) { gmNotifies.RemoveAt(i); _notify = null; i--; continue; } if (CheckSend()) { if ((TimeUtility.ServerNow - _notify.nextNotifyTime).TotalSeconds >= 0) { var _totalMinutes = (int)(TimeUtility.ServerNow - _notify.start).TotalMinutes; var _detalMinutes = (_totalMinutes / _notify.interval + 1) * _notify.interval; _notify.nextNotifyTime = _notify.start.AddTicks(_detalMinutes * TimeSpan.TicksPerMinute); Notify(_notify); } } } } public void Notify(HA001_tagBroadCastInfo package) { if (package.IsDelOthers == 1) { gmNotifies.Clear(); } gmNotifies.Add(new GMNotifyMessgae() { start = TimeUtility.GetTime(package.StartTime), end = TimeUtility.GetTime(package.EndTime), message = UIHelper.ServerStringTrim(package.Msg).Replace(@"\", string.Empty), interval = package.Interval, nextNotifyTime = TimeUtility.GetTime(package.StartTime), }); } private void Notify(GMNotifyMessgae _notify) { ServerTipDetails.ShowMarquee(_notify.message, null, 10); ChatCtrl.Inst.RevChatInfo(_notify.message, infoArray); } private bool CheckNotify(GMNotifyMessgae _notify) { if ((TimeUtility.ServerNow - _notify.end).TotalSeconds > 0) { return false; } return true; } private bool CheckSend() { if(!(StageLoad.Instance.currentStage is DungeonStage)) { return false; } if (WindowCenter.Instance.IsOpen()) { return false; } return true; } public class GMNotifyMessgae { public DateTime start; public DateTime end; public DateTime nextNotifyTime; public int interval;//分钟 public string message = string.Empty; } } }