| | |
| | | allSpineResources.AddRange(blueTeamInfo.SpineResources); |
| | | allAudioResources.AddRange(redTeamInfo.AudioResources); |
| | | allAudioResources.AddRange(blueTeamInfo.AudioResources); |
| | | |
| | | // 检查是否为同一战场的重复注册(比如队伍变更)——如果红队发生变更,需要强制卸载之前的常驻资源 |
| | | if (cacheManager.HasBattleRegistered(battleGuid)) |
| | | { |
| | | var existingRedOwners = cacheManager.GetRegisteredOwners(battleGuid, true); // 只比较常驻(红队) |
| | | var newRedOwners = new HashSet<string>(); |
| | | foreach (var r in redTeamInfo.SpineResources) if (!string.IsNullOrEmpty(r.OwnerId)) newRedOwners.Add(r.OwnerId); |
| | | foreach (var r in redTeamInfo.AudioResources) if (!string.IsNullOrEmpty(r.OwnerId)) newRedOwners.Add(r.OwnerId); |
| | | |
| | | bool different = false; |
| | | if (existingRedOwners.Count != newRedOwners.Count) different = true; |
| | | else |
| | | { |
| | | foreach (var o in existingRedOwners) if (!newRedOwners.Contains(o)) { different = true; break; } |
| | | } |
| | | |
| | | if (different) |
| | | { |
| | | // 计算哪些 Owner 被移除,只卸载这些 Owner 引用对应的资源以提高性能 |
| | | var removedOwners = new HashSet<string>(existingRedOwners); |
| | | removedOwners.ExceptWith(newRedOwners); |
| | | |
| | | if (removedOwners.Count > 0) |
| | | { |
| | | Debug.Log($"BattlePreloadManager: Detected red-team change for {battleGuid}. Removed owners: {removedOwners.Count}. Unloading affected resources only."); |
| | | cacheManager.UnregisterBattlefieldOwners(battleGuid, removedOwners); |
| | | } |
| | | else |
| | | { |
| | | Debug.Log($"BattlePreloadManager: Detected red-team change for {battleGuid}, but no owners were removed (only additions). No unload necessary."); |
| | | } |
| | | } |
| | | } |
| | | |
| | | cacheManager.RegisterBattlefieldResources(battleGuid, allSpineResources, allAudioResources); |
| | | |