using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.U2D; using UnityEngine.UI; using YooAsset; public class Game2Scene : MonoBehaviour { public GameObject CanvasRoot; private readonly List _cachedAssetOperationHandles = new List(1000); private SceneOperationHandle _subSceneHandle = null; void Start() { YooAssets.UnloadUnusedAssets(); // 初始化窗口 InitWindow(); // 异步加载背景音乐 StartCoroutine(AsyncLoadMusic()); } void OnDestroy() { foreach (var handle in _cachedAssetOperationHandles) { handle.Release(); } _cachedAssetOperationHandles.Clear(); } void OnGUI() { GUIConsole.OnGUI(); } void InitWindow() { // 同步加载背景图片 #if UNITY_WEBGL { var rawImage = CanvasRoot.transform.Find("background").GetComponent(); AssetOperationHandle handle = YooAssets.LoadAssetAsync("Texture/bg"); _cachedAssetOperationHandles.Add(handle); handle.Completed += (AssetOperationHandle obj) => { rawImage.texture = handle.AssetObject as Texture; }; } #else { var rawImage = CanvasRoot.transform.Find("background").GetComponent(); AssetOperationHandle handle = YooAssets.LoadAssetSync("Texture/bg"); _cachedAssetOperationHandles.Add(handle); rawImage.texture = handle.AssetObject as Texture; } #endif // 异步加载主场景 { var btn = CanvasRoot.transform.Find("load_scene").GetComponent