101 lines
2.8 KiB
C#
101 lines
2.8 KiB
C#
using Framework;
|
||
using UnityEngine;
|
||
|
||
public class UIActivityNode : UINode
|
||
{
|
||
public enum ActivityType
|
||
{
|
||
Group,
|
||
Normal
|
||
}
|
||
[SerializeField]
|
||
private ActivityType _activityType;
|
||
|
||
[SerializeField]
|
||
private int _activityID;
|
||
public int activityID
|
||
{
|
||
get { return _activityID; }
|
||
set
|
||
{
|
||
_activityID = value;
|
||
logic?.FakeAwake(); // Re-bind or refresh
|
||
}
|
||
}
|
||
|
||
private IActivityEntranceNode _logic;
|
||
public IActivityEntranceNode logic
|
||
{
|
||
get
|
||
{
|
||
return _logic;
|
||
}
|
||
set
|
||
{
|
||
_logic = value;
|
||
_logic?.FakeAwake();
|
||
}
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
// 发送事件,通知逻辑层创建和绑定逻辑实例
|
||
EventManager.Instance.Send(EventManager.EventName.ActivityNodeCreated, this);
|
||
EventManager.Instance.Register(EventManager.EventName.RefreshUIActivity, RefreshVisibility);
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
RefreshVisibility();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 改变该节点活动id
|
||
/// </summary>
|
||
/// <param name="newId"></param>
|
||
public void ChangeActivityID(int newId)
|
||
{
|
||
this.activityID = newId;
|
||
RefreshVisibility();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 无绑定逻辑、无活动或不在活动组时间窗内时隐藏(scale=0);否则按时间窗显示。
|
||
/// </summary>
|
||
private void RefreshVisibility()
|
||
{
|
||
if (logic == null)
|
||
{
|
||
DebugUtil.Log("UIActivityNode logic is null");
|
||
gameObject.IsScaleShow(false);
|
||
return;
|
||
}
|
||
|
||
var start_time = _activityType==ActivityType.Group?
|
||
logic.GetActivityGroupOpenTime(activityID):logic.GetActivityOpenTime(activityID);
|
||
|
||
var end_time = _activityType==ActivityType.Group?
|
||
logic.GetActivityGroupCloseTime(activityID):logic.GetActivityCloseTime(activityID);
|
||
|
||
// 该组没有任何活动时,起止为 MaxValue / MinValue,必然 start > end,统一视为不显示
|
||
if (start_time > end_time)
|
||
{
|
||
DebugUtil.Log((_activityType== ActivityType.Group ? "Activity Group " : "Activity ") + activityID + " has no valid time:" +
|
||
" start_time: " + start_time + " end_time: " + end_time);
|
||
gameObject.IsScaleShow(false);
|
||
return;
|
||
}
|
||
|
||
var curTime = logic.GetCurTime();
|
||
bool is_active = curTime >= start_time && curTime <= end_time;
|
||
gameObject.IsScaleShow(is_active);
|
||
DebugUtil.Log("UIActivityNode logic active is " + is_active);
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
EventManager.Instance.Unregister(EventManager.EventName.RefreshUIActivity, RefreshVisibility);
|
||
logic?.FakeOnDestroy();
|
||
}
|
||
}
|