using System;
|
using UnityEngine;
|
|
/// <summary>
|
/// 挑战标签页按钮的逻辑处理基类
|
/// 挂在与 ChallengeTabButton 同一个GameObject上
|
/// </summary>
|
[RequireComponent(typeof(ChallengeTabButton))]
|
public abstract class BaseChallengeTabHandler : MonoBehaviour
|
{
|
protected ChallengeTabButton tabButton;
|
private ChallengeTabButton.DisplayData displayData;
|
|
protected virtual void Awake()
|
{
|
tabButton = GetComponent<ChallengeTabButton>();
|
// 初始化一次 DisplayData,之后只修改变化的字段
|
displayData = new ChallengeTabButton.DisplayData
|
{
|
Index = GetIndex(),
|
RedpointId = GetRedpointId(),
|
OpenState = GetOpenState(),
|
FuncId = GetFuncId(),
|
OnClickAction = GetOnClickAction()
|
};
|
}
|
|
/// <summary>
|
/// 订阅事件 (由 ChallengeTabWin 在 OnPreOpen 时调用)
|
/// </summary>
|
public virtual void SubscribeEvents()
|
{
|
// 订阅全局刷新事件
|
TimeMgr.Instance.OnDayEvent += Refresh;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange;
|
// 订阅此按钮特定的事件
|
SubscribeToSpecificEvents();
|
}
|
|
/// <summary>
|
/// 取消订阅事件 (由 ChallengeTabWin 在 OnPreClose 时调用)
|
/// </summary>
|
public virtual void UnsubscribeEvents()
|
{
|
TimeMgr.Instance.OnDayEvent -= Refresh;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange;
|
UnsubscribeFromSpecificEvents();
|
}
|
|
/// <summary>
|
/// 刷新UI显示 (由 ChallengeTabWin 或事件回调调用)
|
/// </summary>
|
public void Refresh()
|
{
|
if (tabButton == null)
|
return;
|
displayData.CountInfo = GetCountInfo();
|
tabButton.Display(displayData);
|
}
|
|
private void OnFuncStateChange(int funcId)
|
{
|
if (GetOpenState() == 0 && funcId == GetFuncId())
|
{
|
Refresh();
|
}
|
}
|
|
/// <summary>
|
/// 获取Tab的索引(用于Icon和Name)
|
/// </summary>
|
protected abstract int GetIndex();
|
|
/// <summary>
|
/// 获取开启方式 (0=FuncID, 1=活动)
|
/// </summary>
|
protected abstract int GetOpenState();
|
|
/// <summary>
|
/// 获取功能ID
|
/// </summary>
|
protected abstract int GetFuncId();
|
|
/// <summary>
|
/// 获取红点ID
|
/// </summary>
|
protected abstract int GetRedpointId();
|
|
/// <summary>
|
/// 获取数量的显示文本
|
/// </summary>
|
protected abstract string GetCountInfo();
|
|
/// <summary>
|
/// 获取按钮点击时触发的 *具体* 业务逻辑
|
/// </summary>
|
protected abstract Action GetOnClickAction();
|
|
/// <summary>
|
/// 订阅此Tab特有的事件
|
/// </summary>
|
protected abstract void SubscribeToSpecificEvents();
|
|
/// <summary>
|
/// 取消订阅此Tab特有的事件
|
/// </summary>
|
protected abstract void UnsubscribeFromSpecificEvents();
|
}
|