//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, August 06, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
public class LimitedTimePackageTime : MonoBehaviour
|
{
|
|
[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;
|
m_Time.SetActive(false);
|
}
|
|
private void DayResetEvent(int resetType)
|
{
|
secondEvent();
|
}
|
|
private void secondEvent()
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.GiftPackage, out operationBase))
|
{
|
var operation = (operationBase as GiftPackageClass);
|
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);
|
}
|
}
|
}
|
}
|
|
}
|
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));
|
}
|
}
|
|
}
|
|
|
|