fix: 移除Timer
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.UI;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class DemoTimer : MonoBehaviour
|
||||
{
|
||||
public float totalTimeInSeconds = 1200f;
|
||||
private TMP_Text _timerText;
|
||||
private float _currentTime;
|
||||
private bool _isRunning;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_timerText = GetComponent<TMP_Text>();
|
||||
// 注册事件
|
||||
EnumEventSystem.Global.Register(GameLifecycleEvent.SessionStarted, TimerStart);
|
||||
EnumEventSystem.Global.Register(GameLifecycleEvent.SessionEnded, TimerStop);
|
||||
}
|
||||
|
||||
private void TimerStart()
|
||||
{
|
||||
_currentTime = totalTimeInSeconds;
|
||||
_isRunning = true;
|
||||
_timerText.enabled = true;
|
||||
}
|
||||
|
||||
private void TimerStop()
|
||||
{
|
||||
_currentTime = 0;
|
||||
_isRunning = false;
|
||||
_timerText.enabled = false;
|
||||
}
|
||||
|
||||
private void TimerPause()
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
_currentTime -= Time.deltaTime;
|
||||
if (_currentTime <= 0)
|
||||
{
|
||||
TimerPause();
|
||||
ForceReturnToMainMenu();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateTimerDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimerDisplay()
|
||||
{
|
||||
int hours = Mathf.FloorToInt(_currentTime / 3600);
|
||||
int minutes = Mathf.FloorToInt(_currentTime % 3600 / 60);
|
||||
int seconds = Mathf.FloorToInt(_currentTime % 60);
|
||||
|
||||
_timerText.text = $"{hours:D2}:{minutes:D2}:{seconds:D2}";
|
||||
}
|
||||
|
||||
private void ForceReturnToMainMenu()
|
||||
{
|
||||
// 打开EndPanel
|
||||
UIManager.Instance.ShowPanel<EndPanel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a21f67dffcd841adb0f408b5cf075ea8
|
||||
timeCreated: 1750061640
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Globalization;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.UI;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using AibisDream.Utility;
|
||||
@@ -85,14 +84,6 @@ namespace AibisDream
|
||||
case "Language":
|
||||
LocalizationKit.SwitchLanguage(LocalizationKit.ResolveLanguage(value));
|
||||
break;
|
||||
case "OpenTimer":
|
||||
var isTimerOpen = bool.TryParse(value, out var result) ? result : false;
|
||||
UIManager.Instance.GetPanel<InfoPanel>().SetTimerActive(isTimerOpen);
|
||||
break;
|
||||
case "EndTime":
|
||||
int endTime = int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out var endTime1) ? endTime1 : 1200;
|
||||
UIManager.Instance.GetPanel<InfoPanel>().SetTimerDuration(endTime);
|
||||
break;
|
||||
default:
|
||||
Debug.Log($"{propName}未正确处理");
|
||||
break;
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.UI
|
||||
{
|
||||
public class InfoPanel : MonoBehaviour, IUIPanel
|
||||
{
|
||||
[SerializeField] private DemoTimer demoTimer;
|
||||
[SerializeField] private GameObject loading;
|
||||
[SerializeField] private GameObject saveLoading;
|
||||
|
||||
public void SetTimerActive(bool isOpen)
|
||||
{
|
||||
demoTimer.gameObject.SetActive(isOpen);
|
||||
}
|
||||
|
||||
public void SetTimerDuration(int time)
|
||||
{
|
||||
demoTimer.totalTimeInSeconds = time;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
|
||||
@@ -2,7 +2,5 @@
|
||||
"Volume": "0.20",
|
||||
"Language": "",
|
||||
"WindowMode": "FullScreen",
|
||||
"TextSpeed": "3.0",
|
||||
"OpenTimer": false,
|
||||
"EndTime": 1500
|
||||
}
|
||||
"TextSpeed": "3.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user