From 99a11d2bb19d74f6cc8584ac16838062af4fb301 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期五, 03 四月 2026 11:24:07 +0800
Subject: [PATCH] webgl 优化
---
Main/System/Battle/BattleObject/BattleObjMgr.cs | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/Main/System/Battle/BattleObject/BattleObjMgr.cs b/Main/System/Battle/BattleObject/BattleObjMgr.cs
index 9fdadf0..9b301df 100644
--- a/Main/System/Battle/BattleObject/BattleObjMgr.cs
+++ b/Main/System/Battle/BattleObject/BattleObjMgr.cs
@@ -8,8 +8,39 @@
public class BattleObjMgr
{
// 姝讳骸涓嶅彲浠ュ皢BattleObject绉诲嚭瀛楀吀/鍒楄〃
- public List<BattleObject> redCampList => new List<BattleObject>(redCampDict.Values);
- public List<BattleObject> blueCampList => new List<BattleObject>(blueCampDict.Values);
+ // 缂撳瓨闃佃惀鍒楄〃锛屼粎鍦ㄥ瓧鍏稿彉鏇存椂閲嶅缓锛岄伩鍏嶆瘡娆″睘鎬ц闂垎閰嶆柊List
+ private List<BattleObject> _redCampListCache;
+ private List<BattleObject> _blueCampListCache;
+ private bool _redCampDirty = true;
+ private bool _blueCampDirty = true;
+ public List<BattleObject> redCampList
+ {
+ get
+ {
+ if (_redCampDirty || _redCampListCache == null)
+ {
+ if (_redCampListCache == null) _redCampListCache = new List<BattleObject>(redCampDict.Count);
+ else _redCampListCache.Clear();
+ foreach (var kv in redCampDict) _redCampListCache.Add(kv.Value);
+ _redCampDirty = false;
+ }
+ return _redCampListCache;
+ }
+ }
+ public List<BattleObject> blueCampList
+ {
+ get
+ {
+ if (_blueCampDirty || _blueCampListCache == null)
+ {
+ if (_blueCampListCache == null) _blueCampListCache = new List<BattleObject>(blueCampDict.Count);
+ else _blueCampListCache.Clear();
+ foreach (var kv in blueCampDict) _blueCampListCache.Add(kv.Value);
+ _blueCampDirty = false;
+ }
+ return _blueCampListCache;
+ }
+ }
private Dictionary<int, BattleObject> redCampDict = new Dictionary<int, BattleObject>();
private Dictionary<int, BattleObject> blueCampDict = new Dictionary<int, BattleObject>();
@@ -40,6 +71,12 @@
await CreateTeam(posNodeList, campDict, teamBase, _camp, active);
}
+ private void MarkCampDirty(Dictionary<int, BattleObject> campDict)
+ {
+ if (campDict == redCampDict) _redCampDirty = true;
+ else if (campDict == blueCampDict) _blueCampDirty = true;
+ }
+
protected async UniTask CreateTeam(List<GameObject> posNodeList, Dictionary<int, BattleObject> campDict, TeamBase teamBase, BattleCamp _Camp, bool active)
{
DestroyTeam(campDict);
@@ -61,6 +98,7 @@
battleObj.SetSpeedRatio(battleField.speedRatio);
}
}
+ MarkCampDirty(campDict);
if (teamBase.teamMingge != null)
{
@@ -163,10 +201,12 @@
if (battleObj.Camp == BattleCamp.Red)
{
redCampDict.Remove(battleObj.GetPositionNum());
+ _redCampDirty = true;
}
else
{
blueCampDict.Remove(battleObj.GetPositionNum());
+ _blueCampDirty = true;
}
allBattleObjDict.Remove((int)objID);
BattleObjectFactory.DestroyBattleObject((int)objID, battleObj);
@@ -187,6 +227,7 @@
}
}
campDict.Clear();
+ MarkCampDirty(campDict);
}
// 绌洪棽鐘舵��
--
Gitblit v1.8.0