加载性能优化, 暂时放弃异步加载
This commit is contained in:
@@ -13,6 +13,14 @@ namespace Demo.Game
|
||||
{
|
||||
public partial class GameController : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[Resources]
|
||||
public void DebugGetScriptCounter()
|
||||
{
|
||||
Debug.Log(ScriptableObject.s_DebugContainer.Count, this);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Resources, SerializeField] public BasicAudioSystem MainAudio;
|
||||
[Resources, SerializeField] private CinemachineVirtualCameraBase MainCamera;
|
||||
[Resources, SerializeField] public GlobalConfig MainConfig;
|
||||
@@ -201,46 +209,37 @@ namespace Demo.Game
|
||||
rootGameObject.SetContent(nameof(SongOffset), SongOffset);
|
||||
rootGameObject.SetContent(nameof(IsAutoPlay), IsAutoPlay ? 1 : 0);
|
||||
rootGameObject.SetContent("SongLength", MainAudio.CurrentClip.length);
|
||||
Stack<IEnumerator> loadingTask = new();
|
||||
loadingTask.Push(rootGameObject.ParseFromScriptFile2Expr(rootObject));
|
||||
float waitClock = Time.realtimeSinceStartup;
|
||||
Dictionary<Type, int> DebugCounter = new();
|
||||
while (loadingTask.Count > 0)
|
||||
static IEnumerator Foo(IEnumerator ir)
|
||||
{
|
||||
// 防止大量无延迟函数如NewSubObject的使用导致的假死机
|
||||
if (Time.realtimeSinceStartup - waitClock > 0.1f)
|
||||
Stack<IEnumerator> loadingTask = new();
|
||||
loadingTask.Push(ir);
|
||||
while (loadingTask.Count > 0)
|
||||
{
|
||||
yield return null;
|
||||
waitClock = Time.realtimeSinceStartup;
|
||||
if (loadingTask.Peek().MoveNext())
|
||||
{
|
||||
if (loadingTask.Peek().Current is IEnumerator next)
|
||||
loadingTask.Push(next);
|
||||
else if (loadingTask.Peek().Current is ScriptableObject)
|
||||
yield return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
loadingTask.Pop();
|
||||
}
|
||||
}
|
||||
if (loadingTask.Peek().MoveNext())
|
||||
{
|
||||
if (loadingTask.Peek().Current is IEnumerator next)
|
||||
loadingTask.Push(next);
|
||||
}
|
||||
else
|
||||
{
|
||||
loadingTask.Pop();
|
||||
}
|
||||
yield return null;
|
||||
yield break;
|
||||
}
|
||||
int NDFSCount = 0;
|
||||
IEnumerator NDFS(ScriptableObject current)
|
||||
yield return Foo(rootGameObject.ParseFromScriptFile2Expr(rootObject));//ConventionUtility.AvoidFakeStop(rootGameObject.ParseFromScriptFile2Expr(rootObject));
|
||||
static void NDFS(ScriptableObject current)
|
||||
{
|
||||
foreach (var child in current.Childs)
|
||||
{
|
||||
ConventionUtility.StartCoroutine(NDFS(child));
|
||||
NDFSCount++;
|
||||
if(NDFSCount % 100 == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
NDFS(child);
|
||||
}
|
||||
if (current.IsScriptApply == false)
|
||||
ConventionUtility.StartCoroutine(current.ApplyScript());
|
||||
}
|
||||
//yield return
|
||||
ConventionUtility.StartCoroutine(NDFS(rootGameObject));
|
||||
NDFS(rootGameObject);
|
||||
float loadRootObjectEndTime = Time.realtimeSinceStartup;
|
||||
float loadRootObjectElapsed = (loadRootObjectEndTime - loadRootObjectStartTime) * 1000f;
|
||||
Debug.Log($"[GameInit] Load Root Object 耗时: {loadRootObjectElapsed:F2} ms", this);
|
||||
|
||||
Reference in New Issue
Block a user