public void Play(AudioClipType type, GameObject audioSourceObject = null, float spatialBlend = 0) { try { AudioSource audioSrc = GetAudioSource(audioSourceObject, type); if (audioSrc == null) { Logger.Warning("No AudioSource component was attached, cannot play audio."); return; } if (audioSrc.isPlaying) { return; } AudioClip audioClip = GetAudioClip(type); if (audioClip == null) { Logger.Error("No AudioClip found for type: " + type + " and filename '" + audioClips[type].filename + "'. Wrong filename?"); return; } audioSrc.spatialBlend = spatialBlend; audioSrc.PlayOneShot(audioClip, 1.0f); } catch (Exception e) { Logger.Error("Error with playing audio file of type: " + type + " from source " + audioSourceObject + "\nError message: " + e.Message); } }
public async void PlayAudio(AudioClipType type) { var clipRef = _audioList.First(x => x.Type == type).ClipRef; var audioClip = await AssetsController.LoadAsset <AudioClip>(clipRef); _audioSource.PlayOneShot(audioClip); }
public void PlayAudioClip(AudioClipType type, float volume = -1, bool loop = false, bool clearOther = false) { if (!_audioClips.ContainsKey(type)) { return; } if (volume < 0) { volume = _config.SoundEffectVolume; } if (clearOther) { foreach (var audioSource in _soundEffAudioSources) { DestroyImmediate(audioSource); } } var playSource = _soundEffAudioSources.FirstOrDefault(audioSource => audioSource.isPlaying == false); if (playSource == null) { playSource = gameObject.AddComponent <AudioSource>(); playSource.bypassEffects = true; playSource.bypassListenerEffects = true; playSource.bypassReverbZones = true; _soundEffAudioSources.Add(playSource); } playSource.clip = _audioClips[type]; playSource.volume = volume; playSource.loop = loop; playSource.Play(); }
public FileAudio([NotNull] FileInfo file, AudioClipType type) { _file = file; Type = type; Name = file.Name; }
public void PlayAmibientClip(AudioClipType type, bool loop) { if (type == AudioClipType.None) { audioSource.clip = null; audioSource.Play(); return; } if (!audioSource.loop && audioSource.isPlaying) { return; } AudioClip newClip = GetClipByType(type); if (newClip == audioSource.clip) { return; } audioSource.clip = newClip; audioSource.loop = loop; audioSource.Play(); }
public AsyncFileAudio([NotNull] Task <FileInfo> file, AudioClipType type) { Type = type; Name = "Loading..."; _fileTask = Task.Factory.StartNew(async() => { _file = await file; }); }
private AudioClip GetAudioClip(AudioClipType type) { if (audioClips[type].clip == null) { audioClips[type].clip = Resources.Load <AudioClip>(AUDIO_FILE_LOCATION + audioClips[type].filename); } return(audioClips[type].clip); }
public void SetAudio(AudioClipType index) { if (GameServer.getSingleton().isAudio) { return; } audioSourceOther.clip = allAudioClips[(int)index]; audioSourceOther.Play(); }
public void PlayClip(AudioClipType clipType) { this.audioSource.clip = this.audioClips.FirstOrDefault(ac => ac.clipType == clipType).clip; if (this.audioSource.clip != null) { this.audioSource.Play(); } }
/// <summary> /// Dos the play sound. /// </summary> /// <param name="aClipName">A clip name.</param> public void doPlaySound(AudioClipType aClipName) { //Debug.Log ("playing : " + aClipName); switch (aClipName) { case AudioClipType.BUTTON_CLICK: _audioSource.PlayOneShot(_buttonClick_audioclip); break; case AudioClipType.WAYPOINT_TRIGGERED: _audioSource.PlayOneShot(_waypointTriggered_audioclip); break; case AudioClipType.PLAYER_JUMPS: _audioSource.PlayOneShot(_playerJumps_audioclip); break; case AudioClipType.PLAYER_LANDS: _audioSource.PlayOneShot(_playerLands_audioclip); break; case AudioClipType.PLAYER_KILLS_ENEMY: _audioSource.PlayOneShot(_playerKillsEnemy_audioclip); break; case AudioClipType.PLAYER_FALLS_OFFSCREEN: _audioSource.PlayOneShot(_playerFallsOffscreen_audioclip); break; case AudioClipType.COIN_COLLECTED: _audioSource.PlayOneShot(_coinCollected_audioclip); break; case AudioClipType.ENEMY_KILLS_PLAYER: _audioSource.PlayOneShot(_enemyKillsPlayer_audioclip); break; case AudioClipType.GAME_START: _audioSource.PlayOneShot(_gameStart_audioclip); break; case AudioClipType.GAME_OVER_WIN: _audioSource.PlayOneShot(_gameOverWin_audioclip); break; case AudioClipType.GAME_OVER_LOSS: _audioSource.PlayOneShot(_gameOverLoss_audioclip); break; default: #pragma warning disable 0162 throw new SwitchStatementException(); break; #pragma warning restore 0162 } }
public void PlayOneShot(AudioClipType audioType) { switch (audioType) { case AudioClipType.SwordHitReject: mainEffectAudioSouce.PlayOneShot(swordHitReject); break; } }
protected override void ItemCommandClick(string controlID) { if (controlID == COMMAND_ADD_AUDIO) { string[] selectedFiles = _guiController.ShowOpenFileDialogMultipleFiles("Select audio to add", AUDIO_FILES_FILTER); if (selectedFiles.Length > 0) { ImportAudioFiles(selectedFiles); } } else if (controlID == COMMAND_RENAME) { _guiController.ProjectTree.BeginLabelEdit(this, _rightClickedID); } else if (controlID == COMMAND_DELETE) { AudioClip clipToDelete = _items[_rightClickedID]; if (_guiController.ShowQuestion("Are you sure you want to delete audio '" + clipToDelete.ScriptName + "'?") == System.Windows.Forms.DialogResult.Yes) { DeleteSingleItem(clipToDelete); } } else if (controlID == SPEECH_NODE_ID) { _guiController.ShowMessage("You create voice speech files by placing them in the Speech sub-folder in explorer, and they must have special names corresponding to the line of text that they represent.\n\nPlease look up 'Voice Speech' in the help file for details.", MessageBoxIconType.Information); } else if (controlID == COMMAND_PROPERTIES) { ShowPaneForItem(_rightClickedID); } else if (controlID == COMMAND_NEW_CLIP_TYPE) { CreateNewAudioClipType(); } else if (controlID == COMMAND_RENAME_CLIP_TYPE) { _guiController.ProjectTree.BeginLabelEdit(this, _rightClickedID); } else if (controlID == COMMAND_DELETE_CLIP_TYPE) { AudioClipType typeToDelete = FindAudioClipTypeByNodeID(_rightClickedID, true); DeleteAudioClipType(typeToDelete); } else if (controlID.StartsWith(NODE_ID_PREFIX_CLIP_TYPE)) { ShowPaneForItem(controlID); } else if (controlID == COMMAND_PROPERTIES_CLIP_TYPE) { ShowPaneForItem(_rightClickedID); } else if (controlID != AUDIO_TYPES_FOLDER_NODE_ID) { ShowPaneForItem(controlID); } }
private GameObject GetDefaultAudioSource(AudioClipType type) { GameObject source = GameObject.FindWithTag(audioClips[type].sourceTag); if (source == null) { Logger.Error("Did not find a GameObject tagged with DefaultAudioSource cannot play audio!"); } return(source); }
public bool HasClipPlayedPreviously(AudioClipType clipType) { #if ENABLE_WINMD_SUPPORT var clipName = clipType.ToString(); return(ApplicationData.Current.LocalSettings.Values.ContainsKey(clipName)); #else throw new NotImplementedException(); #endif }
public void StopIfPlayingType(AudioClipType clipType, float fadeOutDuration) { if (!IsWorking()) { return; } if (_clipType == clipType) { Stop(fadeOutDuration); } }
public override void Deserialize(System.IO.BinaryReader stream) { AudioClipType type = (AudioClipType)stream.ReadInt32(); if (type == AudioClipType.Waveform) { WaveType waveType = (WaveType)stream.ReadInt32(); double frequency = stream.ReadDouble(); Value = new WaveClip(waveType, frequency); } }
private void CreateNewAudioClipType() { _guiController.ProjectTree.StartFromNode(this, AUDIO_TYPES_FOLDER_NODE_ID); AudioClipType newClipType = new AudioClipType(_agsEditor.CurrentGame.AudioClipTypes.Count + 1, "New audio type", 0, 0, false, CrossfadeSpeed.No); _agsEditor.CurrentGame.AudioClipTypes.Add(newClipType); string newNodeID = AddTreeNodeForAudioClipType(newClipType); _guiController.ProjectTree.BeginLabelEdit(this, newNodeID); AudioClipTypeTypeConverter.RefreshAudioClipTypeList(); }
private string AddTreeNodeForAudioClipType(AudioClipType clipType) { string newNodeID = NODE_ID_PREFIX_CLIP_TYPE + clipType.TypeID; ProjectTreeItem treeItem = (ProjectTreeItem)_guiController.ProjectTree.AddTreeLeaf(this, newNodeID, clipType.Name, AUDIO_CLIP_TYPE_ICON); treeItem.AllowLabelEdit = true; treeItem.LabelTextProperty = clipType.GetType().GetProperty("Name"); treeItem.LabelTextDescriptionProperty = clipType.GetType().GetProperty("Name"); treeItem.LabelTextDataSource = clipType; return(newNodeID); }
//Запускает зацикленный источник звука public void PlayAudioContinuous(AudioClipType _audioType, ActionToCheck _toCheck) { Audio audio = audios[listsOfAudios[_audioType]]; if (audio.GetAudioSource() == null) { audio = PlayAudio(_audioType); audio.SetActionToCheck(_toCheck); audio.GetAudioSource().loop = true; audioSourcesContinuous.Add(audio); } }
private AudioClip GetClipByType(AudioClipType type) { switch (type) { case AudioClipType.LevelStarted: return(levelStartedSound); case AudioClipType.PlayerForceedEngine: return(playerForceedEngineSound); case AudioClipType.PlayerStoppedEngine: return(playerStoppedEngineSound); case AudioClipType.ScoreUp: return(scoreUpSound); case AudioClipType.TankHit: return(tankHitSound); case AudioClipType.EnvironmentHit: return(environmentHitSound); case AudioClipType.TargetHit: return(targetSound); case AudioClipType.Ice: return(iceSound); case AudioClipType.Shoot: return(shootSound); case AudioClipType.EnemyExplosion: return(enemyExplosionSound); case AudioClipType.LiveTaken: return(liveTakenSound); case AudioClipType.PlayerExplosion: return(playerExplosionSound); case AudioClipType.BonusAppearance: return(bonusAppearanceSound); case AudioClipType.BonusTaken: return(bonusTakenSound); case AudioClipType.Pause: return(pauseSound); } Assert.IsTrue(false, "Empty audio clip"); return(null); }
//Для каждого нового звукового эффекта создаётся новый источник звука public Audio PlayAudio(AudioClipType _audioType) { Audio audio = audios[listsOfAudios[_audioType]]; AudioSource newAudioSource = gameObject.AddComponent <AudioSource>(); audio.SetAudioSource(newAudioSource); newAudioSource.clip = audio.GetAudioClip(); newAudioSource.pitch = audio.GetPitch(); newAudioSource.volume *= masterVolume; newAudioSource.Play(); audioSourcesToRemove.Add(newAudioSource); return(audio); }
private AudioSource GetAudioSource(GameObject sourceObject, AudioClipType type) { GameObject src = sourceObject ?? GetDefaultAudioSource(type); foreach (AudioSource audioSrc in GameObjectUtility.EnsureComponents <AudioSource>(src, audioClips[type].maxCount)) { if (!audioSrc.isPlaying) { return(audioSrc); } } return(null); }
public void PlayAudioClipNow(AudioClipType type) { if (source.isPlaying) { source.Stop(); } AudioClip clip = null; switch (type) { case AudioClipType.ENTER_DUNGEON: clip = EnterDungeon; break; case AudioClipType.EXIT_DUNGEON: clip = ExitDungeon; break; case AudioClipType.ENEMY_FOUND: clip = EnemyFound; break; case AudioClipType.ATTACK: clip = Attack; break; case AudioClipType.ENEMY_DIE: clip = EnemyDie; break; case AudioClipType.VICTORY: clip = Victory; break; case AudioClipType.GAMEOVER: clip = GameOver; break; case AudioClipType.GRAB_ITEM: clip = GrabItem; break; case AudioClipType.ADVANCE: clip = Advance; break; } source.clip = clip; source.Play(); }
public void DoPlaySound(AudioClipType aClipName) { switch (aClipName) { case AudioClipType.GODZILLA_DAMAGE: _audioSource.PlayOneShot (_godzillaDamageAudioclip); break; case AudioClipType.MAZINGER_DAMAGE: _audioSource.PlayOneShot (_mazingerDamageudioclip); break; default: Debug.LogError ("Invalid clip type"); break; } }
public void PlayAudioClipDelayed(AudioClipType clipType, float delay, bool is3D, Vector3 position = default(Vector3)) { if (!SoundEnabled) { return; } var clip = _soundsConfig.GetClip(clipType); if (clip == null) { Debug.LogError("Audio clip for " + clipType + " was not found"); return; } StartCoroutine(PlayAudioClipDelayed(clip, delay, is3D, position: position)); }
public bool PlayClipOnceOnly(AudioClipType clipType) { #if ENABLE_WINMD_SUPPORT bool play = !this.HasClipPlayedPreviously(clipType); if (play) { var clipName = clipType.ToString(); ApplicationData.Current.LocalSettings.Values[clipName] = true; this.PlayClip(clipType); } return(play); #else throw new NotImplementedException(); #endif }
public void Play(AudioCommand command) { if (command == null) { return; } // save to current _command = command; _playTime = Time.time; // config AudioSource. Reset all setting first ResetAudioSource(); _source.outputAudioMixerGroup = command.basicCfg.mixerGroup; _clipType = command.basicCfg.clipType; _source.clip = command.GetClipForPlay(); // start the playing process StartPlayingProcess(command); }
public void PlayAudio(AudioClipType type, float volumeScale = 1) { AudioClip current; switch (type) { case AudioClipType.EXPLOSION: current = explosionClips[rand.Next(0, explosionClips.Length)]; break; default: current = otherClips[(int)type]; break; } audioSource.PlayOneShot(current, volumeScale); }
private void AdjustAudioTypeIDsAfterDeletingOne(AudioClipType typeJustDeleted) { foreach (AudioClipType type in _agsEditor.CurrentGame.AudioClipTypes) { if (type.TypeID > typeJustDeleted.TypeID) { type.TypeID--; } } foreach (AudioClip clip in _agsEditor.CurrentGame.RootAudioClipFolder.GetAllAudioClipsFromAllSubFolders()) { if (clip.Type > typeJustDeleted.TypeID) { clip.Type--; } } }
private void PlayerClip(AudioSource audioSource, AudioClipType type) { if (audioSource == null) { return; } AudioClip newClip = GetClipByType(type); if (newClip == audioSource.clip) { return; } audioSource.loop = false; audioSource.clip = newClip; audioSource.Play(); }
public void PlaySoundTime(AudioClipType type, float startTime, float stopTime) { /* Create a new audio clip */ AudioClip clip = audioDic [type]; int frequency = clip.frequency; float timeLength = stopTime - startTime; int samplesLength = (int)(frequency * timeLength); AudioClip newClip = AudioClip.Create(clip.name + "-sub", samplesLength, 1, frequency, false); /* Create a temporary buffer for the samples */ float[] data = new float[samplesLength]; /* Get the data from the original clip */ clip.GetData(data, (int)(frequency * startTime)); /* Transfer the data to the new clip */ newClip.SetData(data, 0); /* Return the sub clip */ AS_SOUND.PlayOneShot(newClip); //return newClip; }
/// <summary> /// Dos the play sound. /// </summary> /// <param name="aClipName">A clip name.</param> public void doPlaySound (AudioClipType aClipName) { //Debug.Log ("playing : " + aClipName); switch (aClipName) { case AudioClipType.BUTTON_CLICK: _audioSource.PlayOneShot (_buttonClick_audioclip); break; case AudioClipType.WAYPOINT_TRIGGERED: _audioSource.PlayOneShot (_waypointTriggered_audioclip); break; case AudioClipType.PLAYER_JUMPS: _audioSource.PlayOneShot (_playerJumps_audioclip); break; case AudioClipType.PLAYER_LANDS: _audioSource.PlayOneShot (_playerLands_audioclip); break; case AudioClipType.PLAYER_KILLS_ENEMY: _audioSource.PlayOneShot (_playerKillsEnemy_audioclip); break; case AudioClipType.PLAYER_FALLS_OFFSCREEN: _audioSource.PlayOneShot (_playerFallsOffscreen_audioclip); break; case AudioClipType.COIN_COLLECTED: _audioSource.PlayOneShot (_coinCollected_audioclip); break; case AudioClipType.ENEMY_KILLS_PLAYER: _audioSource.PlayOneShot (_enemyKillsPlayer_audioclip); break; case AudioClipType.GAME_START: _audioSource.PlayOneShot (_gameStart_audioclip); break; case AudioClipType.GAME_OVER_WIN: _audioSource.PlayOneShot (_gameOverWin_audioclip); break; case AudioClipType.GAME_OVER_LOSS: _audioSource.PlayOneShot (_gameOverLoss_audioclip); break; default: #pragma warning disable 0162 throw new SwitchStatementException(); break; #pragma warning restore 0162 } }