using ET; using System; using System.Collections.Generic; using DG.Tweening; using FairyGUI; namespace ET { public class MainUISlotComponentAwakeSystem : AwakeSystem { public override void Awake(MainUISlotComponent self) { MainUISlotComponent.Instance = self; } } public class MainUISlotComponent : Entity { public const int MainUISlotCount = 9; public const int PublicCoolTime = 5 * 1000; public enum SlotState { /// /// 使用过状态 /// Used, /// /// 等待状态 /// Common, /// /// 正在公共冷却 /// Cooling, } public static MainUISlotComponent Instance { get; set; } private readonly MainUISlot[] MainUISlotsArr = new MainUISlot[MainUISlotCount]; private readonly (MainUISlot, SlotState)[] _sameSlotArr = new (MainUISlot, SlotState)[MainUISlotCount]; public bool isInit; public MainUISlot[] GetAll() { return MainUISlotsArr; } public MainUISlot Get(int index) { return MainUISlotsArr[index]; } private (MainUISlot, SlotState)[] GetIndexs(int id) { int index = 0; foreach (MainUISlot item in GetAll()) { if (item?.MainUISlotId == id) { _sameSlotArr[index++] = (item, SlotState.Used); continue; } _sameSlotArr[index++] = (item, item!=null && item.IsCooling ? SlotState.Cooling : SlotState.Common); } return _sameSlotArr; } public void UpdateMainUISlot(int index, MainUISlot mainUISlot) { MainUISlotsArr[index] = mainUISlot; } /// /// 设置主UI的CD /// // by 左倾月 on 2020/6/22 at 0:11 /// /// 格子Id /// 冷却时间 public void SetCD(int id, int coolTime ) { var slotArr = GetIndexs(id); foreach ((MainUISlot slot, SlotState state) in slotArr) { if (slot == null) continue; switch (state) { case SlotState.Used: slot.slotState = SlotState.Used; Delay(slot, coolTime,true); break; case SlotState.Common: Delay(slot, PublicCoolTime,false); break; case SlotState.Cooling: break; } } } public void SetPublicCD(MainUIType mainUIType, int coolTime,int Id, int cd) { foreach (MainUISlot mainUISlot in GetAll()) { if(mainUISlot.slotState == SlotState.Common) { if (mainUISlot.MainUISlotId == Id && mainUISlot.MainUIType == mainUIType) { Delay(mainUISlot, cd, true); mainUISlot.slotState = SlotState.Used; } else { Delay(mainUISlot, coolTime, false); mainUISlot.slotState = SlotState.Cooling; } } } } //!冷却遮罩效果 private void Delay(MainUISlot slot, int time, bool isShowTime) { float rTime = time / 1000f; slot.IsCooling = true; slot.FUI_Btn.self.touchable = false; GImage mask = slot.FUI_Btn.m_imgMask; mask.fillAmount = 1; DOTween.To(() => mask.fillAmount, x => { mask.fillAmount = x; if (isShowTime) slot.FUI_Btn.m_txtCD.text = (x * rTime).ToString("f1"); }, 0, rTime).OnComplete(() => { slot.IsCooling = false; slot.FUI_Btn.m_txtCD.text = null; slot.FUI_Btn.m_imgMask.fillAmount = 0; slot.FUI_Btn.self.touchable = true; slot.slotState = SlotState.Common; }); } } }