添加debug工具
This commit is contained in:
3
Assets/Project/Script/Tools.meta
Normal file
3
Assets/Project/Script/Tools.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ace0f38f4fa34f3595aa6f05f51226d1
|
||||
timeCreated: 1725362336
|
86
Assets/Project/Script/Tools/DebugTools.cs
Normal file
86
Assets/Project/Script/Tools/DebugTools.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Project.Script.Tools
|
||||
{
|
||||
public class DebugTools : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject inspectorGameObject;
|
||||
private bool _isShowDebugToolButton = false;
|
||||
|
||||
private bool IsShowDebugToolButton
|
||||
{
|
||||
get { return _isShowDebugToolButton; }
|
||||
set
|
||||
{
|
||||
if (_isShowDebugToolButton == value)
|
||||
return;
|
||||
_isShowDebugToolButton = value;
|
||||
if (!_isShowDebugToolButton)
|
||||
{
|
||||
inspectorGameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float _timer;
|
||||
private float _clickCount;
|
||||
[SerializeField] private float _time = 0.8f;
|
||||
[SerializeField] private uint _clickCountSum = 5;
|
||||
private bool _isStartClick = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||
DontDestroyOnLoad(gameObject);
|
||||
inspectorGameObject.SetActive(false);
|
||||
#else
|
||||
Destroy(gameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isStartClick)
|
||||
{
|
||||
_timer += Time.deltaTime;
|
||||
if (_timer > _time)
|
||||
{
|
||||
_timer = 0;
|
||||
_clickCount = 0;
|
||||
_isStartClick = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 3秒内连续点击屏幕5次设置 _isShowDebugToolButton = true 或者 false
|
||||
if (!Input.GetMouseButtonDown(0)) return;
|
||||
if (!_isStartClick)
|
||||
_isStartClick = true;
|
||||
|
||||
if (_timer < _time)
|
||||
{
|
||||
_clickCount++;
|
||||
if (!(_clickCount >= _clickCountSum)) return;
|
||||
IsShowDebugToolButton = !IsShowDebugToolButton;
|
||||
_clickCount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timer = 0;
|
||||
_clickCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (!IsShowDebugToolButton)
|
||||
return;
|
||||
// 屏幕顶部居中按钮用来显示或隐藏Inspector
|
||||
if (GUI.Button(new Rect(Screen.width / 2f - 50, 0, 150, 50),
|
||||
"对象监视面板" + (inspectorGameObject.activeSelf ? "(关闭)" : "(打开)")))
|
||||
{
|
||||
inspectorGameObject.SetActive(!inspectorGameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Project/Script/Tools/DebugTools.cs.meta
Normal file
3
Assets/Project/Script/Tools/DebugTools.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9a2525bb0c0493ba04bd913d977100f
|
||||
timeCreated: 1725362346
|
Reference in New Issue
Block a user