137 lines
4.2 KiB
C#
137 lines
4.2 KiB
C#
using BrewMonster.Network;
|
||
using System.Collections;
|
||
using EditorAttributes;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace BrewMonster.Scripts
|
||
{
|
||
public class DlgConsole : MonoBehaviour
|
||
{
|
||
[SerializeField] GameObject _panelConsole;
|
||
|
||
[SerializeField] TMP_InputField _consoleInput;
|
||
//send button
|
||
[SerializeField] Button _btnSend;
|
||
[SerializeField] Button _btnOpen;
|
||
[SerializeField] Button _btnClose;
|
||
|
||
[Space(10)]
|
||
[Header("Command Buttons")]
|
||
[SerializeField] Button _btnNoCooldown;
|
||
[SerializeField] Button _btnToggleAutoWrath;
|
||
|
||
private bool _isAutoAddWrathEnabled = false;
|
||
private Coroutine _autoAddWrathCoroutine;
|
||
|
||
private void Awake()
|
||
{
|
||
_btnSend?.onClick.AddListener(OnBtnSendClicked);
|
||
_btnOpen?.onClick.AddListener(OnBtnOpenClicked);
|
||
_btnClose?.onClick.AddListener(OnBtnCloseClicked);
|
||
_btnNoCooldown?.onClick.AddListener(OnBtnNoCooldownClicked);
|
||
_btnToggleAutoWrath?.onClick.AddListener(OnBtnToggleAutoWrathClicked);
|
||
|
||
DontDestroyOnLoad(this);
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
// Stop coroutine if running when object is destroyed
|
||
// 对象销毁时如果协程正在运行则停止它
|
||
if (_autoAddWrathCoroutine != null)
|
||
{
|
||
StopCoroutine(_autoAddWrathCoroutine);
|
||
_autoAddWrathCoroutine = null;
|
||
}
|
||
}
|
||
|
||
#region button events
|
||
private void OnBtnSendClicked()
|
||
{
|
||
string input = _consoleInput.text;
|
||
if (string.IsNullOrEmpty(input))
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (!input.StartsWith("d "))
|
||
return;
|
||
|
||
input = input.Substring(2);
|
||
string[] cmdParams = input.Split(' ');
|
||
|
||
}
|
||
|
||
private void OnBtnOpenClicked()
|
||
{
|
||
_panelConsole.SetActive(true);
|
||
}
|
||
private void OnBtnCloseClicked()
|
||
{
|
||
_panelConsole.SetActive(false);
|
||
}
|
||
private void OnBtnNoCooldownClicked()
|
||
{
|
||
UnityGameSession.c2s_CmdDebug(8903, 73125);
|
||
}
|
||
private void OnBtnAddWrathClicked()
|
||
{
|
||
UnityGameSession.c2s_CmdDebug(1992);
|
||
}
|
||
//1992
|
||
#endregion
|
||
|
||
[ContextMenu("Toggle Auto-Add Wrath")]
|
||
public void OnBtnToggleAutoWrathClicked()
|
||
{
|
||
ToggleAutoAddWrath();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Toggle auto-add wrath feature (calls OnBtnAddWrathClicked every 3 seconds)
|
||
/// 切换自动添加怒气功能(每3秒调用OnBtnAddWrathClicked)
|
||
/// </summary>
|
||
public void ToggleAutoAddWrath()
|
||
{
|
||
_isAutoAddWrathEnabled = !_isAutoAddWrathEnabled;
|
||
|
||
if (_isAutoAddWrathEnabled)
|
||
{
|
||
// Start the coroutine if not already running
|
||
// 如果尚未运行,则启动协程
|
||
if (_autoAddWrathCoroutine == null)
|
||
{
|
||
_autoAddWrathCoroutine = StartCoroutine(AutoAddWrathCoroutine());
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Stop the coroutine if running
|
||
// 如果正在运行,则停止协程
|
||
if (_autoAddWrathCoroutine != null)
|
||
{
|
||
StopCoroutine(_autoAddWrathCoroutine);
|
||
_autoAddWrathCoroutine = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Coroutine that calls OnBtnAddWrathClicked every 3 seconds
|
||
/// 每3秒调用OnBtnAddWrathClicked的协程
|
||
/// </summary>
|
||
private IEnumerator AutoAddWrathCoroutine()
|
||
{
|
||
while (_isAutoAddWrathEnabled)
|
||
{
|
||
BMLogger.LogError("Auto-Add Wrath: Adding wrath...");
|
||
OnBtnAddWrathClicked();
|
||
yield return new WaitForSeconds(3.0f);
|
||
}
|
||
_autoAddWrathCoroutine = null;
|
||
}
|
||
}
|
||
}
|