少年修仙传客户端代码仓库
client_Hale
2018-09-18 bc49768eaf9757e20bd264dc6183b2497780ee08
System/Vip/LimitedTimePackageTime.cs
@@ -11,55 +11,83 @@
    public class LimitedTimePackageTime:MonoBehaviour {
        [SerializeField] Text m_LimitedTimePackageTime_text;
        [SerializeField] TimerBehaviour m_Time;
        [SerializeField] RectTransform m_ContainerAdvance;
        [SerializeField] Text m_AdvanceTime;
        private void OnEnable()
        {
            GlobalTimeEvent.Instance.secondEvent += secondEvent;
            OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;
        }
        private void OnDisable()
        {
            GlobalTimeEvent.Instance.secondEvent -= secondEvent;
            OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
        }
        private void DayResetEvent(int resetType)
        {
            secondEvent();
        }
        private void secondEvent()
        {
            int time = OperationTimeHepler.Instance.GetOperationSurplusTime(Operation.GiftPackage);
            if (time <= 0)
            OperationBase operationBase;
            if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.GiftPackage, out operationBase))
            {
                if (m_LimitedTimePackageTime_text.gameObject.activeSelf)
                var operation = (operationBase as GiftPackageClass);
                bool inAdvance = false;
                var seconds = 0;
                if (operation.InAdvanceTime(TimeUtility.ServerNow))
                {
                    m_LimitedTimePackageTime_text.gameObject.SetActive(false);
                }
                return;
            }
            if (time>86400)
            {
                if (m_LimitedTimePackageTime_text.gameObject.activeSelf)
                {
                    m_LimitedTimePackageTime_text.gameObject.SetActive(false);
                }
            }
            else
            {
                if (!m_LimitedTimePackageTime_text.gameObject.activeSelf)
                {
                    m_LimitedTimePackageTime_text.gameObject.SetActive(true);
                }
                if (time<3600)
                {
                    m_LimitedTimePackageTime_text.text = TimeUtility.SecondsToHMS(time);
                    m_LimitedTimePackageTime_text.color = UIHelper.GetUIColor(TextColType.Red);
                    inAdvance = true;
                    seconds = operation.GetSecondsBeforeStart(TimeUtility.ServerNow);
                }
                else
                {
                    m_LimitedTimePackageTime_text.text = TimeUtility.SecondsToHMS(time);
                    m_LimitedTimePackageTime_text.color = UIHelper.GetUIColor(TextColType.Green);
                    seconds = operation.GetResetSurplusTime();
                }
                m_ContainerAdvance.gameObject.SetActive(inAdvance);
                if (inAdvance)
                {
                    if (m_Time.gameObject.activeSelf)
                    {
                        DisplayTime(0);
                    }
                    DisplayAdvance(seconds);
                }
                else
                {
                    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);
                        }
                    }
                }
            }
        }
        void DisplayTime(int seconds)
        {
            m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);
            m_Time.Begin(DateTime.Now.AddTicks(seconds * TimeSpan.TicksPerSecond));
        }
        void DisplayAdvance(int seconds)
        {
            m_AdvanceTime.text = Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToHMS(seconds));
        }
    }
}