public PlaySoundInfo(int serialId, SoundGroup soundGroup, PlaySoundParams playSoundParams, object userData) { m_SerialId = serialId; m_SoundGroup = soundGroup; m_PlaySoundParams = playSoundParams; m_UserData = userData; }
public PlaySoundInfo() { m_SerialId = 0; m_SoundGroup = null; m_PlaySoundParams = null; m_UserData = null; }
public void Clear() { m_SerialId = 0; m_SoundGroup = null; m_PlaySoundParams = null; m_UserData = null; }
public static int?PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null) { soundComponent.StopMusic(); IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>(); if (dtMusic == null) { Log.Warning("Music data is null", musicId.ToString()); return(null); } DRMusic drMusic = dtMusic.GetDataRow(musicId); if (drMusic == null) { Log.Warning("Can not load music '{0}' from data table.", musicId.ToString()); return(null); } PlaySoundParams playSoundParams = new PlaySoundParams { Priority = 64, Loop = true, VolumeInSoundGroup = 1f, FadeInSeconds = FadeVolumeDuration, SpatialBlend = 0f, }; s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", playSoundParams, null, userData); return(s_MusicSerialId); }
/// <summary> /// 创建播放声音参数。 /// </summary> /// <returns>创建的播放声音参数。</returns> public static PlaySoundParams Create() { PlaySoundParams playSoundParams = ReferencePool.Acquire <PlaySoundParams>(); playSoundParams.m_Referenced = true; return(playSoundParams); }
void LoadSoundAssetSuccess(string path, object[] userdata, AudioClip audioAsset, OnAssetDestory onDestory) { int soundId = (int)userdata[0]; SoundTableSetting soundTable = (SoundTableSetting)userdata[1]; SoundGroup soundGroup = dicSoundGroups[soundTable.Group]; PlaySoundParams soundParams = new PlaySoundParams(); soundParams.Time = soundTable.Time; soundParams.MuteInSoundGroup = Constant.DefaultMute; soundParams.Loop = soundTable.Loop; soundParams.Priority = soundTable.Priority; soundParams.VolumeInSoundGroup = Constant.DefaultVolume; soundParams.FadeInSeconds = soundTable.FadeInSeconds; soundParams.FadeOutSeconds = soundTable.FadeOutSeconds; soundParams.Pitch = soundTable.Pitch; soundParams.PanStereo = soundTable.PanStereo; soundParams.SpatialBlend = soundTable.SpatialBlend; soundParams.MaxDistance = soundTable.MaxDistance; PlaySoundErrorCode?errCode; soundGroup.PlaySound(soundId, audioAsset, soundParams, onDestory, out errCode); if (errCode != null) { Debug.LogError(soundId + " PlaySoundErrorCode=>" + errCode.ToString()); } }
public static PlaySoundInfo Create(PlaySoundParams playSoundParams, bool isShort) { PlaySoundInfo playSoundInfo = ReferencePool.Acquire <PlaySoundInfo>(); playSoundInfo.PlaySoundParams = playSoundParams; playSoundInfo.IsShort = isShort; return(playSoundInfo); }
/// <summary> /// 初始化播放声音更新事件的新实例。 /// </summary> /// <param name="serialId">声音的序列编号。</param> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="progress">加载声音进度。</param> /// <param name="userData">用户自定义数据。</param> public PlaySoundUpdateEventArgs(int serialId, string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams, float progress, object userData) { SerialId = serialId; SoundAssetName = soundAssetName; SoundGroupName = soundGroupName; PlaySoundParams = playSoundParams; Progress = progress; UserData = userData; }
/// <summary> /// 创建播放声音参数。 /// </summary> /// <returns>创建的播放声音参数。</returns> public static PlaySoundParams Create() { PlaySoundParams playSoundParams = new PlaySoundParams(); playSoundParams.Mute = false; playSoundParams.Loop = false; playSoundParams.Volume = 1; return(playSoundParams); }
/// <summary> /// 初始化播放声音失败事件的新实例。 /// </summary> /// <param name="serialId">声音的序列编号。</param> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="errorCode">错误码。</param> /// <param name="errorMessage">错误信息。</param> /// <param name="userData">用户自定义数据。</param> public PlaySoundFailureEventArgs(int serialId, string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams, PlaySoundErrorCode errorCode, string errorMessage, object userData) { SerialId = serialId; SoundAssetName = soundAssetName; SoundGroupName = soundGroupName; PlaySoundParams = playSoundParams; ErrorCode = errorCode; ErrorMessage = errorMessage; UserData = userData; }
public static PlaySoundInfo Create(int serialId, SoundGroup soundGroup, PlaySoundParams playSoundParams, object userData) { PlaySoundInfo playSoundInfo = ReferencePool.Acquire <PlaySoundInfo>(); playSoundInfo.m_SerialId = serialId; playSoundInfo.m_SoundGroup = soundGroup; playSoundInfo.m_PlaySoundParams = playSoundParams; playSoundInfo.m_UserData = userData; return(playSoundInfo); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="serialId">声音的序列编号。</param> /// <param name="soundAsset">声音资源。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="onDestory">销毁资源的操作</param> /// <param name="errorCode">错误码。</param> /// <returns>用于播放的声音代理。</returns> public ISoundAgent PlaySound(int serialId, object soundAsset, PlaySoundParams playSoundParams, OnAssetDestory onDestory, out PlaySoundErrorCode?errorCode) { errorCode = null; SoundAgent candidateAgent = null; foreach (SoundAgent soundAgent in m_SoundAgents) { if (!soundAgent.IsPlaying) { candidateAgent = soundAgent; break; } if (soundAgent.Priority < playSoundParams.Priority) { if (candidateAgent == null || soundAgent.Priority < candidateAgent.Priority) { candidateAgent = soundAgent; } } else if (!m_AvoidBeingReplacedBySamePriority && soundAgent.Priority == playSoundParams.Priority) { if (candidateAgent == null || soundAgent.SetSoundAssetTime < candidateAgent.SetSoundAssetTime) { candidateAgent = soundAgent; } } } if (candidateAgent == null) { errorCode = PlaySoundErrorCode.IgnoredDueToLowPriority; return(null); } if (!candidateAgent.SetSoundAsset(soundAsset, onDestory)) { errorCode = PlaySoundErrorCode.SetSoundAssetFailure; return(null); } candidateAgent.SerialId = serialId; candidateAgent.Time = playSoundParams.Time; candidateAgent.MuteInSoundGroup = playSoundParams.MuteInSoundGroup; candidateAgent.Loop = playSoundParams.Loop; candidateAgent.Priority = playSoundParams.Priority; candidateAgent.VolumeInSoundGroup = playSoundParams.VolumeInSoundGroup; candidateAgent.Pitch = playSoundParams.Pitch; candidateAgent.PanStereo = playSoundParams.PanStereo; candidateAgent.SpatialBlend = playSoundParams.SpatialBlend; candidateAgent.MaxDistance = playSoundParams.MaxDistance; candidateAgent.Play(playSoundParams.FadeInSeconds); return(candidateAgent); }
/// <summary> /// 初始化播放声音时加载依赖资源事件的新实例。 /// </summary> /// <param name="serialId">声音的序列编号。</param> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="dependencyAssetName">被加载的依赖资源名称。</param> /// <param name="loadedCount">当前已加载依赖资源数量。</param> /// <param name="totalCount">总共加载依赖资源数量。</param> /// <param name="userData">用户自定义数据。</param> public PlaySoundDependencyAssetEventArgs(int serialId, string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams, string dependencyAssetName, int loadedCount, int totalCount, object userData) { SerialId = serialId; SoundAssetName = soundAssetName; SoundGroupName = soundGroupName; PlaySoundParams = playSoundParams; DependencyAssetName = dependencyAssetName; LoadedCount = loadedCount; TotalCount = totalCount; UserData = userData; }
public int PlaySound(string assetName) { PlaySoundParams playSoundParams = new PlaySoundParams(); playSoundParams.Priority = 0; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = 1; playSoundParams.SpatialBlend = 0f; return(GameEntry.Sound.PlaySound(AssetUtility.GetUISoundAsset(assetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams)); }
/// <summary> /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. /// </summary> /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param> public void Play(float?pitch, float maxVolume, PlaySoundParams playParams = null) { SoundFinished = null; // clear it out so subscribers don't have to clean up isWaitingForDelay = false; playSndParams = playParams; // compute pitch if (pitch.HasValue) { _audio.pitch = pitch.Value; } else if (useRandomPitch) { var randPitch = UnityEngine.Random.Range(randomPitchMin, randomPitchMax); switch (randomPitchMode) { case RandomPitchMode.AddToClipPitch: randPitch += OriginalPitch; break; } _audio.pitch = randPitch; } else // non random pitch { audio.pitch = OriginalPitch; } // set fade mode this.curFadeMode = FadeMode.None; curDetectEndMode = DetectEndMode.DetectEnd; StopAllCoroutines(); if (audLocation == MasterAudio.AudioLocation.Clip) { FinishSetupToPlay(); return; } _maxVol = maxVolume; AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName, this); if (audLocation == MasterAudio.AudioLocation.ResourceFile) { FinishSetupToPlay(); } }
public static int?PlayUISound(this SoundComponent soundComponent, string soundAssetName, object userData = null) { //IDataTable<DRUISound> dtUISound = GameEntry.DataTable.GetDataTable<DRUISound>(); //DRUISound drUISound = dtUISound.GetDataRow(uiSoundId); //if (drUISound == null) { // Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString()); // return null; //} PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = 0; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = 1; playSoundParams.SpatialBlend = 0f; return(soundComponent.PlaySound(AssetUtility.GetUISoundAsset(soundAssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData)); }
/// <summary> /// 播放界面音效 /// </summary> /// <param name="soundComponent"></param> /// <param name="soundId"></param> /// <param name="userData"></param> public static void PlayUISound(this SoundComponent soundComponent, int soundId, object userData) { //TODO:通过id从音效配置中找到对应的资源,播放 string assetName = "TestUISound"; PlaySoundParams playSoundParams = new PlaySoundParams { //这些参数,可以填在音效配置中 Priority = 0, Loop = true, VolumeInSoundGroup = 1f, FadeInSeconds = FadeVolumeDuration, SpatialBlend = 0f, }; soundComponent.PlaySound(AssetUtility.GetUISoundAsset(assetName), "UISound", playSoundParams.Priority, playSoundParams, userData); }
public static int?PlaySound(this SoundComponent soundComponent, string assetName, StarForce.Entity bindingEntity = null, object userData = null) { //IDataTable<DRSound> dtSound = GameEntry.DataTable.GetDataTable<DRSound>(); //DRSound drSound = dtSound.GetDataRow(soundId); //if (drSound == null) { // Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString()); // return null; //} PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = 0; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = 1; playSoundParams.SpatialBlend = 1; return(soundComponent.PlaySound(AssetUtility.GetSoundAsset(assetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData)); }
public static int?PlaySound(this SoundComponent soundComponent, int soundId, Entity bindingEntity = null, object userData = null) { IDataTable <DRSound> dtSound = GameEntry.DataTable.GetDataTable <DRSound>(); DRSound drSound = dtSound.GetDataRow(soundId); if (drSound == null) { Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString()); return(null); } PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = drSound.Priority; playSoundParams.Loop = drSound.Loop; playSoundParams.VolumeInSoundGroup = drSound.Volume; playSoundParams.SpatialBlend = drSound.SpatialBlend; return(soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, bindingEntity != null ? bindingEntity.Entity : null, userData)); }
public int PlayUISound(int uiSoundId, object userData = null) { DataTableComponent dataTableComponent = UnityGameFramework.Runtime.GameEntry.GetComponent <DataTableComponent>(); IDataTable <DRUISound> dtUISound = dataTableComponent.GetDataTable <DRUISound>(); DRUISound drUISound = dtUISound.GetDataRow(uiSoundId); if (drUISound == null) { Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString()); return(-1); } PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = drUISound.Priority; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = drUISound.Volume; playSoundParams.SpatialBlend = 0f; return(soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Demo15.Constant.AssetPriority.UISoundAsset, playSoundParams, userData)); }
public static int?PlaySound(this SoundComponent soundComponent, int soundId, Entity bindingEntity = null, object userData = null) { SoundData soundData = GameEntry.Data.GetData <DataSound>().GetSoundDataBySoundId(soundId); PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Time = soundData.SoundPlayParam.Time; playSoundParams.MuteInSoundGroup = soundData.SoundPlayParam.Mute; playSoundParams.Loop = soundData.SoundPlayParam.Loop; playSoundParams.Priority = soundData.SoundPlayParam.Priority; playSoundParams.VolumeInSoundGroup = soundData.SoundPlayParam.Volume; playSoundParams.FadeInSeconds = soundData.SoundPlayParam.FadeInSeconds; playSoundParams.Pitch = soundData.SoundPlayParam.Pitch; playSoundParams.PanStereo = soundData.SoundPlayParam.PanStereo; playSoundParams.SpatialBlend = soundData.SoundPlayParam.SpatialBlend; playSoundParams.MaxDistance = soundData.SoundPlayParam.MaxDistance; playSoundParams.DopplerLevel = soundData.SoundPlayParam.DopplerLevel; return(soundComponent.PlaySound(soundData.AssetPath, soundData.SoundGroupData.Name, Constant.AssetPriority.MusicAsset, playSoundParams, bindingEntity, userData)); }
public static int?PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null) { var dtUISound = GameEntry.DataTable.GetDataTable <DRUISound>(); var drUISound = dtUISound.GetDataRow(uiSoundId); if (drUISound == null) { Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString()); return(null); } PlaySoundParams playSoundParams = new PlaySoundParams(); playSoundParams.Priority = drUISound.Priority; playSoundParams.Loop = false; playSoundParams.VolumeInSoundGroup = drUISound.Volume; playSoundParams.SpatialBlend = 0f; return(soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", Constant.AssetPriority.UISoundAsset, playSoundParams, userData)); }
public static int PlayMusic(this SoundComponent soundComponent, int musicId, object userData = null) { IDataTable <DRMusic> dtMusic = GameEntry.DataTable.GetDataTable <DRMusic>(); DRMusic drMusic = dtMusic.GetDataRow(musicId); if (drMusic == null) { Log.Warning("Can not load music '{0}' from data table.", musicId.ToString()); return(-1); } PlaySoundParams playSoundParams = new PlaySoundParams { Priority = 64, Loop = true, VolumeInSoundGroup = 1f, SpatialBlend = 0f, }; return(soundComponent.PlaySound(AssetUtility.GetMusicAsset(drMusic.AssetName), "Music", playSoundParams, null, userData)); }
public static int PlayUISound(this SoundComponent soundComponent, int uiSoundId, object userData = null) { IDataTable <DRUISound> dtUISound = GameEntry.DataTable.GetDataTable <DRUISound>(); DRUISound drUISound = dtUISound.GetDataRow(uiSoundId); if (drUISound == null) { Log.Warning("Can not load UI sound '{0}' from data table.", uiSoundId.ToString()); return(-1); } PlaySoundParams playSoundParams = new PlaySoundParams { Priority = drUISound.Priority, Loop = false, VolumeInSoundGroup = drUISound.Volume, SpatialBlend = 0f, }; return(soundComponent.PlaySound(AssetUtility.GetUISoundAsset(drUISound.AssetName), "UISound", playSoundParams, userData)); }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> public void Stop(bool stopEndDetection = false) { if (stopEndDetection || isWaitingForDelay) { curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat } objectToFollow = null; objectToTriggerFrom = null; ParentGroup.RemoveActiveAudioSourceId(this); _audio.Stop(); playSndParams = null; if (SoundFinished != null) { SoundFinished(); // parameters aren't used } MaybeUnloadClip(); }
/// <summary> /// 返回音频长度 /// </summary> /// <param name="soundComponent"></param> /// <param name="soundId"></param> /// <returns>返回音频长度</returns> public static int?PlaySoundAndLength(this SoundComponent soundComponent, int soundId, ref int length) { IDataTable <DRSound> dtSound = GameEntry.DataTable.GetDataTable <DRSound>(); DRSound drSound = dtSound.GetDataRow(soundId); if (drSound == null) { Log.Warning("Can not load sound '{0}' from data table.", soundId.ToString()); return(0); } PlaySoundParams playSoundParams = new PlaySoundParams { Priority = drSound.Priority, Loop = drSound.Loop, VolumeInSoundGroup = drSound.Volume, SpatialBlend = drSound.SpatialBlend, }; length = drSound.Length; return(soundComponent.PlaySound(AssetUtility.GetSoundAsset(drSound.AssetName), "Sound", Constant.AssetPriority.SoundAsset, playSoundParams, null, null)); }
public static int?PlayMusic(this SoundComponent soundComponent, string assetName, object userData = null) { soundComponent.StopMusic(); //IDataTable<DRMusic> dtMusic = GameEntry.DataTable.GetDataTable<DRMusic>(); //DRMusic drMusic = dtMusic.GetDataRow(musicId); //if (drMusic == null) //{ // Log.Warning("Can not load music '{0}' from data table.", musicId.ToString()); // return null; //} PlaySoundParams playSoundParams = PlaySoundParams.Create(); playSoundParams.Priority = 64; playSoundParams.Loop = true; playSoundParams.VolumeInSoundGroup = 1f; playSoundParams.FadeInSeconds = FadeVolumeDuration; playSoundParams.SpatialBlend = 0f; s_MusicSerialId = soundComponent.PlaySound(AssetUtility.GetMusicAsset(assetName), "Music", Constant.AssetPriority.MusicAsset, playSoundParams, null, userData); return(s_MusicSerialId); }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> public void Stop(bool stopEndDetection = false) { if (stopEndDetection || isWaitingForDelay) { curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat } objectToFollow = null; objectToTriggerFrom = null; ParentGroup.RemoveActiveAudioSourceId(InstanceId); VarAudio.Stop(); VarAudio.time = 0f; playSndParams = null; if (SoundFinished != null) { SoundFinished(); // parameters aren't used SoundFinished = null; // clear it out so subscribers don't have to clean up } MaybeUnloadClip(); }
/// <summary> /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. /// </summary> /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param> public void Play(float?pitch, float maxVolume, PlaySoundParams playParams = null) { SoundFinished = null; // clear it out so subscribers don't have to clean up isWaitingForDelay = false; playSndParams = playParams; // compute pitch if (pitch.HasValue) { _audio.pitch = pitch.Value; } else { var randPitch = 0f; if (randomPitch != 0f) { randPitch = UnityEngine.Random.Range(-randomPitch, randomPitch); } _audio.pitch = OriginalPitch + randPitch; } // set fade mode this.curFadeMode = FadeMode.None; curDetectEndMode = DetectEndMode.DetectEnd; StopAllCoroutines(); if (audLocation == MasterAudio.AudioLocation.Clip) { FinishSetupToPlay(maxVolume); return; } StartCoroutine(LoadResourceFileAsync(resourceFileName, maxVolume)); }
/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="soundGroupName">声音组名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <param name="bindingEntity">声音绑定的实体。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, string soundGroupName, PlaySoundParams playSoundParams, Entity bindingEntity, object userData) { return(m_SoundManager.PlaySound(soundAssetName, soundGroupName, playSoundParams, new PlaySoundInfo(bindingEntity, userData))); }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> public void Stop(bool stopEndDetection = false) { if (stopEndDetection || isWaitingForDelay) { curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat } objectToFollow = null; objectToTriggerFrom = null; ParentGroup.RemoveActiveAudioSourceId(InstanceId); VarAudio.Stop(); VarAudio.time = 0f; playSndParams = null; if (SoundFinished != null) { SoundFinished(); // parameters aren't used SoundFinished = null; // clear it out so subscribers don't have to clean up } if (_updater != null) { GameObject.Destroy(_updater); _updater = null; } MaybeUnloadClip(); }
/// <summary> /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. /// </summary> /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param> public void Play(float? pitch, float maxVolume, PlaySoundParams playParams = null) { SoundFinished = null; // clear it out so subscribers don't have to clean up isWaitingForDelay = false; playSndParams = playParams; // compute pitch if (pitch.HasValue) { VarAudio.pitch = pitch.Value; } else if (useRandomPitch) { var randPitch = UnityEngine.Random.Range(randomPitchMin, randomPitchMax); switch (randomPitchMode) { case RandomPitchMode.AddToClipPitch: randPitch += OriginalPitch; break; } VarAudio.pitch = randPitch; } else { // non random pitch VarAudio.pitch = OriginalPitch; } // set fade mode this.curFadeMode = FadeMode.None; curDetectEndMode = DetectEndMode.DetectEnd; _maxVol = maxVolume; StopAllCoroutines(); if (audLocation == MasterAudio.AudioLocation.Clip) { FinishSetupToPlay(); return; } AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName, this); if (audLocation == MasterAudio.AudioLocation.ResourceFile) { FinishSetupToPlay(); } }
/// <summary> /// This method is called automatically from MasterAudio.PlaySound and MasterAudio.PlaySound3D. /// </summary> /// <param name="maxVolume">If fade in time is not zero on this Variation, max volume is the fully faded in clip's target volume. Otherwise this is not used.</param> public void Play(float? pitch, float maxVolume, PlaySoundParams playParams = null) { SoundFinished = null; // clear it out so subscribers don't have to clean up isWaitingForDelay = false; playSndParams = playParams; // compute pitch if (pitch.HasValue) { _audio.pitch = pitch.Value; } else { var randPitch = 0f; if (randomPitch != 0f) { randPitch = UnityEngine.Random.Range(-randomPitch, randomPitch); } _audio.pitch = OriginalPitch + randPitch; } // set fade mode this.curFadeMode = FadeMode.None; curDetectEndMode = DetectEndMode.DetectEnd; if (audLocation == MasterAudio.AudioLocation.ResourceFile) { AudioResourceOptimizer.PopulateSourcesWithResourceClip(resourceFileName); } StopAllCoroutines(); timesLocationUpdated = 0; if (!_audio.isPlaying && _audio.time > 0f) { // paused. Do nothing except Play } else if (useFades && (fadeInTime > 0f || fadeOutTime > 0f)) { fadeMaxVolume = maxVolume; _audio.volume = 0f; StartCoroutine(FadeInOut()); } if (playSndParams != null && playSndParams.isChainLoop) { _audio.loop = false; } ParentGroup.AddActiveAudioSourceId(this); StartCoroutine(DetectSoundFinished(playParams.delaySoundTime)); attachToSource = false; bool useClipAgePriority = MasterAudio.Instance.prioritizeOnDistance && (MasterAudio.Instance.useClipAgePriority || ParentGroup.useClipAgePriority); if (playParams.attachToSource || useClipAgePriority) { attachToSource = playParams.attachToSource; StartCoroutine(FollowSoundMaker()); } }
/// <summary> /// This method allows you to stop the audio being played by this Variation. /// </summary> public void Stop(bool stopEndDetection = false) { if (stopEndDetection || isWaitingForDelay) { curDetectEndMode = DetectEndMode.None; // turn off the chain loop endless repeat } ParentGroup.RemoveActiveAudioSourceId(this); _audio.Stop(); playSndParams = null; if (SoundFinished != null) { SoundFinished(); // parameters aren't used } MaybeUnloadClip(); }