From 5f728e2633e8e20ebafc4e534fe7e7362362c839 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期四, 04 十二月 2025 11:58:07 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts
---
Main/System/Battle/BattleResources/BattlePreloadManager.cs | 148 +++++++++++++++++++++++++++---------------------
1 files changed, 83 insertions(+), 65 deletions(-)
diff --git a/Main/System/Battle/BattleResources/BattlePreloadManager.cs b/Main/System/Battle/BattleResources/BattlePreloadManager.cs
index f6885cd..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,7 +30,18 @@
var redTeamInfo = AnalyzeTeamList(redTeamList, true);
var blueTeamInfo = AnalyzeTeamList(blueTeamList, false);
- StartPreload(redTeamInfo, blueTeamInfo, battleGuid, progressCallback, () =>
+ // ===== 鍚堝苟绾㈣摑闃熻祫婧愶紝缁熶竴娉ㄥ唽 =====
+ var allSpineResources = new List<BattleResCache.ResourceIdentifier>();
+ var allAudioResources = new List<BattleResCache.ResourceIdentifier>();
+
+ 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();
@@ -92,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)
{
@@ -106,83 +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 // 鈫� 涓嶆槸绾㈤槦
- );
-
- audioLoader.LoadAudioResourcesAsync(
- blueInfo.AudioResources,
- cacheManager.GetAudioCache(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();
+ }
);
}
- /// <summary>
- /// 澶勭悊绾㈤槦鍙樻洿锛氭竻绌烘棫鐨勶紝閲嶆柊鍔犺浇鏂扮殑
- /// </summary>
- public void HandleRedTeamChange(List<TeamBase> newRedTeamList, Action completeCallback)
+ private void LoadAudioAsync(BattleResCache.ResourceIdentifier identifier, string battleGuid, Action onComplete)
{
- if (newRedTeamList == null)
- {
- completeCallback?.Invoke();
- return;
- }
+ string key = identifier.GetKey();
- Debug.Log("BattlePreloadManager: Handling red team change");
-
- // 1. 鍗歌浇鏃х殑绾㈤槦璧勬簮
- unloadManager.UnloadRedTeamResources(cacheManager);
-
- // 2. 鍒嗘瀽鏂扮孩闃熻祫婧�
- var newRedInfo = AnalyzeTeamList(newRedTeamList, true);
-
- // 3. 棰勫姞杞芥柊绾㈤槦璧勬簮锛堢孩闃熸槸鍏ㄥ眬鐨勶紝浼犵┖瀛楃涓诧級
- StartPreload(newRedInfo, new TeamResTracker.TeamResourceInfo(), "", null, completeCallback);
+ 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