using UnityEngine; namespace OHM.UnityToolkit { public class SFXInstance : MonoBehaviour { [SerializeField] public bool autoDestroyOnEnd = true; [SerializeField] public AudioSource audioSource; public static readonly int[] majorScale = { 2, 2, 1, 2, 2, 2, 1 }; public static readonly int[] majorScaleMirrored = { 2, 2, 1, 2, 2, 2, 1, -1, -2, -2, -2, -1, -2, -2 }; public static readonly int[] majorScaleLoop = { 2, 2, 1, 2, 2, 2, -13 }; public static readonly int[] test = { 2, 2, 1, -5, 0, 2, 2, 1, 2, -7 }; private void Awake() { ComponentsUtils.GetRequiredComponent(this, ref audioSource); } private void Update() { if (!autoDestroyOnEnd) { return; } if (audioSource != null && audioSource.isPlaying) { return; } UnityEngine.Object.Destroy(base.gameObject); } private void OnDisable() { if (autoDestroyOnEnd) { UnityEngine.Object.Destroy(base.gameObject); } } public void RisingPitchShiftingSemiTone(int semitoneCount) { audioSource.pitch = Mathf.Pow(1.06f, semitoneCount); } public void RisingPitchShiftingScale(int[] scale, int count) { int semitones = 0; for (int i = 0; i < count; i++) { semitones += scale[i % scale.Length]; } RisingPitchShiftingSemiTone(semitones); } } }