少年修仙传客户端代码仓库
client_linchunjie
2018-09-17 db0192c0e911dc86d828ec650e995282e6eacdf2
System/OpenServerActivity/FlashSaleCoolDown.cs
@@ -12,25 +12,52 @@
        private void OnEnable()
        {
            DisplayTime();
            SecondEvent();
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            GlobalTimeEvent.Instance.secondEvent += SecondEvent;
            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
            OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;
        }
        private void DayResetEvent(int resetType)
        {
            SecondEvent();
        }
        private void SecondEvent()
        {
            var seconds = OperationTimeHepler.Instance.GetOperationSurplusTime(Operation.FlashSale);
            m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashSale, out operationBase))
            {
                var operation = (operationBase as OperationFlashSale);
                var seconds = operation.GetResetSurplusTime();
                if (seconds * TimeSpan.TicksPerSecond >= TimeSpan.TicksPerDay || seconds <= 0)
                {
                    if (m_Time.gameObject.activeSelf)
                    {
                        DisplayTime(0);
                    }
                }
                else
                {
                    m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
                    if (!m_Time.gameObject.activeSelf)
                    {
                        DisplayTime(seconds);
                    }
                }
            }
        }
        private void OnDisable()
        {
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
        }
        void DisplayTime()
        void DisplayTime(int seconds)
        {
            var seconds = OperationTimeHepler.Instance.GetOperationSurplusTime(Operation.FlashSale);
            m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
            m_Time.Begin(DateTime.Now.AddTicks(seconds * TimeSpan.TicksPerSecond));
        }
    }