void Awake() { // avoid duplicates if (instance != null) { // we set dontDestroyOnLoad to false here due to the Destroy being delayed. it will avoid issues // with OnLevelWasLoaded being called while the object is being destroyed. dontDestroyOnLoad = false; Destroy(gameObject); return; } instance = this; if (dontDestroyOnLoad) { DontDestroyOnLoad(gameObject); } // Create the _soundList to speed up sound playing in game _availableSounds = new Stack <SKSound>(maxCapacity); _playingSounds = new List <SKSound>(); for (int i = 0; i < initialCapacity; i++) { _availableSounds.Push(new SKSound(this)); } }
private void Start() { soundKit = Toolbox.Instance.TryGet <SoundKit>(); soundKit.playBackgroundMusic(bgm, 1.0f, false); SceneManager.LoadSceneAsync(Scenes.EFFECTS, LoadSceneMode.Additive); }
public void OnEnable() { // _previewer = EditorUtility // .CreateGameObjectWithHideFlags("Audio preview", HideFlags.HideAndDontSave, typeof(AudioSource)) // .GetComponent<AudioSource>(); _previewer = EditorUtility .CreateGameObjectWithHideFlags("Audio preview", HideFlags.HideAndDontSave, typeof(SoundKit)) .GetComponent <SoundKit>(); _previewer.initialCapacity = 1; _previewer.maxCapacity = 1; _previewer.Awake(); }
// public override void Play(AudioSource source) // { // if (clips.Length == 0) return; // // source.clip = clips[Random.Range(0, clips.Length)]; // source.volume = Random.Range(volume.Min, volume.Max); // source.pitch = Random.Range(pitch.Min, pitch.Max); // source.Play(); // } public override void Play(SoundKit source) { if (clips.Length == 0) { return; } AudioClip ranClip = clips[Random.Range(0, clips.Length)]; float ranVol = Random.Range(volume.Min, volume.Max); float ranPitch = Random.Range(pitch.Min, pitch.Max); source.playSound(ranClip, ranVol, ranPitch, 0f); }
private void Start() { sk = Toolbox.Instance.TryGet <SoundKit>(); GameObject treeObj = GameObject.FindGameObjectWithTag(Tags.TREES); GameObject grassObj = GameObject.FindGameObjectWithTag(Tags.GRASS); treeAnimators = treeObj.GetComponentsInChildren <Animator>(); grassAnimators = grassObj.GetComponentsInChildren <Animator>(); skyboxMaterial = RenderSettings.skybox; skyboxMaterial.SetFloat("_AtmosphereThickness", atmosphereThickness); tweenTarget = new CustomTweenTarget(skyboxMaterial); }
private void Start() { soundKit = Toolbox.Instance.TryGet <SoundKit>(); platformController.IsJumpingThisFrameCallback += () => { isJumping = true; jumpAudio?.Play(soundKit); }; platformController.IsLandingThisFrameCallback += () => { isJumping = false; if (Time.time - attackActuatedTime <= earlyAttackTimeTolerance) { attackCanAttackCancel = false; animator.SetTrigger(AnimatorParams.ATTACK); } }; }
// public override void Play(AudioSource source) // { // float totalWeight = 0; // for (int i = 0; i < Entries.Length; ++i) // totalWeight += Entries[i].Weight; // // float pick = Random.Range(0, totalWeight); // for (int i = 0; i < Entries.Length; ++i) // { // if (pick > Entries[i].Weight) // { // pick -= Entries[i].Weight; // continue; // } // // Entries[i].Event.Play(source); // return; // } // } public override void Play(SoundKit source) { float totalWeight = 0; for (int i = 0; i < Entries.Length; ++i) { totalWeight += Entries[i].Weight; } float pick = Random.Range(0, totalWeight); for (int i = 0; i < Entries.Length; ++i) { if (pick > Entries[i].Weight) { pick -= Entries[i].Weight; continue; } Entries[i].Event.Play(source); return; } }
void Awake() { // avoid duplicates if( instance != null ) { // we set dontDestroyOnLoad to false here due to the Destroy being delayed. it will avoid issues // with OnLevelWasLoaded being called while the object is being destroyed. dontDestroyOnLoad = false; Destroy( gameObject ); return; } instance = this; if( dontDestroyOnLoad ) DontDestroyOnLoad( gameObject ); // Create the _soundList to speed up sound playing in game _availableSounds = new Stack<SKSound>( maxCapacity ); _playingSounds = new List<SKSound>(); for( int i = 0; i < initialCapacity; i++ ) _availableSounds.Push( new SKSound( this ) ); }
void OnApplicationQuit() { instance = null; }
public SKSound(SoundKit manager) { _manager = manager; audioSource = _manager.gameObject.AddComponent <AudioSource>(); audioSource.playOnAwake = false; }
public SKSound( SoundKit manager ) { _manager = manager; audioSource = _manager.gameObject.AddComponent<AudioSource>(); audioSource.playOnAwake = false; }
public override void Play(SoundKit source) { source.playSound(clip, volume, pitch, 0f); }
// public abstract void Play(AudioSource source); public abstract void Play(SoundKit source);