| using System;  | 
| using System.Collections;  | 
| using System.Collections.Generic;  | 
| using UnityEngine;  | 
| using UnityEngine.UI;  | 
|   | 
| namespace vnxbqy.UI  | 
| {  | 
|     public class FlashSaleCoolDown : MonoBehaviour  | 
|     {  | 
|         [SerializeField] TimerBehaviour m_Time;  | 
|         [SerializeField] RectTransform m_ContainerAdvance;  | 
|         [SerializeField] Text m_AdvanceTime;  | 
|   | 
|         private void OnEnable()  | 
|         {  | 
|             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()  | 
|         {  | 
|             OperationBase operationBase;  | 
|             if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.FlashSale, out operationBase))  | 
|             {  | 
|                 var operation = (operationBase as OperationFlashSale);  | 
|                 bool inAdvance = false;  | 
|                 var seconds = 0;  | 
|                 if (operation.InAdvanceTime(TimeUtility.ServerNow))  | 
|                 {  | 
|                     inAdvance = true;  | 
|                     seconds = operation.GetSecondsBeforeStart(TimeUtility.ServerNow);  | 
|                 }  | 
|                 else  | 
|                 {  | 
|                     seconds = operation.GetResetSurplusTime();  | 
|                 }  | 
|   | 
|                 m_ContainerAdvance.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);  | 
|                         }  | 
|                     }  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         private void OnDisable()  | 
|         {  | 
|             GlobalTimeEvent.Instance.secondEvent -= SecondEvent;  | 
|             OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;  | 
|             m_Time.SetActive(false);  | 
|         }  | 
|   | 
|         void DisplayTime(int seconds)  | 
|         {  | 
|             m_Time.timeShow.color = seconds > 3600 ? UIHelper.GetUIColor(TextColType.Green) : UIHelper.GetUIColor(TextColType.Red);  | 
|             m_Time.Begin(seconds);  | 
|         }  | 
|   | 
|         void DisplayAdvance(int seconds)  | 
|         {  | 
|             m_AdvanceTime.text = Language.Get("OperationAdvanceOpen", TimeUtility.SecondsToHMS(seconds));  | 
|         }  | 
|     }  | 
| }  | 
|   |