Files
AIGame/AIClient/Assets/HotUpdate/Scripts/TownSquareSpawner.cs
T
udxandCursor 9793d8581d Add TownSquare scene assets, resource production docs, and model pipeline updates.
Bring in plaza props/prefabs, ZhaoYun source GLB, design originals, and Hunyuan/Blender tooling used to produce them.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 14:28:46 +08:00

68 lines
2.1 KiB
C#

using System.Collections;
using AOT.Boot;
using UnityEngine;
using YooAsset;
namespace HotUpdate
{
/// <summary>
/// 加载小镇广场环境,供角色站在广场中央。
/// </summary>
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<GameObject>(PrefabAddress);
yield return handle;
if (handle.Status == EOperationStatus.Succeeded)
prefab = handle.GetAssetObject<GameObject>();
else
handle.Release();
}
#if UNITY_EDITOR
if (prefab == null)
prefab = UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(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}");
}
}
}