using System.Collections.Generic;
|
using UnityEngine;
|
|
/// <summary>
|
/// 队伍资源追踪器
|
/// 分析队伍需要哪些资源(Spine动画、音频)
|
/// </summary>
|
public class TeamResTracker
|
{
|
/// <summary>
|
/// 队伍资源信息
|
/// </summary>
|
public class TeamResourceInfo
|
{
|
public List<BattleResCache.ResourceIdentifier> SpineResources = new List<BattleResCache.ResourceIdentifier>();
|
public List<BattleResCache.ResourceIdentifier> AudioResources = new List<BattleResCache.ResourceIdentifier>();
|
|
public void Clear()
|
{
|
SpineResources.Clear();
|
AudioResources.Clear();
|
}
|
|
/// <summary>
|
/// 获取所有资源数量
|
/// </summary>
|
public int GetTotalCount()
|
{
|
return SpineResources.Count + AudioResources.Count;
|
}
|
}
|
|
/// <summary>
|
/// 分析单个队伍的资源需求
|
/// </summary>
|
public static TeamResourceInfo AnalyzeTeam(TeamBase team, bool isPersistent)
|
{
|
TeamResourceInfo info = new TeamResourceInfo();
|
|
if (team == null || team.serverHeroes == null)
|
{
|
return info;
|
}
|
|
foreach (var teamHero in team.serverHeroes)
|
{
|
if (teamHero == null)
|
continue;
|
|
// 生成角色唯一标识(用于引用追踪)
|
string ownerId = $"{teamHero.heroId}_{teamHero.SkinID}";
|
|
// ===== 移除:不再预加载角色Spine资源 =====
|
// AddHeroSpineResource(teamHero, info, isPersistent, ownerId);
|
|
// 只预加载技能相关资源(音效、特效Spine)
|
AddSkillResources(teamHero, info, isPersistent, ownerId);
|
}
|
|
return info;
|
}
|
|
/// <summary>
|
/// 添加技能相关资源
|
/// </summary>
|
private static void AddSkillResources(TeamHero teamHero, TeamResourceInfo info, bool isPersistent, string ownerId)
|
{
|
if (teamHero.heroConfig == null)
|
return;
|
|
// 普攻技能
|
if (teamHero.heroConfig.AtkSkillID > 0)
|
{
|
AddSingleSkillResources(teamHero.heroConfig.AtkSkillID, info, isPersistent, ownerId);
|
}
|
|
// 怒气技能
|
if (teamHero.heroConfig.AngerSkillID > 0)
|
{
|
AddSingleSkillResources(teamHero.heroConfig.AngerSkillID, info, isPersistent, ownerId);
|
}
|
}
|
|
/// <summary>
|
/// 添加单个技能的资源
|
/// </summary>
|
private static void AddSingleSkillResources(int skillId, TeamResourceInfo info, bool isPersistent, string ownerId)
|
{
|
SkillConfig skillConfig = SkillConfig.Get(skillId);
|
if (skillConfig == null)
|
return;
|
|
AddSkillAudio(skillConfig, info, isPersistent, ownerId);
|
AddSkillEffects(skillConfig, info, isPersistent, ownerId);
|
}
|
|
private static void AddSkillAudio(SkillConfig skillConfig, TeamResourceInfo info, bool isPersistent, string ownerId)
|
{
|
if (skillConfig.SkinllSFX1 > 0)
|
{
|
AddAudioResource(skillConfig.SkinllSFX1, info, isPersistent, ownerId);
|
}
|
|
if (skillConfig.SkinllSFX2 > 0)
|
{
|
AddAudioResource(skillConfig.SkinllSFX2, info, isPersistent, ownerId);
|
}
|
}
|
|
private static void AddSkillEffects(SkillConfig skillConfig, TeamResourceInfo info, bool isPersistent, string ownerId)
|
{
|
List<int> effectIds = new List<int>();
|
|
if (skillConfig.BulletEffectId > 0) effectIds.Add(skillConfig.BulletEffectId);
|
if (skillConfig.ExplosionEffectId > 0) effectIds.Add(skillConfig.ExplosionEffectId);
|
if (skillConfig.ExplosionEffect2 > 0) effectIds.Add(skillConfig.ExplosionEffect2);
|
if (skillConfig.ExplosionEffect3 > 0) effectIds.Add(skillConfig.ExplosionEffect3);
|
if (skillConfig.ExplosionEffect4 > 0) effectIds.Add(skillConfig.ExplosionEffect4);
|
if (skillConfig.EffectId > 0) effectIds.Add(skillConfig.EffectId);
|
if (skillConfig.EffectId2 > 0) effectIds.Add(skillConfig.EffectId2);
|
if (skillConfig.MStartEffectId > 0) effectIds.Add(skillConfig.MStartEffectId);
|
if (skillConfig.BuffEffect > 0) effectIds.Add(skillConfig.BuffEffect);
|
if (skillConfig.TriggerEffect > 0) effectIds.Add(skillConfig.TriggerEffect);
|
|
foreach (int effectId in effectIds)
|
{
|
EffectConfig effectConfig = EffectConfig.Get(effectId);
|
if (effectConfig == null)
|
continue;
|
|
// 特效Spine资源(只预加载特效Spine,不预加载角色Spine)
|
if (effectConfig.isSpine > 0 && !string.IsNullOrEmpty(effectConfig.fxName))
|
{
|
var identifier = new BattleResCache.ResourceIdentifier
|
{
|
Directory = "UIEffect/" + effectConfig.packageName,
|
AssetName = effectConfig.fxName,
|
Type = BattleResCache.ResourceType.Spine,
|
IsPersistent = isPersistent,
|
OwnerId = ownerId // ← 添加所有者ID
|
};
|
|
if (!ContainsResource(info.SpineResources, identifier))
|
{
|
info.SpineResources.Add(identifier);
|
}
|
}
|
|
// 特效音频
|
if (effectConfig.audio > 0)
|
{
|
AddAudioResource(effectConfig.audio, info, isPersistent, ownerId);
|
}
|
}
|
}
|
|
private static void AddAudioResource(int audioId, TeamResourceInfo info, bool isPersistent, string ownerId)
|
{
|
AudioConfig audioConfig = AudioConfig.Get(audioId);
|
if (audioConfig == null)
|
return;
|
|
var identifier = new BattleResCache.ResourceIdentifier
|
{
|
Directory = "Audio/" + audioConfig.Folder, // ← 修复:添加 Audio/ 前缀
|
AssetName = audioConfig.Audio,
|
Type = BattleResCache.ResourceType.Audio,
|
IsPersistent = isPersistent,
|
OwnerId = ownerId
|
};
|
|
if (!ContainsResource(info.AudioResources, identifier))
|
{
|
info.AudioResources.Add(identifier);
|
}
|
}
|
|
/// <summary>
|
/// 检查资源列表是否包含指定资源
|
/// </summary>
|
private static bool ContainsResource(List<BattleResCache.ResourceIdentifier> list, BattleResCache.ResourceIdentifier resource)
|
{
|
foreach (var item in list)
|
{
|
if (item.GetKey() == resource.GetKey())
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|