mirror of
https://github.com/MrUnknownDE/vcc-tools.git
synced 2026-04-30 12:23:47 +02:00
Compare commits
5 Commits
9250fc71ed
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 689ceca124 | |||
| 185f1cc96a | |||
| 32a428502d | |||
| 50017d40c8 | |||
| 5490b72e5d |
64
AudioLink/AudioLinkBeatDetector.cs
Normal file
64
AudioLink/AudioLinkBeatDetector.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using UdonSharp;
|
||||||
|
using UnityEngine;
|
||||||
|
using AudioLink;
|
||||||
|
|
||||||
|
public class AudioLinkBeatDetector : UdonSharpBehaviour
|
||||||
|
{
|
||||||
|
public AudioLink.AudioLink audioLinkInstance;
|
||||||
|
|
||||||
|
[Header("Settings")]
|
||||||
|
[Range(0, 1)] public float threshold = 0.5f;
|
||||||
|
public float minBpm = 70f;
|
||||||
|
public float maxBpm = 210f; // Alles darüber wird als Fehler ignoriert
|
||||||
|
|
||||||
|
[Header("Output")]
|
||||||
|
public float bpm = 128f;
|
||||||
|
public float instantBpm = 128f;
|
||||||
|
public bool isBeat;
|
||||||
|
|
||||||
|
private float lastBeatTime;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (audioLinkInstance == null || !audioLinkInstance.AudioDataIsAvailable()) return;
|
||||||
|
|
||||||
|
Vector2 bassPos = AudioLink.AudioLink.GetALPassAudioBass();
|
||||||
|
Vector4 data = audioLinkInstance.GetDataAtPixel((int)bassPos.x, (int)bassPos.y);
|
||||||
|
float currentLevel = data.x;
|
||||||
|
|
||||||
|
// Prüfen auf Threshold
|
||||||
|
if (currentLevel > threshold)
|
||||||
|
{
|
||||||
|
float currentTime = Time.time;
|
||||||
|
float timeDiff = currentTime - lastBeatTime;
|
||||||
|
|
||||||
|
// Der "Debounce" Check:
|
||||||
|
// 0.27s entspricht ca. 222 BPM. Alles was schneller kommt, ist Rauschen.
|
||||||
|
if (timeDiff > 0.27f)
|
||||||
|
{
|
||||||
|
if (lastBeatTime > 0)
|
||||||
|
{
|
||||||
|
float detected = 60f / timeDiff;
|
||||||
|
|
||||||
|
// Nur plausible Werte übernehmen
|
||||||
|
if (detected >= minBpm && detected <= maxBpm)
|
||||||
|
{
|
||||||
|
instantBpm = detected;
|
||||||
|
// Glättung: 0.5 sorgt für schnelles Folgen, aber filtert Ausreißer
|
||||||
|
bpm = Mathf.Lerp(bpm, instantBpm, 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastBeatTime = currentTime;
|
||||||
|
isBeat = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isBeat = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isBeat = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
AudioLink/BeatDetectorDisplay.cs
Normal file
43
AudioLink/BeatDetectorDisplay.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using UdonSharp;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using TMPro;
|
||||||
|
|
||||||
|
public class BeatDetectorDisplay : UdonSharpBehaviour
|
||||||
|
{
|
||||||
|
public AudioLinkBeatDetector engine;
|
||||||
|
public TextMeshProUGUI bpmText;
|
||||||
|
public Image beatIndicator;
|
||||||
|
public Color activeColor = Color.cyan;
|
||||||
|
|
||||||
|
private float flashTimer;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (engine == null) return;
|
||||||
|
|
||||||
|
// Wenn die Engine einen Beat erkennt...
|
||||||
|
if (engine.isBeat)
|
||||||
|
{
|
||||||
|
// ...aktualisieren wir SOFORT den Text mit der instantBpm
|
||||||
|
if (bpmText != null)
|
||||||
|
{
|
||||||
|
bpmText.text = engine.instantBpm.ToString("F0"); // "F0" für ganze Zahlen ohne Lag-Gefühl
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visueller Kick
|
||||||
|
flashTimer = 0.1f;
|
||||||
|
if (beatIndicator != null) beatIndicator.color = activeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timer für das Abklingen der LED
|
||||||
|
if (flashTimer > 0)
|
||||||
|
{
|
||||||
|
flashTimer -= Time.deltaTime;
|
||||||
|
if (flashTimer <= 0 && beatIndicator != null)
|
||||||
|
{
|
||||||
|
beatIndicator.color = new Color(0.1f, 0.1f, 0.1f, 1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,218 +0,0 @@
|
|||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Net.WebSockets;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
public class LiveSyncPanel : EditorWindow
|
|
||||||
{
|
|
||||||
private string wsUrl = "ws://localhost:8080";
|
|
||||||
private static ClientWebSocket ws;
|
|
||||||
private static bool isConnected = false;
|
|
||||||
private static CancellationTokenSource cts;
|
|
||||||
|
|
||||||
private Transform lastSelected;
|
|
||||||
private bool isNetworkApplying = false;
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
private class SyncMessage
|
|
||||||
{
|
|
||||||
public string type;
|
|
||||||
public string objectName;
|
|
||||||
public Vector3 position;
|
|
||||||
public Vector3 eulerAngles;
|
|
||||||
public Vector3 localScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MenuItem("Tools/MrUnknownDE/Live Sync Bridge")]
|
|
||||||
public static void ShowWindow()
|
|
||||||
{
|
|
||||||
GetWindow<LiveSyncPanel>("Live Sync Bridge").minSize = new Vector2(320, 350);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnEnable()
|
|
||||||
{
|
|
||||||
wsUrl = EditorPrefs.GetString("LiveSync_WS_URL", "ws://localhost:8080");
|
|
||||||
EditorApplication.update += EditorUpdate;
|
|
||||||
Selection.selectionChanged += OnSelectionChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDisable()
|
|
||||||
{
|
|
||||||
EditorApplication.update -= EditorUpdate;
|
|
||||||
Selection.selectionChanged -= OnSelectionChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGUI()
|
|
||||||
{
|
|
||||||
GUILayout.Space(5);
|
|
||||||
|
|
||||||
// --- 🚧 DICK & FETT: WIP WARNING 🚧 ---
|
|
||||||
EditorGUILayout.HelpBox(
|
|
||||||
"🚧 WORK IN PROGRESS 🚧\n\n" +
|
|
||||||
"This feature is highly experimental and in active development!\n" +
|
|
||||||
"Expect bugs, network desyncs, or unexpected behavior.\n\n" +
|
|
||||||
"ALWAYS backup your project before starting a Live Session!",
|
|
||||||
MessageType.Warning);
|
|
||||||
|
|
||||||
GUILayout.Space(10);
|
|
||||||
GUILayout.Label("REAL-TIME MULTI-USER SYNC", EditorStyles.boldLabel);
|
|
||||||
GUILayout.Space(10);
|
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
wsUrl = EditorGUILayout.TextField("WebSocket Server:", wsUrl);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
EditorPrefs.SetString("LiveSync_WS_URL", wsUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Space(15);
|
|
||||||
|
|
||||||
if (!isConnected)
|
|
||||||
{
|
|
||||||
GUI.backgroundColor = new Color(0.2f, 0.6f, 0.2f);
|
|
||||||
if (GUILayout.Button("🔌 Connect Session", GUILayout.Height(40))) Connect();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GUI.backgroundColor = new Color(0.8f, 0.3f, 0.3f);
|
|
||||||
if (GUILayout.Button("🛑 Disconnect", GUILayout.Height(40))) Disconnect();
|
|
||||||
|
|
||||||
GUILayout.Space(15);
|
|
||||||
EditorGUILayout.HelpBox("🟢 Connected!\nTransforms are tracked in real-time.\nListening for Git updates...", MessageType.Info);
|
|
||||||
}
|
|
||||||
GUI.backgroundColor = Color.white;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void Connect()
|
|
||||||
{
|
|
||||||
if (ws != null && ws.State == WebSocketState.Open) return;
|
|
||||||
|
|
||||||
ws = new ClientWebSocket();
|
|
||||||
cts = new CancellationTokenSource();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await ws.ConnectAsync(new Uri(wsUrl), cts.Token);
|
|
||||||
isConnected = true;
|
|
||||||
UnityEngine.Debug.Log("Live Sync: Connected to Server!");
|
|
||||||
|
|
||||||
_ = ReceiveLoop();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.LogError("Live Sync: Connection failed. Is the server running? " + e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void Disconnect()
|
|
||||||
{
|
|
||||||
if (ws != null)
|
|
||||||
{
|
|
||||||
cts?.Cancel();
|
|
||||||
if (ws.State == WebSocketState.Open) await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "Client disconnecting", CancellationToken.None);
|
|
||||||
ws.Dispose();
|
|
||||||
}
|
|
||||||
isConnected = false;
|
|
||||||
UnityEngine.Debug.Log("Live Sync: Disconnected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EditorUpdate()
|
|
||||||
{
|
|
||||||
if (!isConnected || isNetworkApplying) return;
|
|
||||||
|
|
||||||
if (lastSelected != null && lastSelected.hasChanged)
|
|
||||||
{
|
|
||||||
SyncMessage msg = new SyncMessage
|
|
||||||
{
|
|
||||||
type = "TRANSFORM",
|
|
||||||
objectName = lastSelected.name,
|
|
||||||
position = lastSelected.position,
|
|
||||||
eulerAngles = lastSelected.eulerAngles,
|
|
||||||
localScale = lastSelected.localScale
|
|
||||||
};
|
|
||||||
|
|
||||||
SendMessage(JsonUtility.ToJson(msg));
|
|
||||||
lastSelected.hasChanged = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSelectionChanged()
|
|
||||||
{
|
|
||||||
if (Selection.activeTransform != null)
|
|
||||||
{
|
|
||||||
lastSelected = Selection.activeTransform;
|
|
||||||
lastSelected.hasChanged = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void BroadcastGitUpdate()
|
|
||||||
{
|
|
||||||
if (!isConnected || ws == null || ws.State != WebSocketState.Open) return;
|
|
||||||
|
|
||||||
SyncMessage msg = new SyncMessage { type = "GIT_PULL" };
|
|
||||||
SendMessage(JsonUtility.ToJson(msg));
|
|
||||||
UnityEngine.Debug.Log("Live Sync: Broadcasted Git Update signal to team.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async void SendMessage(string json)
|
|
||||||
{
|
|
||||||
if (ws == null || ws.State != WebSocketState.Open) return;
|
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(json);
|
|
||||||
await ws.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, cts.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ReceiveLoop()
|
|
||||||
{
|
|
||||||
byte[] buffer = new byte[2048];
|
|
||||||
while (ws.State == WebSocketState.Open)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var result = await ws.ReceiveAsync(new ArraySegment<byte>(buffer), cts.Token);
|
|
||||||
if (result.MessageType == WebSocketMessageType.Text)
|
|
||||||
{
|
|
||||||
string json = Encoding.UTF8.GetString(buffer, 0, result.Count);
|
|
||||||
EditorApplication.delayCall += () => ProcessIncoming(json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch { break; }
|
|
||||||
}
|
|
||||||
isConnected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessIncoming(string json)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SyncMessage msg = JsonUtility.FromJson<SyncMessage>(json);
|
|
||||||
|
|
||||||
if (msg.type == "TRANSFORM")
|
|
||||||
{
|
|
||||||
GameObject target = GameObject.Find(msg.objectName);
|
|
||||||
if (target != null)
|
|
||||||
{
|
|
||||||
isNetworkApplying = true;
|
|
||||||
target.transform.position = msg.position;
|
|
||||||
target.transform.eulerAngles = msg.eulerAngles;
|
|
||||||
target.transform.localScale = msg.localScale;
|
|
||||||
target.transform.hasChanged = false;
|
|
||||||
isNetworkApplying = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (msg.type == "GIT_PULL")
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.LogWarning("Live Sync: Teammate pushed new files! Starting auto-pull...");
|
|
||||||
GitPanel.RunGitCommand("pull --rebase origin HEAD");
|
|
||||||
AssetDatabase.Refresh();
|
|
||||||
UnityEngine.Debug.Log("Live Sync: Auto-pull complete. Files updated.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.LogWarning("Live Sync: Failed to parse incoming message. " + e.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "de.mrunknownde.gittool.Editor",
|
|
||||||
"rootNamespace": "",
|
|
||||||
"references": [],
|
|
||||||
"includePlatforms": [
|
|
||||||
"Editor"
|
|
||||||
],
|
|
||||||
"excludePlatforms": [],
|
|
||||||
"allowUnsafeCode": false,
|
|
||||||
"overrideReferences": false,
|
|
||||||
"precompiledReferences": [],
|
|
||||||
"autoReferenced": true,
|
|
||||||
"defineConstraints": [],
|
|
||||||
"versionDefines": [],
|
|
||||||
"noEngineReferences": false
|
|
||||||
}
|
|
||||||
170
ProTV/ProTVRoomZone.asset
Normal file
170
ProTV/ProTVRoomZone.asset
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
|
||||||
|
m_Name: ProTVRoomZone
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
serializedUdonProgramAsset: {fileID: 11400000, guid: 7f1b25a7785724b4a80dabaacffcc775,
|
||||||
|
type: 2}
|
||||||
|
udonAssembly:
|
||||||
|
assemblyError:
|
||||||
|
sourceCsScript: {fileID: 11500000, guid: 48ee0805fb47e2e4494f694b970678c1, type: 3}
|
||||||
|
scriptVersion: 2
|
||||||
|
compiledVersion: 2
|
||||||
|
behaviourSyncMode: 0
|
||||||
|
hasInteractEvent: 0
|
||||||
|
scriptID: -2239841375030423733
|
||||||
|
serializationData:
|
||||||
|
SerializedFormat: 2
|
||||||
|
SerializedBytes:
|
||||||
|
ReferencedUnityObjects: []
|
||||||
|
SerializedBytesString:
|
||||||
|
Prefab: {fileID: 0}
|
||||||
|
PrefabModificationsReferencedUnityObjects: []
|
||||||
|
PrefabModifications: []
|
||||||
|
SerializationNodes:
|
||||||
|
- Name: fieldDefinitions
|
||||||
|
Entry: 7
|
||||||
|
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
|
||||||
|
UdonSharp.Editor]], mscorlib
|
||||||
|
- Name: comparer
|
||||||
|
Entry: 7
|
||||||
|
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
|
||||||
|
mscorlib]], mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 12
|
||||||
|
Data: 2
|
||||||
|
- Name:
|
||||||
|
Entry: 7
|
||||||
|
Data:
|
||||||
|
- Name: $k
|
||||||
|
Entry: 1
|
||||||
|
Data: localVideoPlayer
|
||||||
|
- Name: $v
|
||||||
|
Entry: 7
|
||||||
|
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||||
|
- Name: <Name>k__BackingField
|
||||||
|
Entry: 1
|
||||||
|
Data: localVideoPlayer
|
||||||
|
- Name: <UserType>k__BackingField
|
||||||
|
Entry: 7
|
||||||
|
Data: 3|System.RuntimeType, mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 1
|
||||||
|
Data: UnityEngine.GameObject, UnityEngine.CoreModule
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name: <SystemType>k__BackingField
|
||||||
|
Entry: 9
|
||||||
|
Data: 3
|
||||||
|
- Name: <SyncMode>k__BackingField
|
||||||
|
Entry: 7
|
||||||
|
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 6
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name: <IsSerialized>k__BackingField
|
||||||
|
Entry: 5
|
||||||
|
Data: true
|
||||||
|
- Name: _fieldAttributes
|
||||||
|
Entry: 7
|
||||||
|
Data: 4|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 12
|
||||||
|
Data: 1
|
||||||
|
- Name:
|
||||||
|
Entry: 7
|
||||||
|
Data: 5|UnityEngine.HeaderAttribute, UnityEngine.CoreModule
|
||||||
|
- Name: header
|
||||||
|
Entry: 1
|
||||||
|
Data: "Der Videoplayer f\xFCr diesen Raum"
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 13
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 7
|
||||||
|
Data:
|
||||||
|
- Name: $k
|
||||||
|
Entry: 1
|
||||||
|
Data: roomCollider
|
||||||
|
- Name: $v
|
||||||
|
Entry: 7
|
||||||
|
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||||
|
- Name: <Name>k__BackingField
|
||||||
|
Entry: 1
|
||||||
|
Data: roomCollider
|
||||||
|
- Name: <UserType>k__BackingField
|
||||||
|
Entry: 7
|
||||||
|
Data: 7|System.RuntimeType, mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 1
|
||||||
|
Data: UnityEngine.BoxCollider, UnityEngine.PhysicsModule
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name: <SystemType>k__BackingField
|
||||||
|
Entry: 9
|
||||||
|
Data: 7
|
||||||
|
- Name: <SyncMode>k__BackingField
|
||||||
|
Entry: 7
|
||||||
|
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 6
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name: <IsSerialized>k__BackingField
|
||||||
|
Entry: 5
|
||||||
|
Data: false
|
||||||
|
- Name: _fieldAttributes
|
||||||
|
Entry: 7
|
||||||
|
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||||
|
- Name:
|
||||||
|
Entry: 12
|
||||||
|
Data: 0
|
||||||
|
- Name:
|
||||||
|
Entry: 13
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 13
|
||||||
|
Data:
|
||||||
|
- Name:
|
||||||
|
Entry: 8
|
||||||
|
Data:
|
||||||
157
ProTV/ProTVRoomZone.cs
Normal file
157
ProTV/ProTVRoomZone.cs
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* ============================================================================
|
||||||
|
* ProTV Room Zone Manager
|
||||||
|
* ============================================================================
|
||||||
|
* Ein autarkes Trigger-Modul zur ressourcenschonenden Steuerung von
|
||||||
|
* ProTV / AVPro Instanzen in VRChat
|
||||||
|
*
|
||||||
|
* written by MrUnknownDE
|
||||||
|
* https://mrunknown.de
|
||||||
|
* ============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
using UdonSharp;
|
||||||
|
using UnityEngine;
|
||||||
|
using VRC.SDKBase;
|
||||||
|
using VRC.Udon;
|
||||||
|
|
||||||
|
public class ProTVRoomZone : UdonSharpBehaviour
|
||||||
|
{
|
||||||
|
[Header("Der Videoplayer für diesen Raum")]
|
||||||
|
public GameObject localVideoPlayer;
|
||||||
|
[Space(10)]
|
||||||
|
[Header("Fade Settings")]
|
||||||
|
[Tooltip("Wie lange soll das Ein-/Ausblenden in Sekunden dauern?")]
|
||||||
|
public float fadeDuration = 1.5f;
|
||||||
|
|
||||||
|
[Tooltip("Ziehe hier die AudioSources des ProTVs rein - damit die Lautstärke smooth gefadet wird.")]
|
||||||
|
public AudioSource[] audioSources;
|
||||||
|
|
||||||
|
private BoxCollider roomCollider;
|
||||||
|
private float fadeProgress = 0f;
|
||||||
|
private int fadeState = 0;
|
||||||
|
|
||||||
|
// Hier speichern wir die echte Lautstärke, bevor sie verfälscht wird
|
||||||
|
private float[] savedVolumes;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
roomCollider = GetComponent<BoxCollider>();
|
||||||
|
|
||||||
|
// Arrays initialisieren und Basis-Lautstärke beim Start sichern
|
||||||
|
if (audioSources != null && audioSources.Length > 0)
|
||||||
|
{
|
||||||
|
savedVolumes = new float[audioSources.Length];
|
||||||
|
for (int i = 0; i < audioSources.Length; i++)
|
||||||
|
{
|
||||||
|
if (audioSources[i] != null) savedVolumes[i] = audioSources[i].volume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SendCustomEventDelayedSeconds(nameof(CheckSpawnPosition), 2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckSpawnPosition()
|
||||||
|
{
|
||||||
|
VRCPlayerApi player = Networking.LocalPlayer;
|
||||||
|
if (!Utilities.IsValid(player)) return;
|
||||||
|
|
||||||
|
if (roomCollider != null && roomCollider.bounds.Contains(player.GetPosition()))
|
||||||
|
{
|
||||||
|
if (localVideoPlayer != null) localVideoPlayer.SetActive(true);
|
||||||
|
fadeProgress = 1f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateSavedVolumes();
|
||||||
|
|
||||||
|
if (localVideoPlayer != null) localVideoPlayer.SetActive(false);
|
||||||
|
fadeProgress = 0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnPlayerTriggerEnter(VRCPlayerApi player)
|
||||||
|
{
|
||||||
|
if (!Utilities.IsValid(player) || !player.isLocal) return;
|
||||||
|
if (localVideoPlayer != null) localVideoPlayer.SetActive(true);
|
||||||
|
fadeProgress = 0f;
|
||||||
|
fadeState = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnPlayerTriggerExit(VRCPlayerApi player)
|
||||||
|
{
|
||||||
|
if (!Utilities.IsValid(player) || !player.isLocal) return;
|
||||||
|
UpdateSavedVolumes();
|
||||||
|
fadeProgress = 1f;
|
||||||
|
fadeState = -1; // Starte Fade Out
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (fadeState == 0) return;
|
||||||
|
if (fadeState == 1) // FADE IN
|
||||||
|
{
|
||||||
|
fadeProgress += Time.deltaTime / fadeDuration;
|
||||||
|
if (fadeProgress >= 1f)
|
||||||
|
{
|
||||||
|
fadeProgress = 1f;
|
||||||
|
fadeState = 0;
|
||||||
|
}
|
||||||
|
ApplyFadedVolume();
|
||||||
|
}
|
||||||
|
else if (fadeState == -1) // FADE OUT
|
||||||
|
{
|
||||||
|
fadeProgress -= Time.deltaTime / fadeDuration;
|
||||||
|
if (fadeProgress <= 0f)
|
||||||
|
{
|
||||||
|
fadeProgress = 0f;
|
||||||
|
fadeState = 0;
|
||||||
|
|
||||||
|
// DER PRO-TV FIX:
|
||||||
|
RestoreOriginalVolume();
|
||||||
|
|
||||||
|
if (localVideoPlayer != null) localVideoPlayer.SetActive(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ApplyFadedVolume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateSavedVolumes()
|
||||||
|
{
|
||||||
|
if (audioSources == null) return;
|
||||||
|
for (int i = 0; i < audioSources.Length; i++)
|
||||||
|
{
|
||||||
|
if (audioSources[i] != null && audioSources[i].volume > 0.05f)
|
||||||
|
{
|
||||||
|
savedVolumes[i] = audioSources[i].volume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyFadedVolume()
|
||||||
|
{
|
||||||
|
if (audioSources == null || savedVolumes == null) return;
|
||||||
|
for (int i = 0; i < audioSources.Length; i++)
|
||||||
|
{
|
||||||
|
if (audioSources[i] != null)
|
||||||
|
{
|
||||||
|
audioSources[i].volume = savedVolumes[i] * fadeProgress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RestoreOriginalVolume()
|
||||||
|
{
|
||||||
|
if (audioSources == null || savedVolumes == null) return;
|
||||||
|
for (int i = 0; i < audioSources.Length; i++)
|
||||||
|
{
|
||||||
|
if (audioSources[i] != null)
|
||||||
|
{
|
||||||
|
audioSources[i].volume = savedVolumes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user