修复问题,优化bug和游戏,resource资源拆迁

This commit is contained in:
2026-02-24 20:59:38 +08:00
parent d5c8966abd
commit 332307d18c
740 changed files with 6964 additions and 23604 deletions
+49 -12
View File
@@ -1,9 +1,12 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public static class BgmRuntimeBootstrap
{
private const string RuntimeAudioListenerName = "__RuntimeAudioListener";
private static readonly List<Transform> _transformBuffer = new List<Transform>(512);
private static readonly List<Transform> _transformStack = new List<Transform>(512);
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
private static void Bootstrap()
@@ -32,6 +35,17 @@ public static class BgmRuntimeBootstrap
}
private static void RemoveBgmParticlesInLoadedScenes()
{
int sceneCount = SceneManager.sceneCount;
for (int i = 0; i < sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
if (!scene.IsValid() || !scene.isLoaded) continue;
RemoveBgmParticlesInScene(scene);
}
}
private static void RemoveBgmParticlesInScene(Scene scene)
{
var emitters = Object.FindObjectsByType<BgmParticleEmitter>(FindObjectsInactive.Include, FindObjectsSortMode.None);
for (int i = 0; i < emitters.Length; i++)
@@ -42,12 +56,11 @@ public static class BgmRuntimeBootstrap
Object.Destroy(e.gameObject);
}
var all = Resources.FindObjectsOfTypeAll<Transform>();
for (int i = 0; i < all.Length; i++)
CollectTransformsInScene(scene, _transformBuffer);
for (int i = 0; i < _transformBuffer.Count; i++)
{
var t = all[i];
if (t == null) continue;
if (!t.gameObject.scene.IsValid() || !t.gameObject.scene.isLoaded) continue;
var t = _transformBuffer[i];
if (t == null || t.gameObject.scene != scene) continue;
if (t.name.Equals("BgmParticles", System.StringComparison.OrdinalIgnoreCase))
Object.Destroy(t.gameObject);
}
@@ -147,15 +160,39 @@ public static class BgmRuntimeBootstrap
if (string.IsNullOrEmpty(objectName))
return null;
Transform[] all = Object.FindObjectsByType<Transform>(FindObjectsInactive.Include, FindObjectsSortMode.None);
for (int i = 0; i < all.Length; i++)
CollectTransformsInScene(scene, _transformBuffer);
for (int i = 0; i < _transformBuffer.Count; i++)
{
Transform t = all[i];
if (t == null || t.gameObject.scene != scene)
continue;
if (string.Equals(t.name, objectName, System.StringComparison.OrdinalIgnoreCase))
return t.gameObject;
var t = _transformBuffer[i];
if (t == null || t.gameObject.scene != scene) continue;
if (string.Equals(t.name, objectName, System.StringComparison.OrdinalIgnoreCase)) return t.gameObject;
}
return null;
}
private static void CollectTransformsInScene(Scene scene, List<Transform> buffer)
{
buffer.Clear();
_transformStack.Clear();
var roots = scene.GetRootGameObjects();
for (int i = 0; i < roots.Length; i++)
{
var root = roots[i];
if (root == null) continue;
_transformStack.Add(root.transform);
while (_transformStack.Count > 0)
{
int last = _transformStack.Count - 1;
var t = _transformStack[last];
_transformStack.RemoveAt(last);
if (t == null) continue;
buffer.Add(t);
int childCount = t.childCount;
for (int c = 0; c < childCount; c++)
{
_transformStack.Add(t.GetChild(c));
}
}
}
}
}