public AudioController Create(Vector3 position, int clipId, Transform parent = null, bool isPlay = true, bool isDelete = true) { if (clipId <= 0) { return(null); } SESoundBuff buff = SESoundBuff.GetSESoundData(clipId); if (buff == null) { Debug.LogError("Can't find sound : " + clipId); return(null); } AudioController au = AudioController.GetAudio(buff, position, parent ? parent : transform, isPlay, isDelete); au.DestroyEvent += OnDelete; m_allAudios.Add(au); return(au); }
IEnumerator IdleAudio(int[] sounds, float distance) { List <int> _tmpSounds = new List <int>(); while (sounds != null && sounds.Length > 0) { yield return(new WaitForSeconds(Random.Range(20f, 35f))); _tmpSounds.Clear(); PeEntity player = PeCreature.Instance.mainPlayer; if (player != null && m_Animator != null) { float sqrDis = PETools.PEUtil.SqrMagnitude(player.position, Entity.position); if (sqrDis > distance * distance) { if (Random.value < 0.2f) { for (int i = 0; i < sounds.Length; i++) { SESoundBuff buff = SESoundBuff.GetSESoundData(sounds[i]); if (buff != null && sqrDis < buff.mMaxDistance * buff.mMaxDistance * 0.81f) { _tmpSounds.Add(sounds[i]); } } if (_tmpSounds.Count > 0) { int soundID = _tmpSounds[Random.Range(0, _tmpSounds.Count)]; AudioManager.instance.Create(Entity.position, soundID); } } } } } }