From 3f2cd27c5dfb3b450245bf1a37fc1b3414031c7c Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 11 二月 2026 11:03:58 +0800
Subject: [PATCH] 小游戏适配 资源系统改造
---
Main/System/Battle/BattleField/BattleField.cs | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/Main/System/Battle/BattleField/BattleField.cs b/Main/System/Battle/BattleField/BattleField.cs
index 0fd882a..b0b24ca 100644
--- a/Main/System/Battle/BattleField/BattleField.cs
+++ b/Main/System/Battle/BattleField/BattleField.cs
@@ -5,6 +5,7 @@
using DG.Tweening;
using System.IO;
using System.Linq;
+using Cysharp.Threading.Tasks;
public class BattleField
@@ -87,7 +88,9 @@
{
guid = _guid;
+ #pragma warning disable CS0618 // Obsolete 鈥� sync legacy constructor, use CreateAsync for new code
GameObject go = ResManager.Instance.LoadAsset<GameObject>("Battle/Prefabs", "BattleRootNode");
+ #pragma warning restore CS0618
GameObject battleRootNodeGO = GameObject.Instantiate(go);
battleRootNode = battleRootNodeGO.GetComponent<BattleRootNode>();
battleRootNodeGO.name = this.GetType().Name;
@@ -98,6 +101,33 @@
recordPlayer = new RecordPlayer();
soundManager = new BattleSoundManager(this);
+ processingDeathObjIds = new HashSet<uint>();
+ }
+
+ /// <summary>
+ /// US2: Static async factory method. Creates BattleField with async resource loading.
+ /// </summary>
+ public static async UniTask<BattleField> CreateAsync(string _guid)
+ {
+ var field = new BattleField(_guid, skipResourceLoad: true);
+ GameObject go = await ResManager.Instance.LoadAssetAsync<GameObject>("Battle/Prefabs", "BattleRootNode");
+ GameObject battleRootNodeGO = GameObject.Instantiate(go);
+ field.battleRootNode = battleRootNodeGO.GetComponent<BattleRootNode>();
+ battleRootNodeGO.name = field.GetType().Name;
+ return field;
+ }
+
+ /// <summary>
+ /// US2: Protected constructor without resource loading (for async factory).
+ /// </summary>
+ protected BattleField(string _guid, bool skipResourceLoad)
+ {
+ guid = _guid;
+ battleObjMgr = new BattleObjMgr();
+ battleEffectMgr = new BattleEffectMgr();
+ battleTweenMgr = new BattleTweenMgr();
+ recordPlayer = new RecordPlayer();
+ soundManager = new BattleSoundManager(this);
processingDeathObjIds = new HashSet<uint>();
}
@@ -302,7 +332,22 @@
BattleMapConfig battleMapConfig = BattleMapConfig.Get(mapID);
if (battleMapConfig != null)
{
+ #pragma warning disable CS0618 // Obsolete 鈥� sync legacy fallback, use LoadMapAsync
Texture texture = ResManager.Instance.LoadAsset<Texture>("Texture/FullScreenBg", battleMapConfig.MapBg);
+ #pragma warning restore CS0618
+ battleRootNode.SetBackground(texture);
+ }
+ }
+
+ /// <summary>
+ /// US2: Async map loading.
+ /// </summary>
+ protected virtual async UniTask LoadMapAsync(int mapID)
+ {
+ BattleMapConfig battleMapConfig = BattleMapConfig.Get(mapID);
+ if (battleMapConfig != null)
+ {
+ Texture texture = await ResManager.Instance.LoadAssetAsync<Texture>("Texture/FullScreenBg", battleMapConfig.MapBg);
battleRootNode.SetBackground(texture);
}
}
--
Gitblit v1.8.0