using System.Collections; using AOT.Boot; using UnityEngine; using YooAsset; namespace HotUpdate { /// /// 加载小镇广场环境,供角色站在广场中央。 /// public sealed class TownSquareSpawner : MonoBehaviour { public const string PrefabAddress = "TownSquare"; public const string EditorPrefabPath = "Assets/Bundles/Scenes/Town/TownSquare/TownSquare.prefab"; public const string ArtPackageName = "Art"; BootContext _ctx; GameObject _instance; public void Bind(BootContext ctx) => _ctx = ctx; public IEnumerator SpawnCo() { GameObject prefab = null; if (YooAssets.IsInitialized && YooAssets.TryGetPackage(ArtPackageName, out var art) && art.InitializeStatus == EOperationStatus.Succeeded) { var handle = art.LoadAssetAsync(PrefabAddress); yield return handle; if (handle.Status == EOperationStatus.Succeeded) prefab = handle.GetAssetObject(); else handle.Release(); } #if UNITY_EDITOR if (prefab == null) prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(EditorPrefabPath); #endif if (prefab == null) { Debug.LogError("[TownSquareSpawner] TownSquare prefab not found"); yield break; } if (_instance != null) Destroy(_instance); _instance = Instantiate(prefab); _instance.name = "TownSquare_Runtime"; DontDestroyOnLoad(_instance); if (Camera.main != null) { var cam = Camera.main; cam.transform.position = new Vector3(0f, 12f, -22f); cam.transform.rotation = Quaternion.Euler(28f, 0f, 0f); cam.fieldOfView = 40f; cam.backgroundColor = new Color(0.78f, 0.88f, 0.94f); } Debug.Log($"[TownSquareSpawner] spawned ok res={_ctx?.ResVersion}"); } } }