2025-10-15 14:08:07 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class UIActivityNode : UINode
|
|
|
|
|
|
{
|
|
|
|
|
|
[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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OnActivityIDChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
logic?.FakeAwake();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 发送事件,通知逻辑层创建和绑定逻辑实例
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.ActivityNodeCreated, this);
|
2026-04-16 14:27:57 +08:00
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.RefreshUIActivity, RefreshVisibility);
|
2025-10-15 14:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
|
{
|
2026-04-16 14:27:57 +08:00
|
|
|
|
RefreshVisibility();
|
|
|
|
|
|
}
|
2025-10-15 14:08:07 +08:00
|
|
|
|
|
2026-04-16 14:27:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 无绑定逻辑、无活动或不在活动组时间窗内时隐藏(scale=0);否则按时间窗显示。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void RefreshVisibility()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (logic == null)
|
2025-10-15 14:08:07 +08:00
|
|
|
|
{
|
2026-04-16 14:27:57 +08:00
|
|
|
|
DebugUtil.Log("UIActivityNode logic is null");
|
|
|
|
|
|
gameObject.IsScaleShow(false);
|
|
|
|
|
|
return;
|
2025-10-15 14:08:07 +08:00
|
|
|
|
}
|
2026-04-16 14:27:57 +08:00
|
|
|
|
|
|
|
|
|
|
var start_time = logic.GetActivityGroupOpenTime(activityID);
|
|
|
|
|
|
var end_time = logic.GetActivityGroupCloseTime(activityID);
|
|
|
|
|
|
|
|
|
|
|
|
// 该组没有任何活动时,起止为 MaxValue / MinValue,必然 start > end,统一视为不显示
|
|
|
|
|
|
if (start_time > end_time)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.Log("UIActivityNode logic end time is greater than start 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);
|
2025-10-15 14:08:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
2026-04-16 14:27:57 +08:00
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.RefreshUIActivity, RefreshVisibility);
|
2025-10-15 14:08:07 +08:00
|
|
|
|
logic?.FakeOnDestroy();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|