Skip to content

Commit

Permalink
swapped microphone from a UI element to a renderer for sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
dooly123 committed Jan 30, 2025
1 parent ee9874e commit af64a97
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Basis.Scripts.TransformBinders.BoneControl;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -479,25 +480,19 @@ public void LoadAndOrSaveDefaultDeviceConfigs(string directoryPath)

UseAbleDeviceConfigs = deviceDictionary.Values.ToList();
}
private static readonly Queue<Action> mainThreadActions = new Queue<Action>();
public void Update()
{
lock (mainThreadActions)
while (mainThreadActions.TryDequeue(out var action))
{
while (mainThreadActions.Count != 0)
{
mainThreadActions.Dequeue()?.Invoke();
}
action.Invoke();
}
}

private static readonly ConcurrentQueue<Action> mainThreadActions = new ConcurrentQueue<Action>();
public static void EnqueueOnMainThread(Action action)
{
Debug.Log("Enqueueing Action on Main Thread...");
lock (mainThreadActions)
{
mainThreadActions.Enqueue(action);
}
if (action == null) return;
mainThreadActions.Enqueue(action);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Basis.Scripts.Drivers;
using Basis.Scripts.UI.UI_Panels;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class BasisLocalCameraDriver : MonoBehaviour
public static event System.Action InstanceExists;
public BasisLockToInput BasisLockToInput;
public bool HasEvents = false;
public Canvas MicrophoneCanvas;
public Transform CanvasTransform;
public RawImage MicrophoneMutedIcon;
public RawImage MicrophoneUnMutedIcon;
public Transform MicrophoneUnMutedIconTransform;
public SpriteRenderer SpriteRendererIcon;
public Transform SpriteRendererIconTransform;
public Sprite SpriteMicrophoneOn;
public Sprite SpriteMicrophoneOff;

public Vector3 DesktopMicrophoneViewportPosition = new(0.2f, 0.15f, 1f); // Adjust as needed for canvas position and depth
public Vector3 VRMicrophoneOffset = new Vector3(-0.0004f, -0.0015f, 2f);
Expand Down Expand Up @@ -78,7 +78,7 @@ public void OnEnable()
HasEvents = true;
}
halfDuration = duration / 2f; // Time to scale up and down
StartingScale = MicrophoneMutedIcon.transform.localScale;
StartingScale = SpriteRendererIcon.transform.localScale;
// Target scale for the "bounce" effect (e.g., 1.2 times larger)
largerScale = StartingScale * 1.2f;
UpdateMicrophoneVisuals(MicrophoneRecorder.isPaused, false);
Expand All @@ -87,16 +87,17 @@ public void OnEnable()
{
SteamAudioManager.NotifyAudioListenerChanged();
}
SpriteRendererIcon.gameObject.SetActive(true);
}
public void MicrophoneTransmitting()
{
MicrophoneUnMutedIcon.color = UnMutedMutedIconColorActive;
MicrophoneUnMutedIconTransform.localScale = largerScale;
SpriteRendererIcon.color = UnMutedMutedIconColorActive;
SpriteRendererIconTransform.localScale = largerScale;
}
public void MicrophoneNotTransmitting()
{
MicrophoneUnMutedIcon.color = UnMutedMutedIconColorInactive;
MicrophoneUnMutedIconTransform.localScale = StartingScale;
SpriteRendererIcon.color = UnMutedMutedIconColorInactive;
SpriteRendererIconTransform.localScale = StartingScale;
}

private void OnPausedEvent(bool IsMuted)
Expand All @@ -113,30 +114,27 @@ public void UpdateMicrophoneVisuals(bool IsMuted, bool PlaySound)
}
if (IsMuted)
{
// BasisDebug.Log(nameof(UpdateMicrophoneVisuals) + IsMuted);

MicrophoneMutedIcon.gameObject.SetActive(true);
MicrophoneUnMutedIcon.gameObject.SetActive(false);
// BasisDebug.Log(nameof(UpdateMicrophoneVisuals) + IsMuted);
SpriteRendererIcon.sprite = SpriteMicrophoneOff;
if (PlaySound)
{
AudioSource.PlayOneShot(MuteSound);

}
// Start a new coroutine for the scale animation
scaleCoroutine = StartCoroutine(ScaleIcons(MicrophoneMutedIcon.gameObject));
scaleCoroutine = StartCoroutine(ScaleIcons(SpriteRendererIcon.gameObject));
}
else
{
// BasisDebug.Log(nameof(UpdateMicrophoneVisuals) + IsMuted);
// BasisDebug.Log(nameof(UpdateMicrophoneVisuals) + IsMuted);

MicrophoneMutedIcon.gameObject.SetActive(false);
MicrophoneUnMutedIcon.gameObject.SetActive(true);
SpriteRendererIcon.sprite = SpriteMicrophoneOn;
if (PlaySound)
{
AudioSource.PlayOneShot(UnMuteSound);
}
// Start a new coroutine for the scale animation
scaleCoroutine = StartCoroutine(ScaleIcons(MicrophoneUnMutedIcon.gameObject));
scaleCoroutine = StartCoroutine(ScaleIcons(SpriteRendererIconTransform.gameObject));
}
}
private IEnumerator ScaleIcons(GameObject iconToScale)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Basis.Scripts.UI.UI_Panels;
using UnityEditor;
using UnityEngine;

public class BasisUIHeadsUpLoadingbarEditor : EditorWindow
{
private BasisUIHeadsUpLoadingbarEditor targetScript;
public string UniqueId = "UniqueIDOutput";
// Create a menu item to open the window
[MenuItem("Basis/Tests/Loading Bar Tests")]
public static void ShowWindow()
{
GetWindow<BasisUIHeadsUpLoadingbarEditor>("Custom Editor Window");
}
public bool IsRunning = false;
private void OnGUI()
{
GUILayout.Label("Execute Task from Editor", EditorStyles.boldLabel);

// Display a button
if (GUILayout.Button("Start Testing"))
{
CallFunction();
IsRunning = true;
}
if (IsRunning)
{
float randomValue = UnityEngine.Random.Range(0f, 99f);
BasisUILoadingBar.ProgressReport(UniqueId, randomValue, "Test Message " + randomValue);
}
}

private void CallFunction()
{
BasisUILoadingBar.ProgressReport(UniqueId, 33, "Test Message");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System;
using System.Linq;
using Basis.Scripts.Device_Management;
Expand Down Expand Up @@ -380,4 +380,4 @@ public bool IsTransmitWorthy()
{
return averageRms > silenceThreshold;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void DeInitalize()
BasisSceneLoadDriver.progressCallback.OnProgressReport -= ProgressReport;
}

private static void ProgressReport(string UniqueID, float progress, string info)
public static void ProgressReport(string UniqueID, float progress, string info)
{
BasisDeviceManagement.EnqueueOnMainThread(() =>
{
Expand Down
Loading

0 comments on commit af64a97

Please sign in to comment.