Files
test/Assets/PerfectWorld/Scripts/UI/TabSelectButtonHandler.cs
vuong dinh hoang 20ee8dd4ad adjujst
2026-05-15 11:09:23 +07:00

58 lines
1.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using PerfectWorld.Scripts.Managers;
namespace BrewMonster.UI
{
/// <summary>
/// Button handler for TAB selection functionality / TAB选择功能的按钮处理器
/// </summary>
public class TabSelectButtonHandler : MonoBehaviour
{
public Button button;
void Start()
{
// Get the Button component / 获取Button组件
button = GetComponent<Button>();
if (button != null)
{
// Assign the method to button click / 将方法分配给按钮点击事件
button.onClick.AddListener(OnTabSelectButtonClicked);
}
else
{
Debug.LogWarning("TabSelectButtonHandler: No Button component found on this GameObject!");
}
}
/// <summary>
/// Called when the button is clicked / 按钮被点击时调用
/// </summary>
public void OnTabSelectButtonClicked()
{
// Get the host player / 获取主机玩家
var hostPlayer = CECGameRun.Instance?.GetHostPlayer();
if (hostPlayer == null)
{
Debug.LogWarning("TabSelectButtonHandler: Host player not found!");
return;
}
// Call AutoSelectTarget to select the nearest target / 调用AutoSelectTarget来选择最近的目标
int selectedId = hostPlayer.AutoSelectTarget();
}
void OnDestroy()
{
// Clean up the listener when destroyed / 销毁时清理监听器
if (button != null)
{
button.onClick.RemoveListener(OnTabSelectButtonClicked);
}
}
}
}