|
@@ -1,7 +1,9 @@
|
|
|
using CommonAI.Zone;
|
|
|
+using CommonAI.Zone.ZoneEditor;
|
|
|
using CommonLang;
|
|
|
using Sirenix.Utilities;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using UnityEngine;
|
|
|
|
|
|
namespace ET.Client
|
|
@@ -36,12 +38,25 @@ namespace ET.Client
|
|
|
public static GameObjectPool Instance;
|
|
|
|
|
|
private readonly HashMap<string, List<GameObject>> goPool = new();
|
|
|
+ private readonly HashMap<string, AudioClip> audioPool = new();
|
|
|
|
|
|
//TODO: 选取当前场景的单位、技能(事件触发等等)
|
|
|
//TODO: BUFF
|
|
|
- public async ETTask CacheSceneObject(/*int scnId*/)
|
|
|
+ public async ETTask CacheSceneObject(int scnId)
|
|
|
{
|
|
|
- var templates = BattleResourceMgr.Instance.GameEditorTemplates.Templates;
|
|
|
+ var mgr = BattleResourceMgr.Instance.GameEditorTemplates;
|
|
|
+ var templates = mgr.Templates;
|
|
|
+
|
|
|
+ SceneData sceneData = mgr.LoadScene(scnId, false, true);
|
|
|
+ BattleMgr.Instance.Layer.Data = sceneData;
|
|
|
+
|
|
|
+ List<string> effectlist = new();
|
|
|
+ List<string> soundlist = new();
|
|
|
+
|
|
|
+ if(!sceneData.BGM.IsNullOrWhitespace())
|
|
|
+ {
|
|
|
+ soundlist.Add(sceneData.BGM);
|
|
|
+ }
|
|
|
|
|
|
//遍历模型
|
|
|
var units = templates.getUnits();
|
|
@@ -53,9 +68,12 @@ namespace ET.Client
|
|
|
var gameobj = UnityEngine.Object.Instantiate(prefab, GlobalViewComponent.Instance.RecycleNode, true);
|
|
|
gameobj.name = name;
|
|
|
RecycleObject(gameobj);
|
|
|
+
|
|
|
+ if(unit.FootCircleEffect != null) CacheLaunchEffect(unit.FootCircleEffect, ref effectlist, ref soundlist);
|
|
|
+ if (unit.SpawnEffect != null) CacheLaunchEffect(unit.SpawnEffect, ref effectlist, ref soundlist);
|
|
|
+ if (unit.DeadActionEffect != null) CacheLaunchEffect(unit.DeadActionEffect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
|
|
|
- List<string> effectlist = new();
|
|
|
var skills = templates.getAllSkillData();
|
|
|
foreach (var skt in skills.Values)
|
|
|
{
|
|
@@ -67,13 +85,13 @@ namespace ET.Client
|
|
|
}
|
|
|
foreach (var kf in act.KeyFrames)
|
|
|
{
|
|
|
- if (kf.Effect != null && !kf.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (kf.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(kf.Effect.Name);
|
|
|
+ CacheLaunchEffect(kf.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (kf.Spell != null)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, kf.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, kf.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -88,9 +106,40 @@ namespace ET.Client
|
|
|
gameobj.name = name;
|
|
|
RecycleObject(gameobj);
|
|
|
}
|
|
|
+
|
|
|
+ foreach(var sound in soundlist)
|
|
|
+ {
|
|
|
+ var key = sound;
|
|
|
+ var m = Regex.Match(key, "/?res/sound/.*/([\\w_\\d]+)\\.assetbundles$");
|
|
|
+ if (m.Success)
|
|
|
+ {
|
|
|
+ key = m.Groups[1].Value.ToLower();
|
|
|
+ }
|
|
|
+ if(audioPool.ContainsKey(key))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //Log.Debug($"cache audio: {key}");
|
|
|
+ var handle = await YooAssetProxy.LoadAssetAsync<AudioClip>($"Sound_{key}");
|
|
|
+ var ac = handle.GetAssetObject<AudioClip>();
|
|
|
+ ac.LoadAudioData();
|
|
|
+ audioPool.Add(key, ac);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void CacheSpellEffect(TemplateManager templates, int spellid, ref List<string> effectlist)
|
|
|
+ private void CacheLaunchEffect(LaunchEffect effect, ref List<string>effectlist, ref List<string> soundlist)
|
|
|
+ {
|
|
|
+ if(!effect.Name.IsNullOrWhitespace())
|
|
|
+ {
|
|
|
+ effectlist.Add(effect.Name);
|
|
|
+ }
|
|
|
+ if(!effect.SoundName.IsNullOrWhitespace())
|
|
|
+ {
|
|
|
+ soundlist.Add(effect.SoundName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CacheSpellEffect(TemplateManager templates, int spellid, ref List<string> effectlist, ref List<string> soundlist)
|
|
|
{
|
|
|
var spell = templates.getSpell(spellid);
|
|
|
if (spell == null)
|
|
@@ -106,24 +155,24 @@ namespace ET.Client
|
|
|
var frame = spell.HitIntervalKeyFrame;
|
|
|
if (frame != null)
|
|
|
{
|
|
|
- if (frame.Effect != null && !frame.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (frame.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(frame.Effect.Name);
|
|
|
+ CacheLaunchEffect(frame.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frame.Spell != null && frame.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, frame.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, frame.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frame.Attack != null)
|
|
|
{
|
|
|
var attack = frame.Attack;
|
|
|
- if (attack.Effect != null && !attack.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (attack.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(attack.Effect.Name);
|
|
|
+ CacheLaunchEffect(attack.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (attack.Spell != null && attack.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -131,48 +180,48 @@ namespace ET.Client
|
|
|
frame = spell.HitOnExplosionKeyFrame;
|
|
|
if (spell.HitOnExplosion && frame != null)
|
|
|
{
|
|
|
- if (frame.Effect != null && !frame.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (frame.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(frame.Effect.Name);
|
|
|
+ CacheLaunchEffect(frame.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frame.Spell != null && frame.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, frame.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, frame.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frame.Attack != null)
|
|
|
{
|
|
|
var attack = frame.Attack;
|
|
|
- if (attack.Effect != null && !attack.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (attack.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(attack.Effect.Name);
|
|
|
+ CacheLaunchEffect(attack.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (attack.Spell != null && attack.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach (var frm in spell.KeyFrames)
|
|
|
{
|
|
|
- if (frm.Effect != null && !frm.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (frm.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(frm.Effect.Name);
|
|
|
+ CacheLaunchEffect(frm.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frm.Spell != null && frame.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, frm.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, frm.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (frm.Attack != null)
|
|
|
{
|
|
|
var attack = frm.Attack;
|
|
|
- if (attack.Effect != null && !attack.Effect.Name.IsNullOrWhitespace())
|
|
|
+ if (attack.Effect != null)
|
|
|
{
|
|
|
- effectlist.Add(attack.Effect.Name);
|
|
|
+ CacheLaunchEffect(attack.Effect, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
if (attack.Spell != null && attack.Spell.SpellID != 0)
|
|
|
{
|
|
|
- CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist);
|
|
|
+ CacheSpellEffect(templates, attack.Spell.SpellID, ref effectlist, ref soundlist);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -188,6 +237,12 @@ namespace ET.Client
|
|
|
}
|
|
|
}
|
|
|
goPool.Clear();
|
|
|
+
|
|
|
+ foreach(var ac in audioPool.Values)
|
|
|
+ {
|
|
|
+ ac.UnloadAudioData();
|
|
|
+ }
|
|
|
+ audioPool.Clear();
|
|
|
}
|
|
|
|
|
|
public void RecycleObject(GameObject go, string key = "")
|
|
@@ -224,7 +279,7 @@ namespace ET.Client
|
|
|
{
|
|
|
goPool.Add(key, new List<GameObject>());
|
|
|
}
|
|
|
- Log.Warning($"new gameobject: ({key})");
|
|
|
+ Log.Warning($"not cache gameobject: ({key})");
|
|
|
|
|
|
var handle = await YooAssetProxy.LoadAssetAsync<GameObject>(key);
|
|
|
var prefab = handle.GetAssetObject<GameObject>();
|
|
@@ -232,5 +287,20 @@ namespace ET.Client
|
|
|
gameobj.name = key;
|
|
|
return gameobj;
|
|
|
}
|
|
|
+
|
|
|
+ public async ETTask<AudioClip> AcquireSound(string key)
|
|
|
+ {
|
|
|
+ if(audioPool.TryGetValue(key, out var ac))
|
|
|
+ {
|
|
|
+ return ac;
|
|
|
+ }
|
|
|
+ Log.Warning($"not cache audio: ({key})");
|
|
|
+
|
|
|
+ var handle = await YooAssetProxy.LoadAssetAsync<AudioClip>($"Sound_{key}");
|
|
|
+ var aac = handle.GetAssetObject<AudioClip>();
|
|
|
+ aac.LoadAudioData();
|
|
|
+ audioPool.Add(key, aac);
|
|
|
+ return aac;
|
|
|
+ }
|
|
|
}
|
|
|
}
|