/// <summary>播放单个语音</summary> private void PlaySound(IListenerTracker listener) { string name = null; name = listener.OnGetCurrentTransform().name.ToLower(); PlayUnit playUnit = null; //获取卡牌类型 //不是字母的话播放双语 if (listener.Type != TrackerType.LETTER) { string pare = null; //先去小库(500个单词)里找解释 if (ContentHelper.Instance.units.ContainsKey(name)) { WordUnit unit = ContentHelper.Instance.units[name]; pare = unit.Parephrase; } else//去词典里找解释 { pare = ContentHelper.Instance.GetPare(name); } playUnit = new Bilingual(name, pare); } else//只播放声音(非双语) { playUnit = new SingleTone(name); } AudioManager.Instance.SetUnits(playUnit); }
IEnumerator Spawn(Unit unit, int spNum, Transform[] wp) { if (!runingUnit[unit.type]) { yield break; } if (unitsPerSpawn > 0 && unit.PARAMS[UNIT_COUNT] > 0 && Hero.PARAMS[HERO_MANA_CURRENT] >= unit.PARAMS[UNIT_COST]) { for (int i = 0; i < unitsPerSpawn; i++) { if (unit.PARAMS[UNIT_COUNT] > 0) { GameObject portal = Instantiate(ResManager.instance.portal) as GameObject; portal.transform.position = new Vector3(spawnPoint[spNum].transform.position.x, spawnPoint[spNum].transform.position.y + 0.8f, spawnPoint[spNum].transform.position.z); GameObject newUnit = Instantiate(whichUnitsToSpawn) as GameObject; newUnit.transform.position = spawnPoint[spNum].transform.position; PlayUnit pUnit = newUnit.GetComponent <PlayUnit>(); pUnit.type = unit.type; pUnit.hp = unit.PARAMS[UNIT_HP_MAX]; pUnit.hpCurrent = unit.PARAMS[UNIT_HP_MAX]; pUnit.attackDelay = unit.PARAMS[UNIT_ATTACK_DELAY]; pUnit.speed = unit.PARAMS[UNIT_SPEED]; pUnit.damage = unit.PARAMS[UNIT_DAMAGE]; pUnit.distance = unit.PARAMS[UNIT_DISTANCE]; pUnit.armor = unit.PARAMS[UNIT_ARMOR]; pUnit.fireResist = unit.PARAMS[UNIT_FIRE_RESIST]; pUnit.iceResist = unit.PARAMS[UNIT_ICE_RESIST]; pUnit.electricResist = unit.PARAMS[UNIT_ELECTRIC_RESIST]; pUnit.IsDead = false; pUnit.wayPoints = wp; pUnit.finish = finish; pUnit.baseUnit = unit; UnitList.Add(pUnit); unit.PARAMS[UNIT_COUNT] -= 1; Hero.PARAMS[HERO_MANA_CURRENT] -= unit.PARAMS[UNIT_COST]; } } if (unit.PARAMS[UNIT_COUNT] == 0) { runingUnit[unit.type] = false; yield break; } yield return(new WaitForSeconds(spawnDelay)); if (!isFin) { StartCoroutine(Spawn(unit, spNum, wp)); } } }
// 按队列顺序播放声音 private void PlayByOrderInQueue() { if (queUnits.Count > 0) { if (currPlay != queUnits.Peek()) { currPlay = queUnits.Peek(); currPlay.Play(); } if (currPlay != null && currPlay.IsDone) { queUnits.Dequeue(); currPlay = null; } } }
public void UnitHit(Projectile newP) { int damage = newP.AttackDamage; int endDamage = damage; if (endDamage < 0) { endDamage = 0; } GameObject gt = Instantiate(ResManager.instance.DamageText, transform); gt.transform.position = new Vector3(transform.localPosition.x, transform.localPosition.y + 1, transform.localPosition.z); DamageText dt = gt.GetComponent <DamageText>(); dt.startMitonPlay("-" + endDamage, Colors.RedColor); if (hpCurrent - endDamage > 0) { hpCurrent -= endDamage; //Manager.Instance.AudioSource.PlayOneShot(SoundManager.Instance.Hit, 0.6f); //anim.Play("Hurt"); } else { //anim.SetTrigger("didDie"); Die(); } if (newP.PType == ProjectileType.fireball) { Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, newP.radius); foreach (Collider2D hit in colliders) { PlayUnit playUnit = hit.transform.GetComponent <PlayUnit>(); if (playUnit != null && playUnit != this) { GameObject go = Instantiate(ResManager.instance.Explosion, transform); go.transform.position = transform.localPosition; playUnit.UnitHit2(newP.AttackDamage); } } } }
IEnumerator PlayTwice(string en, string cn, Action callback = null, PlayUnit unit = null) { if (clips.ContainsKey(en)) { //Debug.Log("播放英文(已存在)!!!"); source.clip = clips[en]; source.Play(); yield return(new WaitForSeconds(clips[en].length)); StartCoroutine(PlayOther(cn, callback, unit)); } else { //Debug.Log("播放英文!!!"); PlaySound(en, () => { //Debug.Log("播放中文!!!"); StartCoroutine(PlayOther(cn, callback, unit)); }); } }
/// <summary> /// 通过名称播放声音 /// </summary> public void PlaySound(string clipName, Action callback = null, PlayUnit unit = null) //string clipName, string content = null, Action callback = null, PlayUnit unit = null { if (!clips.ContainsKey(clipName)) //如果clips不包含此音频,从本地加载,本地没有则合成 { path = Tips.SOUNDS + clipName + Tips.WAV; if (File.Exists(path))//加载本地音频 { StartCoroutine(LoadSound(path, clipName, callback, true, unit)); } else //先合成并播放音频,而后加载合成的音频 { //Debug.Log("要合成了!"); callBack = callback; currUnit = unit; Speak(clipName); } } else { StartCoroutine(PlayCallBack(clips[clipName], callback, true, unit)); } }
IEnumerator PlayOther(string cn, Action callback = null, PlayUnit unit = null) { yield return(new WaitForSeconds(0f)); if (clips.ContainsKey(cn)) { source.clip = clips[cn]; source.Play(); yield return(new WaitForSeconds(clips[cn].length)); if (callback != null) { callback(); } if (unit != null) { unit.IsDone = true; } } else { PlaySound(cn, callback, unit); } }
public void UnRegisterUnit(PlayUnit enemy) { UnitList.Remove(enemy); Destroy(enemy.gameObject); }
public void RegisterUnit(PlayUnit enemy) { UnitList.Add(enemy); }
public void SetUnitList(PlayUnit unit) { unitList.Add(unit); }
//加载声音,并根据参数确定是否播放 IEnumerator LoadSound(string path, string name, Action callback = null, bool isPlay = true, PlayUnit unit = null) { string url = "file://" + path; //Debug.Log(url); WWW www = new WWW(url); yield return(www); var clip = www.GetAudioClip(); clip.name = name; //Debug.Log("音频名称:" + clip.name); if (!clips.ContainsKey(clip.name)) { clips.Add(clip.name, clip); } StartCoroutine(PlayCallBack(clip, callback, isPlay, unit)); }
IEnumerator PlayCallBack(AudioClip clip, Action callback = null, bool isPlay = true, PlayUnit unit = null) { if (isPlay) { source.clip = clip; source.Play(); } yield return(new WaitForSeconds(clip.length)); if (callback != null) { callback(); } if (unit != null) { unit.IsDone = true; } }
/// <summary>向队列中塞入要播放的音频</summary> /// <param name="unit">要播放的音频</param> public void SetUnits(PlayUnit unit) { queUnits.Enqueue(unit); }