static void ReceiveSoundEvent(string serializedSoundEvent) { try { SoundEventModel SoundEvent = Helpers.MsgPack.Deserialize <SoundEventModel>(serializedSoundEvent); if (SoundEvent.SoundName == "STOP" && SirenSoundIds.ContainsKey(SoundEvent.SourceServerId) && SirenSoundIds[SoundEvent.SourceServerId] != -1) { Function.Call(Hash.STOP_SOUND, SirenSoundIds[SoundEvent.SourceServerId]); Function.Call(Hash.RELEASE_SOUND_ID, SirenSoundIds[SoundEvent.SourceServerId]); SirenSoundIds[SoundEvent.SourceServerId] = -1; } else { if (SirenSoundIds.ContainsKey(SoundEvent.SourceServerId) && SirenSoundIds[SoundEvent.SourceServerId] != -1) { Function.Call(Hash.STOP_SOUND, SirenSoundIds[SoundEvent.SourceServerId]); Function.Call(Hash.RELEASE_SOUND_ID, SirenSoundIds[SoundEvent.SourceServerId]); } SirenSoundIds[SoundEvent.SourceServerId] = Function.Call <int>(Hash.GET_SOUND_ID); Function.Call(Hash.PLAY_SOUND_FROM_ENTITY, SirenSoundIds[SoundEvent.SourceServerId], SoundEvent.SoundName, new PlayerList()[SoundEvent.SourceServerId].Character.CurrentVehicle.Handle, 0, 0, 0); } } catch (Exception ex) { Log.Error($"Siren event error: {ex.Message}"); } }
override public void Launch(OnFinishEvent callBack, DataManager dataManager, EventModel eventManagerModel, GameManager gameManager) { base.Launch(callBack, dataManager, eventManagerModel, gameManager); SoundEventModel SoundEventModel = this.dataManager.soundEventModel.getModelById(eventManagerModel.eventChildId); this.Sound(SoundEventModel); this.callBack(); }
// 全BGM停止 public void StopAllBGM(SoundEventModel soundEventModel) { foreach (KeyValuePair <int, SoundObject> pair in this.soundObject) { if (SoundType.BGM == this.GetSoundType(pair.Key)) { pair.Value.Stop(soundEventModel); } } }
public void Play(SoundEventModel soundEventModel) { this.audioSource.loop = soundEventModel.isLoop; // FadeTimeが設定されていない場合すぐに再生 if (soundEventModel.fadeTime == 0) { this.audioSource.Play(); return; } StartCoroutine("Fadein", soundEventModel); }
public void Stop(SoundEventModel soundEventModel) { if (!this.IsPlaying()) { return; } // FadeTimeが設定されていない場合すぐに停止 if (soundEventModel.fadeTime == 0) { this.audioSource.Stop(); return; } StartCoroutine("Fadeout", soundEventModel); }
// フェードイン IEnumerator Fadein(SoundEventModel soundEventModel) { float currentTime = 0.0f; float waitTime = DETECTION_TIME; float originalVol = audioSource.volume; // msecに修正 float duration = (float)(soundEventModel.fadeTime / 1000.0f); audioSource.volume = 0.0f; audioSource.Play(); while (duration > currentTime) { currentTime += Time.deltaTime; audioSource.volume = Mathf.Clamp01(originalVol * currentTime / duration); yield return(new WaitForSeconds(waitTime)); } }
// イベントによる操作 private void Sound(SoundEventModel soundEventModel) { switch (soundEventModel.operationType) { case (int)OperationType.PLAY: this.soundManager.Play(soundEventModel); break; case (int)OperationType.STOP: this.soundManager.Stop(soundEventModel); break; case (int)OperationType.PAUSE: this.soundManager.Pause(soundEventModel); break; case (int)OperationType.STOP_ALLBGM: this.soundManager.StopAllBGM(soundEventModel); break; default: break; } }
// 停止 public void Stop(SoundEventModel soundEventModel) { this.soundObject[soundEventModel.soundId].Stop(soundEventModel); }
// 再生(なんでも) public void Play(SoundEventModel soundEventModel) { this.soundObject[soundEventModel.soundId].Play(soundEventModel); }
// 一時停止 public void Pause(SoundEventModel soundEventModel) { this.soundObject[soundEventModel.soundId].Pause(soundEventModel); }
public void Pause(SoundEventModel soundEventModel) { this.audioSource.Pause(); }