//target描述,此特效的主调者 //timePlayed用于同步动作和特效。快速出招时,特效要加一个已经播放时间,否则特效跟不上动作的播放步骤 public SFXEffectPlay PlayEffect(string file, CharacterLoader target, float timePlayed = 0.0f) { if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { if (f.ParseFile(file)) { EffectList.Add(file, f); //Debug.LogError("effect file:" + file); return(f.Play(target, timePlayed)); } } catch { Debug.LogError(file + " parse error"); } } else { //Debug.LogError("effect file:" + file); return(EffectList[file].Play(target, timePlayed)); } return(null); }
public void LoadEffect(string file) { if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { if (f.ParseFile(file)) { //过滤掉声音的 //bool add = false; //for (int i = 0; i < f.effectList.Count; i++) //{ // if (f.effectList[i].EffectType != "AUDIO") // { // add = true; // break; // } //} //if (add) EffectList.Add(file, f); } } catch (Exception exp) { Debug.LogError(file + " parse error" + exp.StackTrace); throw new Exception("effect load failed"); } } }
//一些环境特效,例如风之类的音效. public SFXEffectPlay PlayEffect(string file, GameObject obj, bool once = false, bool preload = false) { if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { f.ParseFile(file); EffectList[file] = f; if (!f.error) { return(f.Play(obj, once, preload)); } } catch { EffectList[file] = f; Debug.LogError(string.Format("{0} parse error", file)); } } else { if (EffectList[file].error) { return(null); } //Debug.LogError("effect file:" + file + " 455"); return(EffectList[file].Play(obj, once, preload)); } return(null); }
//一些环境特效,例如风之类的音效. public SFXEffectPlay PlayEffect(string file, GameObject obj, bool once = false) { if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { if (f.ParseFile(file)) { EffectList.Add(file, f); //Debug.LogError("effect file:" + file); return(f.Play(obj, once)); } else { Debug.LogError(file + " parse error445"); } } catch { Debug.LogError(file + " parse error449"); } } else { //Debug.LogError("effect file:" + file + " 455"); return(EffectList[file].Play(obj, once)); } return(null); }
//target描述,此特效的主调者 //timePlayed用于同步动作和特效。快速出招时,特效要加一个已经播放时间,否则特效跟不上动作的播放步骤 public SFXEffectPlay PlayEffect(string file, CharacterLoader target, float timePlayed = 0.0f) { if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { f.ParseFile(file); EffectList[file] = f; //Debug.LogError("effect file:" + file); return(f.Play(target, timePlayed)); } catch (Exception exp) { Debug.LogError(string.Format("{0} parse error {1}", file, exp.Message)); EffectList[file] = f; } } else { //Debug.LogError("effect file:" + file); if (EffectList[file].error) { return(null); } return(EffectList[file].Play(target, timePlayed)); } return(null); }
public SFXEffectPlay PlayEffect(string file, Vector3 position, bool once = false, bool preload = false) { GameObject obj = new GameObject(file); obj.transform.position = position; obj.transform.rotation = Quaternion.identity; obj.transform.localScale = Vector3.one; if (!Effect.ContainsKey(file)) { SfxFile f = LoadSfx(file); if (f != null) { return(f.Play(obj, once, preload)); } } else { if (Effect[file].error) { return(null); } //Debug.LogError("effect file:" + file + " 455"); return(Effect[file].Play(obj, once, preload)); } return(null); }
public void InitSync() { TextAsset list = Resources.Load <TextAsset>("effect.lst"); Eff = list.text.Split(new char[] { '\r', '\n' }, System.StringSplitOptions.RemoveEmptyEntries); TotalSfx = Eff.Length; for (int i = 0; i < Eff.Length; i++) { if (!EffectList.ContainsKey(Eff[i])) { SfxFile f = new SfxFile(); f.ParseFile(Eff[i]); EffectList[Eff[i]] = f; } } }
//一些环境特效,例如风之类的音效. public SFXEffectPlay PlayEffect(string file, GameObject obj, bool once = false, bool preload = false) { if (!Effect.ContainsKey(file)) { SfxFile f = LoadSfx(file); if (f != null) { return(f.Play(obj, once, preload)); } } else { if (Effect[file].error) { return(null); } //Debug.LogError("effect file:" + file + " 455"); return(Effect[file].Play(obj, once, preload)); } return(null); }
//target描述,此特效的主调者 //timePlayed用于同步动作和特效。快速出招时,特效要加一个已经播放时间,否则特效跟不上动作的播放步骤 public SFXEffectPlay PlayEffect(string file, MonoBehaviour target, float timePlayed) { //Debug.Log("timePlayed:" + timePlayed); if (!Effect.ContainsKey(file)) { SfxFile f = LoadSfx(file); if (f != null) { return(f.Play(target, timePlayed)); } } else { //Debug.LogError("effect file:" + file); if (Effect[file].error) { return(null); } return(Effect[file].Play(target, timePlayed)); } return(null); }
SfxFile LoadSfx(string file) { SfxFile f = new SfxFile(); if (CombatData.Ins.Chapter != null) { if (PluginEffect.ContainsKey(file)) { return(PluginEffect[file]); } //去掉标识符后的拓展名 string name = file; int dot = file.LastIndexOf('.'); if (dot != -1) { name = file.Substring(0, dot); } string path = CombatData.Ins.Chapter.GetResPath(FileExt.Sfx, name); if (!string.IsNullOrEmpty(path)) { try { f.ParseFile(path); PluginEffect[path] = f; return(f); } catch (Exception exp) { } } } f = new SfxFile(); try { f.ParseFile(file); Effect[file] = f; return(f); } catch (Exception exp) { } return(null); }
public SFXEffectPlay PlayEffect(string file, Vector3 position, bool once = false, bool preload = false) { GameObject obj = new GameObject(file); obj.transform.position = position; obj.transform.rotation = Quaternion.identity; obj.transform.localScale = Vector3.one; if (!EffectList.ContainsKey(file)) { SfxFile f = new SfxFile(); try { f.ParseFile(file); EffectList[file] = f; if (!f.error) { return(f.Play(obj, once, preload)); } } catch { EffectList[file] = f; Debug.LogError(string.Format("{0} parse error", file)); } } else { if (EffectList[file].error) { return(null); } //Debug.LogError("effect file:" + file + " 455"); return(EffectList[file].Play(obj, once, preload)); } return(null); }
public void Load(SfxFile effectFile, float timePlayed, bool preLoad = false) { loop = false; file = effectFile.strfile; var effectList = effectFile.effectList; playedTime = timePlayed; //必须看一下信息,才知道创建什么大小的预设,主要是网格可能大小不一样 SortedDictionary <int, SFXUnit> dic = new SortedDictionary <int, SFXUnit>(); for (int i = 0; i < effectList.Count; i++) { GameObject objSfx = null; SFXUnit sfx = null; if (effectList[i].EffectType.Equals("AUDIO")) { audioList.Add(effectList[i]); } else if (effectList[i].EffectType.Equals("BILLBOARD")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("BOX")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("PLANE")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("DONUT")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("MODEL")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("SPHERE")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("PARTICLE")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType.Equals("CYLINDER")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); } else if (effectList[i].EffectType.Equals("DRAG")) { objSfx = Instantiate(SfxUnit); sfx = objSfx.GetComponent <SFXUnit>(); } else { Debug.LogError("!!!"); } if (sfx != null) { dic.Add(i, sfx); //特效可以非角色发出. if (owner != null) { owner.AddAttackSFX(sfx);//因为这个特效可以做攻击 } sfx.name = effectList[i].EffectName; } } //第一次先创建,再初始化,否则先初始化的,如果要挂到后初始化的上面,会找不到对象 foreach (var each in dic) { if (each.Value != null) { played.Add(each.Value); } } //分2次循环,第一次让前面的可以找到后面的,第二次都开始初始化,就可以互相引用了 foreach (var each in dic) { if (each.Value != null) { each.Value.Init(effectList[each.Key], this, each.Key, timePlayed, preLoad); } } if (audioList.Count != 0) { audioUpdate = true; } }
public void Load(SfxFile effectFile, bool once = false) { loop = !once; file = effectFile.strfile; var effectList = effectFile.effectList; playedTime = 0.0f; //必须看一下信息,才知道创建什么大小的预设,主要是网格可能大小不一样 Dictionary <int, SFXUnit> dic = new Dictionary <int, SFXUnit>(); for (int i = 0; i < effectList.Count; i++) { GameObject objSfx = null; SFXUnit sfx = null; if (effectList[i].EffectType == "AUDIO") { audioList.Add(effectList[i]); } else if (effectList[i].EffectType == "BILLBOARD") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "BOX") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "PLANE") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "DONUT") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "MODEL") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "SPHERE") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "PARTICLE") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else if (effectList[i].EffectType == "CYLINDER") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); //objSfx = GameObject.Instantiate(Resources.Load("SFXCYLINDER")) as GameObject; //SFXCylinder sfxc = objSfx.GetComponent<SFXCylinder>(); //sfxc.Init(effectList[i], GetComponent<MeteorUnit>(), this); } else if (effectList[i].EffectType == "DRAG") { objSfx = GameObject.Instantiate(Resources.Load("SFXUnit")) as GameObject; sfx = objSfx.GetComponent <SFXUnit>(); //sfx.Init(effectList[i], this, i); } else { Debug.LogError("can not recognize"); } if (sfx != null) { dic.Add(i, sfx); //特效可以非角色发出. if (owner != null) { owner.AddAttackSFX(sfx);//因为这个特效可以做攻击 } sfx.name = effectList[i].EffectName; } } //第一次先创建,再初始化,否则先初始化的,如果要挂到后初始化的上面,会找不到对象 foreach (var each in dic) { if (each.Value != null) { played.Add(each.Value); } } //分2次循环,第一次让前面的可以找到后面的,第二次都开始初始化,就可以互相引用了 foreach (var each in dic) { if (each.Value != null) { each.Value.Init(effectList[each.Key], this, each.Key, 0); } } if (audioList.Count != 0) { audioPlayCorout = StartCoroutine(PlayAudioEffect()); } }