public void SetBackgroundMusic(AudioSource music) { this.mBGM = music; JCS_SoundSettings ss = JCS_SoundSettings.instance; this.mBGM.volume = ss.GetBGM_Volume(); this.mBGM.mute = ss.BGM_MUTE; }
/// <summary> /// Switch the background music, fading in and out. /// </summary> /// <param name="soundClip"> clip to play. </param> /// <param name="fadeTime"> time to fade in and out. </param> /// <param name="loop"> loop music? </param> public void SwitchBackgroundMusic( AudioClip soundClip, bool loop = true) { JCS_SoundSettings ss = JCS_SoundSettings.instance; SwitchBackgroundMusic( soundClip, ss.GetSoundFadeOutTimeBaseOnSetting(), ss.GetSoundFadeInTimeBaseOnSetting()); }
/// <summary> /// Play one shot background music, after playing it. /// Play the on stack sound. /// </summary> /// <param name="oneShotClip"> One shot BGM </param> /// <param name="onStackClip"> Audio clip on stack </param> public bool PlayOneShotBackgroundMusic( AudioClip oneShotClip, AudioClip onStackClip) { JCS_SoundSettings ss = JCS_SoundSettings.instance; return(PlayOneShotBackgroundMusic( oneShotClip, onStackClip, ss.GetSoundFadeOutTimeBaseOnSetting(), ss.GetSoundFadeInTimeBaseOnSetting())); }
protected override void Awake() { #if (UNITY_5_4_OR_NEWER) this.mRectTransform = this.GetComponent <RectTransform>(); if (mRectTransform == null) { return; } // this is the new way of doing the "OnLevelWasLoaded" // function call after version 5.4 UnityEngine.SceneManagement.SceneManager.sceneLoaded += (scene, loadingMode) => { JCS_UIManager uim = JCS_UIManager.instance; // Once we load the scene we need to let new object // in the scene know about us! uim.SetJCSDialogue(mDialogueType, this); // add to open window list if the window is open! AddToOpenWindowList(); ResetDialogue(); }; #endif if (mSoundPlayer == null) { this.mSoundPlayer = this.GetComponent <JCS_SoundPlayer>(); } base.Awake(); JCS_SoundSettings ss = JCS_SoundSettings.instance; // Assign Default Audio { if (mOpenWindowClip == null) { this.mOpenWindowClip = ss.DEFAULT_OPEN_WINDOW_CLIP; } if (mCloseWindowClip == null) { this.mCloseWindowClip = ss.DEFAULT_CLOSE_WINDOW_CLIP; } } }
/// <summary> /// On level was loaded callback. /// </summary> /// <param name="scene"></param> /// <param name="loadingMode"></param> private void LevelLoaded() { // set to Sound Manager in order to get manage JCS_SoundManager.instance.SetBackgroundMusic(GetAudioSource()); JCS_SoundSettings ss = JCS_SoundSettings.instance; if (!ss.KEEP_BGM_SWITCH_SCENE) { // Assign BGM from Sound Manager! GetAudioSource().clip = ss.BACKGROUND_MUSIC; GetAudioSource().Play(); } }
private void Start() { if (JCS_Camera.main == null) { JCS_Debug.LogError("There is no 'JCS_Camera' assign!"); return; } JCS_SoundSettings ss = JCS_SoundSettings.instance; // Reset the sound every scene SetSFXSoundVolume(ss.GetSFXSound_Volume()); SetSkillsSoundVolume(ss.GetSkillsSound_Volume()); SetSFXSoundMute(ss.EFFECT_MUTE); SetSkillsSoundMute(ss.PERFONAL_EFFECT_MUTE); }
/// <summary> /// Play one shot of sound. /// </summary> /// <param name="clip"></param> /// <param name="type"></param> public void PlayOneShot(AudioClip clip, JCS_SoundSettingType type) { JCS_SoundSettings ss = JCS_SoundSettings.instance; float volume = 0; switch (type) { case JCS_SoundSettingType.BGM_SOUND: volume = ss.GetBGM_Volume(); break; case JCS_SoundSettingType.SFX_SOUND: volume = ss.GetSFXSound_Volume(); break; case JCS_SoundSettingType.SKILLS_SOUND: volume = ss.GetSkillsSound_Volume(); break; } PlayOneShot(clip, volume); }
/// <summary> /// Load scene with self-define fade in time. /// </summary> /// <param name="sceneName"> scene name to load </param> /// <param name="fadeInTime"> time to fade in </param> /// <param name="screenColor"> screen color </param> /// <param name="keepBGM"> keep background music playing? </param> public void LoadScene( string sceneName, float fadeInTime, Color screenColor, bool keepBGM) { #if (UNITY_EDITOR) // only do this in Editor Mode, // this help level designer to do their job. if (!ReadSceneNames.CheckSceneAvailable(sceneName)) { JCS_Debug.LogReminder("Scene [" + sceneName + "] you want to load is not in the Build Setting"); return; } #endif // if is loading already, dont load it agian if (mSwitchSceneEffect) { return; } // set the next scene name this.mNextSceneName = sceneName; JCS_GameSettings gs = JCS_GameSettings.instance; if (gs.SAVE_ON_SWITCH_SCENE && gs.SAVE_GAME_DATA_FUNC != null) { // do the saving. gs.SAVE_GAME_DATA_FUNC.Invoke(); } // preload the scene mAsyncOperation = SceneManager.LoadSceneAsync(mNextSceneName); mAsyncOperation.allowSceneActivation = false; switch (mSwitchSceneType) { case JCS_SwitchSceneType.BLACK_SCREEN: { // move to the last child in order // to render the black screen in front of // any UI's GUI mBlackScreen.MoveToTheLastChild(); // set the screen color. // NOTE(jenchieh): always start with opacity the same // as previous. screenColor.a = mBlackScreen.LocalColor.a; mBlackScreen.LocalColor = screenColor; // record down the screen color. JCS_SceneSettings.instance.SCREEN_COLOR = screenColor; // start fading in (black screen) mBlackScreen.FadeIn(fadeInTime); } break; case JCS_SwitchSceneType.SLIDE_SCREEN: { mBlackSlideScreen.MoveToTheLastChild(); mBlackSlideScreen.StartSlideIn(mAlign, fadeInTime); } break; } JCS_SoundSettings ss = JCS_SoundSettings.instance; ss.KEEP_BGM_SWITCH_SCENE = keepBGM; if (!keepBGM) { // start fading sound if (ss.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE) { // get the component. if (mJCSFadeSound == null) { mJCSFadeSound = this.gameObject.AddComponent <JCS_FadeSound>(); } mJCSFadeSound.SetAudioSource(JCS_SoundManager.instance.GetBGMAudioSource()); // fade out sound to zero mJCSFadeSound.FadeOut(0, fadeInTime); } } // start check to switch scene or not mSwitchSceneEffect = true; // Pause the game depends on setting... JCS_GameManager.instance.GAME_PAUSE = mPauseGameWhileLoadingScene; }
private void Start() { // NOTE(jenchieh): get the fade out time base on // the scene setting and scene manager specific. float fadeoutTime = JCS_SceneSettings.instance.GetSceneFadeInTimeBaseOnSetting(); switch (mSwitchSceneType) { case JCS_SwitchSceneType.BLACK_SCREEN: { // get the current screen color. mBlackScreen.LocalColor = JCS_SceneSettings.instance.SCREEN_COLOR; mBlackScreen.FadeOut(fadeoutTime); } break; case JCS_SwitchSceneType.SLIDE_SCREEN: { mBlackSlideScreen.StartSlideOut(mAlign, fadeoutTime); } break; } // Only need to fade BGM when BGM is not switch // between scene. JCS_SoundSettings ss = JCS_SoundSettings.instance; if (!ss.KEEP_BGM_SWITCH_SCENE) { if (ss.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE) { // get the component. if (mJCSFadeSound == null) { mJCSFadeSound = this.gameObject.AddComponent <JCS_FadeSound>(); } // set the background audio source. mJCSFadeSound.SetAudioSource( JCS_SoundManager.instance.GetBGMAudioSource()); // active the fade sound in effect. mJCSFadeSound.FadeIn( JCS_SoundSettings.instance.GetBGM_Volume(), /* Fade in the sound base on the setting. */ JCS_SoundSettings.instance.GetSoundFadeInTimeBaseOnSetting()); } } else { // If the keep bgm is true, we disable it once // everytime a scene is loaded. // // ATTENTION(jenchieh): This should be place for the last // use of the variable 'KEEP_BGM_SWITCH_SCENE'. JCS_SoundSettings.instance.KEEP_BGM_SWITCH_SCENE = false; } // the game is loaded start the game agian JCS_GameManager.instance.GAME_PAUSE = false; }