From b1b9a387a63e1ce77cf387b90ec170c7a05bb53b Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 03 十二月 2025 18:29:38 +0800
Subject: [PATCH] 125 战斗 替换加载蓝队逻辑 统一替换引用计数
---
Main/System/Battle/BattleResources/BattlePreloadManager.cs | 130 ++++++++++++++++++++++++++++---------------
1 files changed, 84 insertions(+), 46 deletions(-)
diff --git a/Main/System/Battle/BattleResources/BattlePreloadManager.cs b/Main/System/Battle/BattleResources/BattlePreloadManager.cs
index 9d69924..b2fa301 100644
--- a/Main/System/Battle/BattleResources/BattlePreloadManager.cs
+++ b/Main/System/Battle/BattleResources/BattlePreloadManager.cs
@@ -1,11 +1,10 @@
using UnityEngine;
using System;
using System.Collections.Generic;
+using Spine.Unity;
public class BattlePreloadManager
{
- private BattleSpineResLoader spineLoader = new BattleSpineResLoader();
- private BattleAudioResLoader audioLoader = new BattleAudioResLoader();
private BattleCacheManager cacheManager = new BattleCacheManager();
private BattleUnloadManager unloadManager = new BattleUnloadManager();
@@ -31,10 +30,18 @@
var redTeamInfo = AnalyzeTeamList(redTeamList, true);
var blueTeamInfo = AnalyzeTeamList(blueTeamList, false);
- // ===== 鏂板锛氭敞鍐屾垬鍦虹孩闃熻祫婧愰渶姹� =====
- cacheManager.RegisterBattlefieldRedTeam(battleGuid, redTeamInfo.SpineResources, redTeamInfo.AudioResources);
+ // ===== 鍚堝苟绾㈣摑闃熻祫婧愶紝缁熶竴娉ㄥ唽 =====
+ var allSpineResources = new List<BattleResCache.ResourceIdentifier>();
+ var allAudioResources = new List<BattleResCache.ResourceIdentifier>();
- StartPreload(redTeamInfo, blueTeamInfo, battleGuid, progressCallback, () =>
+ allSpineResources.AddRange(redTeamInfo.SpineResources);
+ allSpineResources.AddRange(blueTeamInfo.SpineResources);
+ allAudioResources.AddRange(redTeamInfo.AudioResources);
+ allAudioResources.AddRange(blueTeamInfo.AudioResources);
+
+ cacheManager.RegisterBattlefieldResources(battleGuid, allSpineResources, allAudioResources);
+
+ StartPreload(allSpineResources, allAudioResources, battleGuid, progressCallback, () =>
{
isLoading = false;
completeCallback?.Invoke();
@@ -95,11 +102,12 @@
return false;
}
- private void StartPreload(TeamResTracker.TeamResourceInfo redInfo, TeamResTracker.TeamResourceInfo blueInfo,
+ private void StartPreload(List<BattleResCache.ResourceIdentifier> spineResources,
+ List<BattleResCache.ResourceIdentifier> audioResources,
string battleGuid,
Action<float> progressCallback, Action completeCallback)
{
- int totalResources = redInfo.GetTotalCount() + blueInfo.GetTotalCount();
+ int totalResources = spineResources.Count + audioResources.Count;
if (totalResources == 0)
{
@@ -109,60 +117,90 @@
}
Debug.Log($"BattlePreloadManager: Preloading {totalResources} resources for battlefield {battleGuid}");
- Debug.Log($" Red: Spine={redInfo.SpineResources.Count}, Audio={redInfo.AudioResources.Count}");
- Debug.Log($" Blue: Spine={blueInfo.SpineResources.Count}, Audio={blueInfo.AudioResources.Count}");
+ Debug.Log($" Spine={spineResources.Count}, Audio={audioResources.Count}");
- int completedPhases = 0;
- int totalPhases = 4;
+ int loadedCount = 0;
- Action onPhaseComplete = () =>
+ Action onSingleComplete = () =>
{
- completedPhases++;
- float progress = (float)completedPhases / totalPhases;
+ loadedCount++;
+ float progress = (float)loadedCount / totalResources;
progressCallback?.Invoke(progress);
- if (completedPhases >= totalPhases)
+ if (loadedCount >= totalResources)
{
Debug.Log($"BattlePreloadManager: Completed! {cacheManager.GetCacheStats(battleGuid)}");
completeCallback?.Invoke();
}
};
- // 骞惰鍔犺浇4涓樁娈碉紙浼犲叆cacheManager鍜屾槸鍚︿负绾㈤槦鏍囪瘑锛�
- spineLoader.LoadSpineResourcesAsync(
- redInfo.SpineResources,
- cacheManager.GetSpineCache(true, battleGuid),
- null,
- onPhaseComplete,
- cacheManager, // 鈫� 浼犲叆绠$悊鍣�
- true // 鈫� 鏄孩闃�
- );
+ // 寮傛鍔犺浇鎵�鏈塖pine璧勬簮
+ foreach (var identifier in spineResources)
+ {
+ LoadSpineAsync(identifier, battleGuid, onSingleComplete);
+ }
- audioLoader.LoadAudioResourcesAsync(
- redInfo.AudioResources,
- cacheManager.GetAudioCache(true, battleGuid),
- null,
- onPhaseComplete,
- cacheManager, // 鈫� 浼犲叆绠$悊鍣�
- true // 鈫� 鏄孩闃�
- );
+ // 寮傛鍔犺浇鎵�鏈堿udio璧勬簮
+ foreach (var identifier in audioResources)
+ {
+ LoadAudioAsync(identifier, battleGuid, onSingleComplete);
+ }
+ }
+
+ private void LoadSpineAsync(BattleResCache.ResourceIdentifier identifier, string battleGuid, Action onComplete)
+ {
+ string key = identifier.GetKey();
- spineLoader.LoadSpineResourcesAsync(
- blueInfo.SpineResources,
- cacheManager.GetSpineCache(false, battleGuid),
- null,
- onPhaseComplete,
- null, // 鈫� 钃濋槦涓嶉渶瑕佸紩鐢ㄨ拷韪�
- false // 鈫� 涓嶆槸绾㈤槦
+ ResManager.Instance.LoadAssetAsync<SkeletonDataAsset>(
+ identifier.Directory,
+ identifier.AssetName,
+ (success, asset) =>
+ {
+ if (success && asset != null)
+ {
+ var skeletonData = asset as SkeletonDataAsset;
+ if (skeletonData != null)
+ {
+ var cachedRes = new BattleResCache.CachedResource(identifier, skeletonData, false);
+ cacheManager.UpdateResourceReference(key, cachedRes, battleGuid, identifier.OwnerId);
+ Debug.Log($"BattlePreloadManager: Loaded spine: {key}");
+ }
+ }
+ else
+ {
+ Debug.LogError($"BattlePreloadManager: Failed to load spine: {key}");
+ }
+ onComplete?.Invoke();
+ }
);
+ }
+
+ private void LoadAudioAsync(BattleResCache.ResourceIdentifier identifier, string battleGuid, Action onComplete)
+ {
+ string key = identifier.GetKey();
- audioLoader.LoadAudioResourcesAsync(
- blueInfo.AudioResources,
- cacheManager.GetAudioCache(false, battleGuid),
- null,
- onPhaseComplete,
- null, // 鈫� 钃濋槦涓嶉渶瑕佸紩鐢ㄨ拷韪�
- false // 鈫� 涓嶆槸绾㈤槦
+ ResManager.Instance.LoadAssetAsync<AudioClip>(
+ identifier.Directory,
+ identifier.AssetName,
+ (success, asset) =>
+ {
+ if (success && asset != null)
+ {
+ var audioClip = asset as AudioClip;
+ if (audioClip != null)
+ {
+ var cachedRes = new BattleResCache.CachedResource(identifier, audioClip, false);
+ cacheManager.UpdateResourceReference(key, cachedRes, battleGuid, identifier.OwnerId);
+ Debug.Log($"BattlePreloadManager: Loaded audio: {key}");
+ }
+ }
+ else
+ {
+ Debug.LogError($"BattlePreloadManager: Failed to load audio: {key}");
+ }
+ onComplete?.Invoke();
+ },
+ false // needExt = false
);
}
}
\ No newline at end of file
--
Gitblit v1.8.0