public bool Play(int soundId, float offset) { if (soundId > (int)EVehicleSoundId.Invalid) { //mute other sounds MuteSoundExcept(soundId); // if it is the first time audio-play then create the specified sound entity. SoundEntity soundEntity = null; if (!_soundEntityCache.ContainsKey(soundId)) { soundEntity = CreateSoundEntity(soundId); _soundEntityCache[soundId] = soundEntity; } soundEntity = _soundEntityCache[soundId]; if (soundEntity == null) { return(true); } //play the speicified sound if (soundEntity.hasAudioSourceKey) { var soundKey = soundEntity.audioSourceKey.Value; if (_soundPlayer.IsPlaying(soundKey)) { _soundPlayer.Mute(soundKey, false); } else { var isLoopSound = _soundConfigManager.IsLoopSound(soundId); if (isLoopSound && offset > 0) { var clipLength = _soundPlayer.GetLength(soundKey); if (clipLength > 0) { offset %= clipLength; } } _soundPlayer.Play(soundKey, offset, isLoopSound); } return(true); } return(false); } //mute all sound if try play Invalid Sound MuteSoundExcept((int)EVehicleSoundId.Invalid); return(true); }