/// <summary> /// 加载内部资源 /// </summary> public override void LoadResource() { if (m_FileName.Length == 0) { this.Destroy(); CommonObjectPools.Despawn(this); return; } Object res = ResourceLoaderManager.Instance.GetResource(m_FileName); if (res == null) { ResourceManager.Instance.AddAsync(m_FileName, eResType.SOUND, delegate(sResLoadResult info) { if (!m_Active) { this.Destroy(); CommonObjectPools.Despawn(this); return; } OnLoadComplete(); } ); } else { OnLoadComplete(); } }
/**统一创建接口,不要使用默认的构造函数实现*/ static public DropPhysxObj Create() { DropPhysxObj obj = CommonObjectPools.Spawn <DropPhysxObj>(); obj.Init(); return(obj); }
public void RemoveBGSound(BackgroundSound sound) { if (sound != null) { sound.Stop(); sound.Destroy(); CommonObjectPools.Despawn(sound); m_ListBGAudio.Remove(sound); } }
/**统一销毁接口*/ static public void Destroy(DropPhysxObj obj) { if (obj == null) { return; } obj.Release(); CommonObjectPools.Despawn(obj); }
public void StopSoundEffect(SoundBase sound) { if (sound == null) { return; } sound.Stop(); sound.Destroy(); CommonObjectPools.Despawn(sound); }
public void ClearBGSound() { for (int i = 0; i < m_ListBGAudio.Count; ++i) { SoundBase sound = m_ListBGAudio[i]; sound.Stop(); sound.Destroy(); CommonObjectPools.Despawn(sound); } m_ListBGAudio.Clear(); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~其他~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /// <summary> /// 忽视距离声音 /// </summary> public SoundBase PlayIgnoreListenerSound(string fileName, int count = 1) { if (IsCloseEffectSound || fileName.Length == 0) { return(null); } EffectSound sound = CommonObjectPools.Spawn <EffectSound>(); sound.Setup(fileName, Vector3.zero, GetDefaultListener().transform, 0, 500, count); sound.LoadResource(); return(sound); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~音效~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /// <summary> /// 音效 /// </summary> /// <param name="fileName">资源文件</param> /// <param name="pos">播放位置</param> /// <param name="loop">是否循环:如果是循环音效,需要手动清理(AudioSourcePools.instance.DespawnAudio)</param> /// <returns></returns> public SoundBase PlaySoundEffect(string fileName, Vector3 pos, float min_distance, float max_distance, int count = 1) { if (IsCloseEffectSound || fileName.Length == 0) { return(null); } EffectSound sound = CommonObjectPools.Spawn <EffectSound>(); sound.Setup(fileName, pos, null, min_distance, max_distance, count); sound.LoadResource(); return(sound); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~背景声音~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /**背景声音*/ public BackgroundSound PlayBGSound(string fileName, bool loop) { if (m_IsCloseBGSound) { return(null); } if (string.IsNullOrEmpty(fileName)) { return(null); } BackgroundSound sound = CommonObjectPools.Spawn <BackgroundSound>(); sound.Setup(fileName, Vector3.zero, null, 0, 0, loop ? int.MaxValue : 1); sound.LoadResource(); m_ListBGAudio.Add(sound); return(sound); }
public override void OnLoadComplete() { AudioSource aSrc = AudioSourcePools.instance.SpawnByFile(m_FileName, m_Position, m_ParentNode); if (aSrc != null && aSrc.clip != null) { aSrc.pitch = 1; aSrc.volume = SoundManager.Instance.EffectSoundVolume; aSrc.loop = m_PlayCount > 1 ? true : false; aSrc.minDistance = m_MinDistance; aSrc.maxDistance = m_MaxDistance; if (m_IsPlay) { aSrc.Play(); } else { aSrc.Stop(); } AutoDestroyAudio component = aSrc.gameObject.GetComponent <AutoDestroyAudio>(); if (component == null) { component = aSrc.gameObject.AddComponent <AutoDestroyAudio>(); } component.PlayCount = m_PlayCount; component.DestroyCallback = OnComponentDestroy; m_SoundSource = aSrc; } else { this.Destroy(); CommonObjectPools.Despawn(this); return; } }
/// <summary> /// 组件自动销毁回调 /// </summary> private void OnComponentDestroy() { m_Active = false; this.Destroy(); CommonObjectPools.Despawn(this); }