127 lines
3.6 KiB
C#
127 lines
3.6 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);
|
|
}
|
|
public void OnBtnNoCooldownClicked()
|
|
{
|
|
UnityGameSession.c2s_CmdDebug(8903, 73125);
|
|
}
|
|
/// 8903 73125
|
|
private void OnBtnAddWrathClicked()
|
|
{
|
|
UnityGameSession.c2s_CmdDebug(1992);
|
|
}
|
|
//1992
|
|
#endregion
|
|
|
|
[ContextMenu("Toggle Auto-Add Wrath")]
|
|
public void OnBtnToggleAutoWrathClicked()
|
|
{
|
|
ToggleAutoAddWrath();
|
|
}
|
|
|
|
public void ToggleAutoAddWrath()
|
|
{
|
|
_isAutoAddWrathEnabled = !_isAutoAddWrathEnabled;
|
|
|
|
if (_isAutoAddWrathEnabled)
|
|
{
|
|
// Start the coroutine if not already running
|
|
// 如果尚未运行,则启动协程
|
|
if (_autoAddWrathCoroutine == null)
|
|
{
|
|
_autoAddWrathCoroutine = StartCoroutine(AutoAddWrathCoroutine());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_autoAddWrathCoroutine != null)
|
|
{
|
|
StopCoroutine(_autoAddWrathCoroutine);
|
|
_autoAddWrathCoroutine = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator AutoAddWrathCoroutine()
|
|
{
|
|
while (_isAutoAddWrathEnabled)
|
|
{
|
|
OnBtnAddWrathClicked();
|
|
yield return new WaitForSeconds(3.0f);
|
|
}
|
|
_autoAddWrathCoroutine = null;
|
|
}
|
|
}
|
|
}
|