Skip to content

Commit

Permalink
Made Controller call AudioLinkEnable/Disable
Browse files Browse the repository at this point in the history
• Made the AudioLinkController call AudioLinkEnable/Disable instead of toggling the AudioLink GameObject.
• Made AudioLink stop doing readbacks if it's disabled.
  • Loading branch information
Nestorboy committed Oct 30, 2023
1 parent 8878724 commit 1fb8058
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Packages/com.llealloo.audiolink/Runtime/Scripts/AudioLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public partial class AudioLink : MonoBehaviour
[NonSerialized] public Color[] audioData = new Color[AudioLinkWidth * AudioLinkHeight];
[HideInInspector] public Texture2D audioData2D; // Texture2D reference for hacked Blit, may eventually be depreciated

private bool _audioLinkEnabled = true;

private float[] _audioFramesL = new float[1023 * 4];
private float[] _audioFramesR = new float[1023 * 4];
private float[] _samples = new float[1023];
Expand Down Expand Up @@ -428,6 +430,11 @@ private void FPSUpdate()

private void Update()
{
if (!_audioLinkEnabled)
{
return;
}

#if !UNITY_ANDROID
if (audioDataToggle)
{
Expand Down Expand Up @@ -557,7 +564,7 @@ private void Update()
#if UNITY_ANDROID
void OnPostRender()
{
if (audioDataToggle)
if (_audioLinkEnabled && audioDataToggle)
{
audioData2D.ReadPixels(new Rect(0, 0, audioData2D.width, audioData2D.height), 0, 0, false);
audioData = audioData2D.GetPixels();
Expand Down Expand Up @@ -728,6 +735,7 @@ private void UpdateGlobalString(int nameID, string input)

public void EnableAudioLink()
{
_audioLinkEnabled = true;
audioRenderTexture.updateMode = CustomRenderTextureUpdateMode.Realtime;
#if UDONSHARP
SetGlobalTexture(_AudioTexture, audioRenderTexture);
Expand All @@ -738,6 +746,7 @@ public void EnableAudioLink()

public void DisableAudioLink()
{
_audioLinkEnabled = false;
audioRenderTexture.updateMode = CustomRenderTextureUpdateMode.OnDemand;
#if UDONSHARP
SetGlobalTexture(_AudioTexture, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ public void UpdateSettings()
audioLink.UpdateSettings();

// Toggle
audioLink.gameObject.SetActive(powerToggle.isOn);
if (powerToggle.isOn)
{
audioLink.EnableAudioLink();
}
else
{
audioLink.DisableAudioLink();
}
}

public void ResetSettings()
Expand Down

0 comments on commit 1fb8058

Please sign in to comment.