using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class FlashRushToBuyCoolDown : MonoBehaviour
|
{
|
[SerializeField] Text timeText;
|
FlashRushToBuyModel rushToBuyModel { get { return ModelCenter.Instance.GetModel<FlashRushToBuyModel>(); } }
|
bool isReplace = false;
|
bool isStartReplace = false;
|
private void Awake()
|
{
|
GlobalTimeEvent.Instance.halfMinuteEvent += UpdateHalfMinute;
|
}
|
|
private void OnEnable()
|
{
|
SecondEvent();
|
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
|
GlobalTimeEvent.Instance.secondEvent += SecondEvent;
|
}
|
|
private void OnDisable()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
|
}
|
|
private void UpdateHalfMinute()
|
{
|
if (!isStartReplace) return;
|
|
isReplace = !isReplace;
|
}
|
|
private void SecondEvent()
|
{
|
DisplayTime();
|
}
|
|
void DisplayTime()
|
{
|
var operation = rushToBuyModel.GetOperationFlashRushToBuy();
|
if (operation == null) return;
|
int seconds = 0;
|
OperationTime operationTime;
|
OperationFlashRushToBuy.FlashSaleShop saleShop;
|
FlashRushToBuyModel.FlashRushToBuySate flashState = rushToBuyModel.GetActivityState(out seconds,out operationTime,out saleShop);
|
isStartReplace = false;
|
switch (flashState)
|
{
|
case FlashRushToBuyModel.FlashRushToBuySate.NoOpen:
|
break;
|
case FlashRushToBuyModel.FlashRushToBuySate.InAdvance:
|
if(seconds <= 3600)
|
{
|
isStartReplace = true;
|
if(!isReplace)
|
{
|
timeText.text = TimeUtility.SecondsToHMS(seconds);
|
}
|
else
|
{
|
timeText.text = operation.ToDisplayBuyTime(operationTime.startHour, operationTime.startMinute);
|
}
|
}
|
else
|
{
|
timeText.text = operation.ToDisplayBuyTime(operationTime.startHour, operationTime.startMinute);
|
}
|
break;
|
case FlashRushToBuyModel.FlashRushToBuySate.Begining:
|
timeText.text = "秒杀中";
|
break;
|
case FlashRushToBuyModel.FlashRushToBuySate.End:
|
timeText.text = "活动已结束";
|
break;
|
}
|
}
|
}
|
}
|
|