public bool PlaySE(string seName, float volume) { if (audioClips.ContainsKey(seName) == false) { return(false); } AudioClipInfo info = audioClips[seName]; //なければロード if (info.clip == null) { info.clip = (AudioClip)Resources.Load(info.resourceName); } if (soundPlayerObj == null) { soundPlayerObj = new GameObject("SoundPlayer"); audioSource = soundPlayerObj.AddComponent <AudioSource>(); } //ボリュームの設定 audioSource.volume = volume; audioSource.loop = false; //再生 audioSource.PlayOneShot(info.clip); return(true); }
public bool playSE(string seName, float volume = 1.0f) { if (seClips.ContainsKey(seName) == false) { reserveSE(seName); //return false; // not register } AudioClipInfo info = seClips[seName]; // Load if (info.clip == null) { info.clip = (AudioClip)Resources.Load(info.resourceName); } if (soundPlayerObj == null) { soundPlayerObj = new GameObject("SoundPlayer"); if (psoundObj) { soundPlayerObj.transform.parent = psoundObj.transform; } audioSource = soundPlayerObj.AddComponent <AudioSource>(); } // Play SE audioSource.PlayOneShot(info.clip, volume * seVolume); return(true); }
/// <summary> /// Play the specified audioClip on specified channel type. This function is meant to be used for single sound occurences. /// Use default level will set the attenuation to its default level. /// </summary> /// <param name="audioClip">Audio clip.</param> /// <param name="clipName">Clip name.</param> /// <param name="channeltype">Channeltype.</param> public void Play(AudioClip audioClip, ChannelType channeltype, AudioClipInfo clipInfo) { GameObject go = new GameObject("GameSound"); go.tag = channeltype.ToString(); go.transform.SetParent(gameObject.transform, false); AudioSource source = go.AddComponent<AudioSource>(); source.playOnAwake = false; source.clip = audioClip; float lvl = 0.0f; ChannelInfo chInfo = null; channelInfos.TryGetValue(channeltype.ToString(), out chInfo); if(chInfo != null) { lvl = clipInfo.useDefaultDBLevel ? chInfo.defaultDBLevel : chInfo.settedDBLevel; } else { Debug.LogError("Channel info not found"); } audioMixer.SetFloat(channeltype.ToString(),lvl); source.outputAudioMixerGroup = chInfo.audioMixerGroup; source.loop = clipInfo.isLoop; source.PlayDelayed(clipInfo.delayAtStart); playingList.Add(go); }
private AudioClipInfo GetSoundClip(string soundName) { if (string.IsNullOrEmpty(soundName)) { return(null); } AudioClipInfo retClip = null; if (mClipInfoMap.TryGetValue(soundName, out retClip)) { return(retClip); } string soundPath = "sound/" + soundName; //AudioClip audioClip = AssetDatabase.LoadAssetAtPath(soundPath, typeof(AudioClip)) as AudioClip; AudioClip audioClip = Resources.Load(soundPath) as AudioClip; if (audioClip != null) { AudioClipInfo clipInfo = new AudioClipInfo(soundName, audioClip); mClipInfoMap.Add(soundName, clipInfo); //Debug.Log(string.Format("<color=green>GetSoundIndex t load sound={0} </color>", soundName)); return(clipInfo); } Debug.Log("Fail to found sound: " + soundPath); return(retClip); }
/// <summary> /// SoundDataを更新 /// </summary> private void UpdateSoundData() { string sourceFolder = _sourceFolder.Replace("Assets/", ""); string[] pathList = Directory.GetFiles(Path.Combine(Application.dataPath, sourceFolder)); List <AudioClipInfo> clipInfoList = new List <AudioClipInfo>(); foreach (var path in pathList) { AudioClip clip = AssetDatabase.LoadAssetAtPath <AudioClip>(path.Remove(0, path.LastIndexOf("Assets"))); if (clip == null) { continue; } var clipInfo = new AudioClipInfo(); clipInfo.clip = clip; clipInfo.key = _audioClipInfoList.Where(x => x.clip == clip).FirstOrDefault()?.key; if (string.IsNullOrEmpty(clipInfo.key)) { clipInfo.key = clip.name.ToUpperSnake(); // キー名が空なら、デフォルトでファイル名を入れておく } clipInfoList.Add(clipInfo); } _audioClipInfoList = clipInfoList; }
//背景音乐 public void PlayMusicBg(string clipname) { mCurMusicName = clipname; if (!Setting.MusicSwitch) { Debug.LogFormat("========PlayMusicBg close========"); ChangeMusicBg("none"); return; } AudioClipInfo clipInfo = GetSoundClip(clipname); if (clipInfo == null) { //Debug.Log(string.Format("<color=red>PlaySound err cant load sound={0}</color>", clipname)); return; } AudioClip clip = clipInfo.Clip; if (clip == null) { //Debug.LogError("PlaySound err sound: " + clipname ); return; } //CurrentAudioSourceBg.Stop(); //Debug.Log(string.Format("<color=green>PlaySound t load sound={0}</color>", clipname)); CurrentAudioSourceBg.clip = clip; CurrentAudioSourceBg.loop = true; CurrentAudioSourceBg.volume = Setting.Volume; CurrentAudioSourceBg.Play(); }
/// <summary> /// 追加したサウンドデータを再生する /// </summary> /// <returns><c>true</c>, 再生の成功 <c>false</c> 再生の失敗 </returns> /// <param name="seName"> SEの名前 </param> /// <param name="volume"> ボリュームの設定 (0f ~ 1.0f) </param> public bool PlaySE(string seName, float volume = 1.0f) { if (audioClips.ContainsKey(seName) == false) { Debug.LogError("<color=red>" seName + "がコンテナの中にありません。パスが間違っているか、呼び出し名が間違っているか確認してください。</color>"); return(false); } AudioClipInfo info = audioClips[seName]; //なければロード if (info.clip == null) { info.clip = (AudioClip)Resources.Load(info.resourceName); } if (soundPlayerObj == null) { soundPlayerObj = new GameObject(audioClips[seName].name); audioSource = soundPlayerObj.AddComponent <AudioSource>(); } //ボリュームの設定 audioSource.volume = volume; audioSource.loop = false; //再生 audioSource.PlayOneShot(info.clip); return(true); }
/// <summary> /// 사운드 재생. /// </summary> /// <param name="audioSource"></param> /// <param name="audioClipInfo"></param> /// <param name="is3DSound"></param> private void PlayAudiosourceSound(AudioSource audioSource, AudioClipInfo audioClipInfo, bool is3DSound = true) { if (audioSource) { if (!SettingManager.Instance.IsOnSound(audioClipInfo.Type)) { SetVolume(audioClipInfo.Type, 0); } if (audioClipInfo.Clip) { audioSource.clip = audioClipInfo.Clip; } if (audioClipInfo.Type == AudioType.BGM) { is3DSound = false; } audioSource = SetAudioSource(audioSource, isVolumeAarry[(int)audioClipInfo.Type] * audioClipInfo.VolumeRate, audioClipInfo.IsLoop, is3DSound); if (audioClipInfo.Type == AudioType.BGM) { audioSource.priority = priorityBGM; } AudioCtrl.Play(audioSource, audioClipInfo.Type); } }
public bool playSE(string seName) { if (audioClips.ContainsKey(seName) == false) { return(false); // not register } AudioClipInfo info = audioClips[seName]; // Load if (info.clip == null) { info.clip = (AudioClip)Resources.Load(info.resourceName); } if (soundPlayerObj == null) { soundPlayerObj = new GameObject("SoundPlayer"); audioSource = soundPlayerObj.AddComponent <AudioSource>(); } // Play SE audioSource.PlayOneShot(info.clip); return(true); }
public bool playSE(string seName) { if (audioClips.ContainsKey(seName) == false) { return(false); // not register } AudioClipInfo info = audioClips[seName]; // Load if (info.clip == null) { info.clip = (AudioClip)Resources.Load(info.resourceName); } if (soundPlayerObj == null) { soundPlayerObj = new GameObject("SoundPlayer"); audioSource = soundPlayerObj.AddComponent <AudioSource>(); //audioSource.volume = 0.5f; GameObject camera = GameObject.Find("Main Camera"); soundPlayerObj.transform.position = camera.transform.position; soundPlayerObj.transform.parent = camera.transform; } // Play SE audioSource.PlayOneShot(info.clip); return(true); }
void PauseLoopingClip(AudioClipInfo info) { if (loopingAudioInfo.ContainsKey(info.clip.name) && loopingAudioInfo[info.clip.name] != null) { loopingAudioInfo[info.clip.name].Pause(); } }
/// <summary> /// Plays the given sound /// Waits until the sound is done playing /// Stops the sound and adds it back to the resource pool /// If the sound is set to loop then it won't add it back to the queue /// until it is done looping /// </summary> /// <param name="soundName"></param> /// <returns></returns> IEnumerator PlaySoundRoutine(AudioName soundName, SoundClip clip) { AudioClipInfo info = m_aduioDictionary[soundName]; clip.Info = info; clip.Volume = m_sfxVolume; clip.Play(); // Will keep checking until the sound no longer plays if (clip.Loops) { // Check again next frame to see if we are done while (clip.IsPlaying) { yield return(new WaitForEndOfFrame()); } } else { // Wait until the sound is done playing to re-queue it yield return(new WaitForSeconds(clip.Length)); } // For safety ensure the sound is stopped clip.Stop(); clip.Info = null; m_soundClips.Enqueue(clip); }
public void PlayAudio(AudioClipInfo clip) { var source = GetComponent <AudioSource>(); if (source != null) { source.Play(clip); } }
private void Init() { _audioSource = GetComponent <AudioSource>(); _audioClipInfo = SoundManager.Instance.GetAudioClipInfo(_audioKey); _audioSource.volume = 0f; _audioSource.playOnAwake = false; volumeRate = _audioClipInfo.VolumeRate; curVolumeRate = volumeRate; }
//------------------------------------------------------------------------------------------------ public void loopAtPosition(string name, Transform transform) { AudioClipInfo clipInfo = new AudioClipInfo(); clipInfo.clip = getAudioClip(name); clipInfo.duration = clipInfo.clip.length; clipInfo.index = 0; clipInfo.transform = transform; loopingClips.Add(name, clipInfo); }
public void PlayUISoundInstance(string key) { AudioClipInfo audioClipInfo = GetAudioClipInfo(key); if (IsValidAudioClipInfo(audioClipInfo)) { GameObject fxObject = new GameObject(audioClipInfo.Clip.name); SoundManager.Instance.PlayUISound(fxObject, key); Destroy(fxObject, audioClipInfo.Clip.length + 0.1f); } }
public void PlaySoundInstance(string key, Vector3 point) { AudioClipInfo audioClipInfo = GetAudioClipInfo(key); if (audioClipInfo != null && audioClipInfo.Clip != null) { GameObject fxObject = new GameObject(audioClipInfo.Clip.name); fxObject.transform.position = point; SoundManager.Instance.PlaySound(fxObject, key); Destroy(fxObject, audioClipInfo.Clip.length + 0.1f); } }
/// <summary> /// 오디오클립 새로 로드. /// </summary> /// <param name="clippath"></param> public void Load(string clippath) { if(!m_audioClipDict.ContainsKey(clippath)) // 이미 로드되지 않은 경우만 작동 { var info = new AudioClipInfo(); info.clip = Resources.Load(clippath) as AudioClip; info.path = clippath; info.refcount = 0; m_audioClipDict[clippath] = info; } }
/// <summary> /// Plays the given clip as a 3D sound by making the sound originate from the given position /// If audio is set to loop it will only stop when either: /// <see cref="PauseSounds"/> or <see cref="StopAll"/> are called /// or when you stop it through the returned AudioSource /// </summary> /// <param name="clipName"></param> /// <param name="position"></param> /// <param name="settings"></param> /// <returns></returns> public AudioSource PlaySoundAt(AudioClipName clipName, Vector3 position) { AudioClipInfo info = GetClipInfo(clipName); AudioClip clip = info.Clip; SingleShotAudio fx = CreateNewSoundSource(); info.Settings.volume = SoundFxVolume; fx.PlaySoundAt(clip, position, info.Settings); AudioSource source = fx.Source; return(source); }
public bool AddData(string key, AudioClipInfo audioClipInfo) { if (GetAudioClipInfo(key) != null) { return(false); } else { _audioDataInfoList.Add(new AudioDataInfo(key, audioClipInfo)); return(true); } }
/// <summary> /// Fade the screen in /// Attaches the battery to the current player controlled robot to grant player control /// </summary> /// <returns></returns> IEnumerator LevelStartRoutine() { // Begin the fade AudioClipInfo clipInfo = AudioManager.Instance.GetClipInfo(AudioClipName.RobotPoweredOn); SceneFader.Instance.FadeIn(clipInfo.Clip.length); // Wait for the fade to finish yield return(new WaitForSeconds(clipInfo.Clip.length)); PlayerController.Instance.LevelLoaded(); }
/// <summary> /// 오디오클립 새로 로드. /// </summary> /// <param name="clippath"></param> public void Load(string clippath) { if (!m_audioClipDict.ContainsKey(clippath)) // 이미 로드되지 않은 경우만 작동 { var info = new AudioClipInfo(); info.clip = Resources.Load(clippath) as AudioClip; info.path = clippath; info.refcount = 0; m_audioClipDict[clippath] = info; } }
public static AudioClip GetAudioClip(string name) { AudioClipInfo audioClipInfo = instance.audioClipInfos.Find( aci => aci.name == name ); if (audioClipInfo != null) { return(audioClipInfo.clip); } return(null); }
public static void AudioClipInfo(string name, AudioClipInfo clip) { EditorGUILayout.BeginVertical(EditorStyles.boxStyle); ObjectPickerUtility.RenderObjectPickerForType(name, clip.audioClip, typeof(AudioClip), val => { clip.audioClip = (AudioClip)val; }); clip.volume = EditorGUILayout.FloatField("Volume", clip.volume); clip.pitch = EditorGUILayout.FloatField("Pitch", clip.pitch); clip.loop = EditorGUILayout.Toggle("Loop", clip.loop); EditorGUILayout.EndVertical(); }
/// <summary> /// Returns the AudipClipInfo assocaited with the given clip name /// </summary> /// <param name="clipName"></param> /// <returns></returns> public AudioClipInfo GetClipInfo(AudioClipName clipName) { AudioClipInfo info = m_clipMapping.ContainsKey(clipName) ? m_clipMapping[clipName] : null; if (info == null) { Debug.LogError($"Clip: '{clipName.ToString()}' has not been assigned in the clips library"); } else if (info.Clip == null) { Debug.LogError($"'{clipName.ToString()}' has no AudioClip assigned to it"); } return(info); }
/// <summary> /// Plays the given clip as 2D sound which means it will be heard equally from all speakers /// If audio is set to loop it will only stop when either: /// <see cref="PauseSounds"/> or <see cref="StopAll"/> are called /// or when you stop it through the returned AudioSource /// </summary> /// <param name="clipName">The name of the clip to play</param> /// <param name="volume">Modify the default volume of the clip</param> /// <param name="pitch">Modify the pitch of the sound</param> /// <returns></returns> public AudioSource Play2DSound(AudioClipName clipName, float volume = 1f, float pitch = 1f) { AudioClipInfo info = GetClipInfo(clipName); AudioSourceSettings settings = info.Settings; // Override settings settings.volume = volume * SoundFxVolume; settings.pitch = pitch; SingleShotAudio fx = CreateNewSoundSource(); fx.Play2DSound(info.Clip, settings); return(fx.Source); }
public void ShowQueLan() { this.prompt.gameObject.SetActive(true); this.prompt.enabled = true; this.prompt.text = "魔法值不足"; if (this.mpNotEnoughClipInfo.clipName != "sd_int_close") { this.mpNotEnoughClipInfo = default(AudioClipInfo); this.mpNotEnoughClipInfo.clipName = "sd_int_close"; this.mpNotEnoughClipInfo.audioSourceType = eAudioSourceType.UI; this.mpNotEnoughClipInfo.audioPriority = 128; this.mpNotEnoughClipInfo.volume = 1f; } AudioMgr.Play(this.mpNotEnoughClipInfo, null); base.StartCoroutine(this.DelayHide()); }
protected virtual void NotifyCraftStart(CraftInfo craftInfo) { AudioClipInfo clip = craftInfo.category.craftingAudioClip; // if (craftInfo.blueprint.overrideCategoryAudioClips) // { // clip = craftInfo.blueprint.craftingAudioClip; // } activeCraft.PlayAudioSource(clip); if (OnCraftStart != null) { OnCraftStart(craftInfo); } }
protected virtual void NotifyCraftSuccess(CraftInfo craftInfo) { InventoryManager.langDatabase.craftedItem.Show(craftInfo.blueprint.name, craftInfo.blueprint.description); AudioClipInfo clip = craftInfo.category.successAudioClip; // if (craftInfo.blueprint.overrideCategoryAudioClips) // { // clip = craftInfo.blueprint.successAudioClip; // } activeCraft.PlayAudioSource(clip); if (OnCraftSuccess != null) { OnCraftSuccess(craftInfo); } }
protected virtual void NotifyCraftCanceled(CraftInfo craftInfo, float progress) { InventoryManager.langDatabase.craftingCanceled.Show(craftInfo.blueprint.name, craftInfo.blueprint.description, progress); AudioClipInfo clip = craftInfo.category.canceledAudioClip; // if (craftInfo.blueprint.overrideCategoryAudioClips) // { // clip = craftInfo.blueprint.canceledAudioClip; // } activeCraft.PlayAudioSource(clip); if (OnCraftCancelled != null) { OnCraftCancelled(craftInfo, currentCraftProgress); } }
public void PlayAudioSource(AudioClipInfo clip) { if (clip != null) { if (audioSource == null) { Debug.LogWarning("Can't play crafting audio clip because there is no audio source attached to the trigger."); } else { audioSource.clip = clip.audioClip; audioSource.volume = clip.volume; audioSource.pitch = clip.pitch; audioSource.loop = clip.loop; audioSource.Play(); } } }
/// <summary> /// audioSource & AudioClipInfo. /// </summary> /// <param name="audioSource"></param> /// <param name="audioClipInfo"></param> public void PlaySound(AudioSource audioSource, string key, bool is3D) { if (audioSource) { AudioClipInfo audioClipInfo = GetAudioClipInfo(key); //Ignore BGM Type - New AudioSource if (audioSource.isPlaying && audioClipInfo.Type == AudioType.FX) { PlaySoundCreateSource(audioSource.gameObject, key, is3D); } else { if (IsValidAudioClipInfo(audioClipInfo)) { PlayAudiosourceSound(audioSource, audioClipInfo, is3D); } } } }
public AudioClip LoadAudioClip(string resourcePath) { resourcePath = prefix + resourcePath; for(int a = 0; a<audioClipInfos.Count; a++) { AudioClipInfo clipInfo = audioClipInfos[a]; if(clipInfo.resourcePath == resourcePath) { //make sure this clip is at the top of the stack now audioClipInfos.RemoveAt(a); audioClipInfos.Add(clipInfo); return clipInfo.clip; } } AudioClip audioClip = Resources.Load(resourcePath) as AudioClip; if(audioClip == null) { TODebug.Log("MusicManager couldn't find music at: " + resourcePath); return null; //can't play the sound because we can't find it! } AudioClipInfo newClipInfo = new AudioClipInfo(); newClipInfo.clip = audioClip; newClipInfo.resourcePath = resourcePath; audioClipInfos.Add(newClipInfo); while(audioClipInfos.Count > NUM_CLIPS_TO_CACHE) { AudioClipInfo clipInfoToRemove = audioClipInfos[0]; Resources.UnloadAsset(clipInfoToRemove.clip); audioClipInfos.RemoveAt(0); } return newClipInfo.clip; }
/// <summary> /// Play the specified clip inside specified folder on given channel type. This is meant to be used for sounds played often as the clips created are saved into a dictionary. /// Clip name must be unique. Use default level will set the attenuation to its default level. /// </summary> /// <param name="folderPath">Folder path.</param> /// <param name="clipname">Clipname.</param> /// <param name="channeltype">Channeltype.</param> public void Play(string folderPath, string clipname, ChannelType channeltype, AudioClipInfo clipInfo) { AudioClip clip = null; GameObject go = new GameObject("GameSound"); go.transform.SetParent(gameObject.transform, false); AudioSource source = go.AddComponent<AudioSource>(); source.playOnAwake = false; if(playedSounds.ContainsKey(clipname)) { playedSounds.TryGetValue(clipname, out clip); } else { clip = Resources.Load(folderPath + "/" + clipname) as AudioClip; playedSounds.Add(clipname,clip); } float lvl = 0.0f; ChannelInfo chInfo = null; channelInfos.TryGetValue(channeltype.ToString(), out chInfo); if(chInfo != null) { lvl = clipInfo.useDefaultDBLevel ? chInfo.defaultDBLevel : chInfo.settedDBLevel; } else { Debug.LogError("Channelinfo not found"); } audioMixer.SetFloat(channeltype.ToString(),lvl); source.outputAudioMixerGroup = chInfo.audioMixerGroup; source.loop = clipInfo.isLoop; source.PlayDelayed(clipInfo.delayAtStart); playingList.Add(go); }
public BGMPlayer(AudioClipInfo info) { AudioSource.clip = info.Clip; State = new Wait(this); Info = info; }
public void play(AudioClipInfo info, float volume) { //Debug.Log("Vol: "+volume); AudioSource.PlayOneShot(info.Clip,volume); }