2025-10-15 14:08:07 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class UIActivityNode : UINode
|
|
|
|
|
|
{
|
2026-05-06 16:35:23 +08:00
|
|
|
|
public enum ActivityType
|
|
|
|
|
|
{
|
|
|
|
|
|
Group,
|
|
|
|
|
|
Normal
|
|
|
|
|
|
}
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private ActivityType _activityType;
|
|
|
|
|
|
|
2025-10-15 14:08:07 +08:00
|
|
|
|
[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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-07 13:31:03 +08:00
|
|
|
|
|
2025-10-15 14:08:07 +08:00
|
|
|
|
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-05-07 13:31:03 +08:00
|
|
|
|
/// <summary>
|
2026-06-05 18:47:07 +08:00
|
|
|
|
/// 改变该节点活动
|
2026-05-07 13:31:03 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newId"></param>
|
2026-06-05 18:47:07 +08:00
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
|
public void SetActivity(int newId,ActivityType type = ActivityType.Normal)
|
2026-05-07 13:31:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.activityID = newId;
|
2026-06-05 18:47:07 +08:00
|
|
|
|
this._activityType = type;
|
2026-05-07 13:31:03 +08:00
|
|
|
|
RefreshVisibility();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
2026-06-09 16:37:30 +08:00
|
|
|
|
/*var start_time = _activityType==ActivityType.Group?
|
2026-05-06 16:35:23 +08:00
|
|
|
|
logic.GetActivityGroupOpenTime(activityID):logic.GetActivityOpenTime(activityID);
|
|
|
|
|
|
|
|
|
|
|
|
var end_time = _activityType==ActivityType.Group?
|
|
|
|
|
|
logic.GetActivityGroupCloseTime(activityID):logic.GetActivityCloseTime(activityID);
|
2026-04-16 14:27:57 +08:00
|
|
|
|
|
|
|
|
|
|
// 该组没有任何活动时,起止为 MaxValue / MinValue,必然 start > end,统一视为不显示
|
|
|
|
|
|
if (start_time > end_time)
|
|
|
|
|
|
{
|
2026-05-07 17:54:53 +08:00
|
|
|
|
DebugUtil.Log((_activityType== ActivityType.Group ? "Activity Group " : "Activity ") + activityID + " has no valid time:" +
|
2026-05-06 16:35:23 +08:00
|
|
|
|
" start_time: " + start_time + " end_time: " + end_time);
|
2026-04-16 14:27:57 +08:00
|
|
|
|
gameObject.IsScaleShow(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var curTime = logic.GetCurTime();
|
2026-06-09 16:37:30 +08:00
|
|
|
|
bool is_active = curTime >= start_time && curTime <= end_time;*/
|
|
|
|
|
|
bool is_active = _activityType == ActivityType.Group ? logic.IsActivityGroupActive(activityID) : logic.IsActivityActive(activityID);
|
2026-04-16 14:27:57 +08:00
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|