public void ConfirmKnifeSFX() { if (GameManager.Sound) { confirmKnifeSID = AndroidNativeAudio.play(confirmKnifeFID); } }
public void UnlockKnifeSFX() { if (GameManager.Sound) { unlockKnifeSID = AndroidNativeAudio.play(unlockKnifeFID); } }
public void Play(string name, bool loop) { /* * Sound s = Array.Find(sounds, sound => sound.name == name); * if(s == null) * { * Debug.LogWarning("Sound: " + name + "not found!"); * return; * } * s.source.Play(); */ Sound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + "not found!"); return; } if (loop) { s.stream = AndroidNativeAudio.play(s.id, loop: -1); } else { s.stream = AndroidNativeAudio.play(s.id); } AndroidNativeAudio.setVolume(s.stream, s.volume); s.streamSet = true; }
public void RandomUnlockSFX() { if (GameManager.Sound) { randomUnlockSID = AndroidNativeAudio.play(randomUnlockFID); } }
void Awake() { if (singleton == null) { DontDestroyOnLoad(gameObject); singleton = this; maxMusicVolume = State.GetMusicVolume(); maxSoundEffectVolume = State.GetSoundEffectsVolume(); #if UNITY_ANDROID && !UNITY_EDITOR AndroidNativeAudio.makePool(3); #endif // cache reference to music source and sound effects sources GameObject[] effects = GameObject.FindGameObjectsWithTag("SoundEffectSource"); foreach (GameObject e in effects) { SoundEffectSources.Add(e.GetComponentInChildren <AudioSource>()); } // start loading sounds StartCoroutine("LoadSounds"); } else if (singleton != this) { Destroy(gameObject); } }
public void ButtonClicked(string ok) { if (coolDownLeft == 0 && !GameController.Instance.GameOver && !GameController.Instance.AbilityInUse) { if (!GameController.Instance.FXMuted) { if (Application.platform == RuntimePlatform.Android) { streamId = AndroidNativeAudio.play(fileId); } else { GetComponent <AudioSource>().Play(); } } GameController.Instance.AbilityInUse = true; coolDownLeft = Cooldown; isTeleporting = true; GameController.Instance.GodMode = true; baseSpeed = GameController.Instance.GameMovSpeed; teleSpeed = (baseTeleDist * GameController.Instance.DefaultScrollSpeed) / TimeToTeleport; //OnTeleport(); } Debug.Log(ok); }
public void ThrowKnifeSFX() { if (GameManager.Sound) { throwKnifeSID = AndroidNativeAudio.play(throwKnifeFID); } }
//public IEnumerator PlaySound(AudioSource source, Transform parent) //{ // Transform sourceTransform = source.transform; // sourceTransform.SetParent(null); // source.Play(); // do // { // yield return null; // } while (source.isPlaying); // sourceTransform.SetParent(parent); //} public void PlaySFX(string name) { string[] str = name.Split(':'); if (str.Length > 1) { float pitch; if (float.TryParse(str[1], out pitch)) { //Debug.Log("SFX:" + str[0] + pitch); PlaySFX(str[0], pitch); } else { Debug.LogErrorFormat("PlaySFX-Pitch Parsing False"); } return; } #if UNITY_EDITOR || UNITY_STANDALONE if (SFXClipDictionary.ContainsKey(name)) { SFX.PlayOneShot(SFXClipDictionary[name], sfxVolume); } #endif #if !UNITY_EDITOR && UNITY_ANDROID currentSFXStreamID = AndroidNativeAudio.play(SFXFileIDDictionary[name], sfxVolume, -1); #endif }
void Start() { var genericMenuList = GameObject.FindGameObjectsWithTag("GenericMenu"); if (genericMenuList.Length > 1) { foreach (var genericMenuManager in genericMenuList) { genericMenuManager.GetComponent <GenericMenuManagerBehavior> ().BackSceneName = this.BackSceneName; } Destroy(gameObject); return; } AndroidNativeAudio.makePool(); _hasMadeAudioPool = true; SceneManager.sceneLoaded += OnSceneLoaded; HandleBackButton(); // ---- AUDIOS ---- // MenuBipDefaultAudioFileID = AndroidNativeAudio.load("MenuBipDefault.mp3"); MenuBipGoToAudioFileID = AndroidNativeAudio.load("MenuBipGoTo.mp3"); MenuBipSelectAudioFileID = AndroidNativeAudio.load("MenuBipSelect.mp3"); MenuBipConfirmAudioFileID = AndroidNativeAudio.load("MenuBipConfirm.mp3"); MenuBipReturnAudioFileID = AndroidNativeAudio.load("MenuBipReturn.mp3"); SwitchTVONFileID = AndroidNativeAudio.load("SwitchTVON.mp3"); NamePresentationFileID = AndroidNativeAudio.load("NamePresentation.mp3"); BorderMovementFileID = AndroidNativeAudio.load("BorderMovement.mp3"); }
//edited add whole fuctions below StreamID's public void KnifeHitSFX() { if (GameManager.Sound) { knifeHitSID = AndroidNativeAudio.play(knifeHitFID); } }
public void InitNativeAudio() { AndroidNativeAudio.makePool(16); buttonSoundID = AndroidNativeAudio.load("Android Native Audio/button.ogg"); coinSoundID = AndroidNativeAudio.load("Android Native Audio/coin.mp3"); }
public int ANALoadAudio(string audioFile) { int fileId = AndroidNativeAudio.load(audioFile); loadedFiles.Add(fileId); return(fileId); }
/// <summary> /// [iOS] Initializes OpenAL. Then 16 OpenAL sources will be allocated all at once. You have a maximum of 16 concurrency shared for all sounds. /// It is not possible to initialize again on iOS. (Nothing will happen) /// /// [Android] Initializes OpenSL ES. Then 1 OpenSL ES Engine and a number of AudioPlayer object (and in turn AudioTrack) will be allocated all at once. /// It is possible on Android to initialize again in order to change <paramref name="initializationOptions">. /// /// (More about this limit : https://developer.android.com/ndk/guides/audio/opensl/opensl-for-android) /// (And my own research here : https://gametorrahod.com/androids-native-audio-primer-for-unity-developers-65acf66dd124) /// </summary> public static void Initialize(InitializationOptions initializationOptions) { //Now it is possible to initialize again with different option on Android. It would dispose and reallocate native sources. #if UNITY_IOS if (Initialized) { return; } #endif #if UNITY_IOS int errorCode = _Initialize(); if (errorCode == -1) { throw new System.Exception("There is an error initializing Native Audio."); } //There is also a check at native side but just to be safe here. Initialized = true; #elif UNITY_ANDROID int errorCode = AndroidNativeAudio.CallStatic <int>(AndroidInitialize, initializationOptions.androidAudioTrackCount, initializationOptions.androidMinimumBufferSize, initializationOptions.preserveOnMinimize); if (errorCode == -1) { throw new System.Exception("There is an error initializing Native Audio."); } Initialized = true; #endif }
public void PlayEffect(string effectName) { SoundEffect s = Array.Find(effects, effect => effect.name == effectName); // this uses a Lambda Expression int soundID = AndroidNativeAudio.play(s.fileID); AndroidNativeAudio.setVolume(soundID, s.volume * volumeControl.EffectsVolume); }
public void LastHitSFX() { if (GameManager.Sound) { lastHitSID = AndroidNativeAudio.play(lastHitFID); } }
public void FreeContinueSFX() { if (GameManager.Sound) { freeContinueSID = AndroidNativeAudio.play(freeContinueFID); } }
public void WoodHitSFX() { if (GameManager.Sound) { woodHitSID = AndroidNativeAudio.play(woodHitFID); } }
void Awake() { instance = this; AndroidNativeAudio.makePool(); //for (int i = 0; i < musicClips.Length; i++) //{ // musicClipDictionary.Add(musicClips[i].name, musicClips[i]); //} #if UNITY_EDITOR || UNITY_STANDALONE for (int i = 0; i < musicNames.Length; i++) { StartCoroutine(LoadClipCoroutine("Music", musicNames[i], AudioType.OGGVORBIS, OnMusicLoadingCompleted)); } for (int i = 0; i < SFXNames.Length; i++) { StartCoroutine(LoadClipCoroutine("SFX", SFXNames[i], AudioType.WAV, OnSFXLoadingCompleted)); } #else for (int i = 0; i < SFXNames.Length; i++) { SFXFileIDDictionary.Add(SFXNames[i], AndroidNativeAudio.load(string.Format("SFX/{0}.wav", SFXNames[i]))); } #endif //for (int i = 0; i < musicNames.Length; i++) //{ // musicFileIDDictionary.Add(musicNames[i], ANAMusic.load(string.Format("Music/{0}.ogg", musicNames[i]), false, false)); //} }
public void AppleHitSFX() { if (GameManager.Sound) { appleHitSID = AndroidNativeAudio.play(appleHitFID); } }
void OnApplicationQuit() { AndroidNativeAudio.unload(BopH); AndroidNativeAudio.unload(BopM); AndroidNativeAudio.unload(BopL); AndroidNativeAudio.releasePool(); }
public void OnUnlockSFX() { if (GameManager.Sound) { onUnlockSID = AndroidNativeAudio.play(onUnlockFID); } }
public void Resume(string name, bool loop) { Sound s = Array.Find(sounds, sound => sound.name == name); if (s == null) { Debug.LogWarning("Sound: " + name + "not found!"); return; } //s.id = AndroidNativeAudio.load(s.name + ".mp3"); if (s.streamSet) { AndroidNativeAudio.resume(s.stream); } else { if (loop) { s.stream = AndroidNativeAudio.play(s.id, loop: -1); s.streamSet = true; } else { s.stream = AndroidNativeAudio.play(s.id); Debug.Log("the stream : " + s.stream); s.streamSet = true; } } }
public void BossFightEndSFX() { if (GameManager.Sound) { bossFightEndSID = AndroidNativeAudio.play(bossFightEndFID); } }
void Start() { unityAudio = GetComponent <AudioSource>(); AndroidNativeAudio.makePool(1); soundID = AndroidNativeAudio.load("Android Native Audio/Tone Native.wav"); }
private void Update() { if (!isShrinking) { this.transform.DOScale(new Vector3(0.51f, 0.51f, 0.51f), lifeSpan); } lifeSpan -= Time.deltaTime; if (lifeSpan < 0f && hasPlayed == false) { hasPlayed = true; SoundID = AndroidNativeAudio.play(FileID); } else if (lifeSpan <= 0f && lifeSpan > -1f) { if (!isShrinking) { isShrinking = true; this.transform.DOScale(new Vector3(0.0f, 0.0f, 1f), 0.3f); } } else if(lifeSpan <= -1f) { Destroy(this.gameObject); } }
/// <summary> /// 初始化音频管理器 /// </summary> /// <param name="audioDatas"></param> public void InitAudioManager(List <AudioData> audioDatas) { dicAudioDatas = new Dictionary <int, AudioData>(); foreach (var item in audioDatas) { dicAudioDatas.Add(item.id, item); } #if UNITY_ANDROID AndroidNativeAudio.makePool(); for (int i = 0; i < audioDatas.Count; i++) { string resPath = audioDatas[i].ResPath; //只加载Audio/Once目录下的音效 if (resPath.IndexOf("Audio/Once") != -1) { string AudioFileName = resPath.Substring(resPath.LastIndexOf("/") + 1); string path = /*Application.streamingAssetsPath + "/" +*/ AppSetting.PlatformName + "/" + AppSetting.MineGameName + "/" + "audio/once/" + AudioFileName; CLog.Log("SDK加载音频路径:" + path); DBTSDK.SDKToolManager.Instance.PreloadEffect(path); //int fileId = AndroidNativeAudio.load(AppSetting.PlatformName + "/" + AppSetting.MineGameName + "/" + "audio/once/" + AudioFileName); m_AndroidAudioDics[audioDatas[i].id] = path; } } #endif }
void OnDestroy() { AndroidNativeAudio.unload(ClickIn); AndroidNativeAudio.unload(ClickOut); AndroidNativeAudio.releasePool(); }
public void PlaySound(int id, float volume = -1) { //if (cancelSound) // return; if (!isInitialized) { Initialize(); } if (volume == -1) { volume = m_Volume; } else { volume = volume * m_Volume; } #if UNITY_ANDROID && !UNITY_EDITOR if (bestPerformance) { PlayWithAudioSource(id, volume); } else { AndroidNativeAudio.play(id, volume); } #else PlayWithAudioSource(id, volume); #endif }
// Use this for initialization void Start() { scoreManager = FindObjectOfType <ScoreManager>(); currencyManager = FindObjectOfType <CurrencyManager>(); camera = FindObjectOfType <CameraController>(); tomatoFileID = AndroidNativeAudio.load("tomato-squish.wav"); }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "Rawio") { gameOverSoundID = AndroidNativeAudio.play(gameOverFileID, 0.5f); gameManager.RestartGame(); } }