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); EventManager.Instance.Register(EventManager.EventName.RefreshUIActivity, RefreshVisibility); } private void OnEnable() { RefreshVisibility(); } /// /// 无绑定逻辑、无活动或不在活动组时间窗内时隐藏(scale=0);否则按时间窗显示。 /// private void RefreshVisibility() { if (logic == null) { DebugUtil.Log("UIActivityNode logic is null"); gameObject.IsScaleShow(false); return; } 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); } private void OnDestroy() { EventManager.Instance.Unregister(EventManager.EventName.RefreshUIActivity, RefreshVisibility); logic?.FakeOnDestroy(); } }