性能优化与检测, 防止假死机

This commit is contained in:
2025-12-09 15:12:25 +08:00
parent 5ab19e39f2
commit eebf283e12
6 changed files with 66 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
using Unity.Cinemachine;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
@@ -200,7 +201,29 @@ namespace Demo.Game
rootGameObject.SetContent(nameof(SongOffset), SongOffset);
rootGameObject.SetContent(nameof(IsAutoPlay), IsAutoPlay ? 1 : 0);
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
yield return rootGameObject.ParseFromScriptFile2Expr(rootObject);
Stack<IEnumerator> loadingTask = new();
loadingTask.Push(rootGameObject.ParseFromScriptFile2Expr(rootObject));
float waitClock = Time.realtimeSinceStartup;
Dictionary<Type, int> DebugCounter = new();
while (loadingTask.Count > 0)
{
// 防止大量无延迟函数如NewSubObject的使用导致的假死机
if (Time.realtimeSinceStartup - waitClock > 0.1f)
{
yield return null;
waitClock = Time.realtimeSinceStartup;
}
if (loadingTask.Peek().MoveNext())
{
if (loadingTask.Peek().Current is IEnumerator next)
loadingTask.Push(next);
}
else
{
loadingTask.Pop();
}
yield return null;
}
int NDFSCount = 0;
IEnumerator NDFS(ScriptableObject current)
{