From 015e8a28d5a44de89b137651ec3fdb2b281f40a5 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sat, 31 May 2025 01:18:01 -0400 Subject: [PATCH 1/2] feat(multiplayer): Add EEGSyncManager for real-time brainwave syncing --- Assets/Scripts/Networking/EEGSyncManager.cs | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Assets/Scripts/Networking/EEGSyncManager.cs diff --git a/Assets/Scripts/Networking/EEGSyncManager.cs b/Assets/Scripts/Networking/EEGSyncManager.cs new file mode 100644 index 0000000..e6977d7 --- /dev/null +++ b/Assets/Scripts/Networking/EEGSyncManager.cs @@ -0,0 +1,36 @@ +using Unity.Netcode; +using UnityEngine; + +public class EEGSyncManager : NetworkBehaviour +{ + public static EEGSyncManager Instance; + + [Header("EEG Sync Data")] + public NetworkVariable syncedAttentionLevel = new NetworkVariable( + 0f, + NetworkVariableReadPermission.Everyone, + NetworkVariableWritePermission.Owner + ); + + private void Awake() + { + if (Instance == null) + { + Instance = this; + } + } + + public void UpdateAttentionLevel(float newLevel) + { + if (IsOwner) + { + syncedAttentionLevel.Value = newLevel; + } + } + + public float GetRemoteAttentionLevel() + { + return syncedAttentionLevel.Value; + } +} + From 3b110aa676ad5f2420c6f97d125ccf0254c6faa8 Mon Sep 17 00:00:00 2001 From: Syed Hussain Ather Date: Sun, 1 Jun 2025 21:45:35 -0400 Subject: [PATCH 2/2] chore(debug): Add console logging for remote EEG attention updates --- Assets/Scripts/Networking/EEGSyncManager.cs | 41 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Networking/EEGSyncManager.cs b/Assets/Scripts/Networking/EEGSyncManager.cs index e6977d7..f8936b3 100644 --- a/Assets/Scripts/Networking/EEGSyncManager.cs +++ b/Assets/Scripts/Networking/EEGSyncManager.cs @@ -1,16 +1,19 @@ +// File: EEGSyncManager.cs + using Unity.Netcode; using UnityEngine; +using UnityEngine.UI; public class EEGSyncManager : NetworkBehaviour { public static EEGSyncManager Instance; [Header("EEG Sync Data")] - public NetworkVariable syncedAttentionLevel = new NetworkVariable( - 0f, - NetworkVariableReadPermission.Everyone, - NetworkVariableWritePermission.Owner - ); + public NetworkVariable syncedAttentionLevel = new NetworkVariable(0f, NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner); + + [Header("UI Elements")] + public Slider remoteAttentionSlider; + public Text remoteAttentionText; private void Awake() { @@ -20,6 +23,28 @@ private void Awake() } } +private float lastLoggedValue = -1f; + + private void Update() + { + if (!IsOwner && remoteAttentionSlider != null) + { + remoteAttentionSlider.value = syncedAttentionLevel.Value; + } + + if (!IsOwner && remoteAttentionText != null) + { + remoteAttentionText.text = $"Other Attention: {syncedAttentionLevel.Value:F2}"; + } + + if (!IsOwner && Mathf.Abs(syncedAttentionLevel.Value - lastLoggedValue) > 0.01f) + { + Debug.Log($"[EEG Sync] Remote attention level updated: {syncedAttentionLevel.Value:F2}"); + lastLoggedValue = syncedAttentionLevel.Value; + } +} + + public void UpdateAttentionLevel(float newLevel) { if (IsOwner) @@ -34,3 +59,9 @@ public float GetRemoteAttentionLevel() } } +// --- Usage Example --- +// In EEG input script (e.g., from Python via LSL): +// EEGSyncManager.Instance.UpdateAttentionLevel(currentAttention); +// In UI or scene logic: +// float otherAttention = EEGSyncManager.Instance.GetRemoteAttentionLevel(); +