Files
butchers-games-test/Assets/Scripts/Toolkit/OHM/UnityToolkit/SFXInstance.cs
T
Boris Nikolaev 5f1e94b653 add project files
2026-08-14 01:58:31 +03:00

63 lines
1.3 KiB
C#

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);
}
}
}