Bind button
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
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();
|
||||
|
||||
if (selectedId != 0)
|
||||
{
|
||||
Debug.Log($"TabSelectButtonHandler: Selected target ID: {selectedId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("TabSelectButtonHandler: No valid target found to select.");
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
// Clean up the listener when destroyed / 销毁时清理监听器
|
||||
if (button != null)
|
||||
{
|
||||
button.onClick.RemoveListener(OnTabSelectButtonClicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8303596f53c1bfe49936ff828ad35e33
|
||||
Reference in New Issue
Block a user