Skip to content

Commit

Permalink
Release 2.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Release Automat committed Aug 21, 2024
1 parent 60ff7cc commit 70d9427
Show file tree
Hide file tree
Showing 87 changed files with 17,111 additions and 6,427 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#if !COMPILER_UDONSHARP && UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using TLP.UdonUtils.Runtime.Common;
using TLP.UdonVoiceUtils.Runtime.Core;
using UdonSharp;
using UdonSharpEditor;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Serialization.OdinSerializer.Utilities;

namespace TLP.UdonVoiceUtils.Editor.Inspectors
{
Expand All @@ -17,13 +21,15 @@ public class PlayerAudioControllerEditor : UnityEditor.Editor
private readonly HashSet<PlayerAudioOverride> _relevantBehaviours =
new HashSet<PlayerAudioOverride>();

private const int RefreshInterval = 60;
private int _refreshCount;

public override void OnInspectorGUI() {
UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target);
DrawDefaultInspector();
}

public void OnSceneGUI() {
var playerAudioController = (PlayerAudioController)target;
if (!Utilities.IsValid(playerAudioController)) {
Debug.LogWarning($"{nameof(playerAudioController)} invalid");
return;
}

Expand All @@ -33,21 +39,14 @@ public void OnSceneGUI() {
case EventType.Repaint:
{
// draw lines to each connected element
_refreshCount = (_refreshCount + 1) % RefreshInterval;
if (_refreshCount == 0) {
UpdateRelevantBehaviours(playerAudioController);
}

UpdateRelevantBehaviours();

foreach (var playerAudioOverride in _relevantBehaviours) {
// TODO refactor redundant code
if (!playerAudioOverride) {
continue;
}

if (playerAudioOverride.PlayerAudioController != playerAudioController) {
continue;
}

var doorPosition = playerAudioOverride.transform.position;

Handles.color = Color.white;
Expand All @@ -73,22 +72,42 @@ public void OnSceneGUI() {
}
}

private void UpdateRelevantBehaviours(PlayerAudioController playerAudioController) {
private void UpdateRelevantBehaviours() {
_relevantBehaviours.Clear();

foreach (var udonBehaviour in Resources.FindObjectsOfTypeAll<UdonBehaviour>()) {
try {
foreach (var betterPlayerAudioOverride in udonBehaviour.gameObject
.GetComponents<PlayerAudioOverride>()) {
if (betterPlayerAudioOverride.PlayerAudioController == playerAudioController) {
_relevantBehaviours.Add(betterPlayerAudioOverride);
var rootGameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
Debug.Log($"Roots: {rootGameObjects.Count()}");

foreach (var rootGameObject in rootGameObjects) {
var udonBehaviours = rootGameObject.GetComponentsInChildren<UdonBehaviour>();
Debug.Log($"{rootGameObject.transform.GetPathInScene()}: {udonBehaviours.Count()}");

foreach (var udonBehaviour in udonBehaviours) {
try {
var udonSharpBehaviour = UdonSharpEditorUtility.GetProxyBehaviour(udonBehaviour);

if (!udonSharpBehaviour) {
Debug.LogWarning(
$"{udonBehaviour.GetComponentPathInScene()} has no backing {nameof(UdonSharpBehaviour)}");
continue;
}

var playerAudioOverride = (PlayerAudioOverride)udonSharpBehaviour;
if (!playerAudioOverride) {
Debug.LogWarning(
$"{udonSharpBehaviour.GetScriptPathInScene()} is no {nameof(PlayerAudioOverride)}");
continue;
}

_relevantBehaviours.Add(playerAudioOverride);
}
catch (Exception) {
// ignored
}
}
catch (Exception) {
// ignored
}
}

Debug.Log($"{nameof(_relevantBehaviours)}: {_relevantBehaviours.Count}");
}

private void HandleInput(Event guiEvent, UdonSharpBehaviour destination) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public void OnSceneGUI() {
// draw
DrawDoorInfo(voiceOverrideDoor);

if (Utilities.IsValid(voiceOverrideDoor.voiceOverrideRoom)) {
var roomPosition = voiceOverrideDoor.voiceOverrideRoom.transform.position;
if (Utilities.IsValid(voiceOverrideDoor.VoiceOverrideRoom)) {
var roomPosition = voiceOverrideDoor.VoiceOverrideRoom.transform.position;

Handles.color = Color.white;
Handles.DrawDottedLine(doorPosition, roomPosition, 2);

GUI.color = Color.white;
Handles.Label(roomPosition, voiceOverrideDoor.voiceOverrideRoom.gameObject.name);
Handles.Label(roomPosition, voiceOverrideDoor.VoiceOverrideRoom.gameObject.name);
}
}
break;
Expand All @@ -62,7 +62,7 @@ public static void DrawDoorInfo(VoiceOverrideDoor voiceOverrideDoor) {

var doorTransform = voiceOverrideDoor.transform;
var doorPosition = doorTransform.position;
var exitDirection = doorTransform.TransformDirection(voiceOverrideDoor.exitDirection).normalized;
var exitDirection = doorTransform.TransformDirection(voiceOverrideDoor.ExitDirection).normalized;


Handles.color = Color.red;
Expand Down Expand Up @@ -91,17 +91,17 @@ private void HandleInput(Event guiEvent, VoiceOverrideDoor voiceOverrideDoor) {
}

private void HandleLeftMouseDown(Vector3 mousePosition, VoiceOverrideDoor voiceOverrideDoor) {
if (Utilities.IsValid(voiceOverrideDoor.voiceOverrideRoom)) {
if (Utilities.IsValid(voiceOverrideDoor.VoiceOverrideRoom)) {
var roomGuiPosition =
HandleUtility.WorldToGUIPoint(voiceOverrideDoor.voiceOverrideRoom.transform.position);
HandleUtility.WorldToGUIPoint(voiceOverrideDoor.VoiceOverrideRoom.transform.position);
var mouseGuiPosition = HandleUtility.WorldToGUIPoint(mousePosition);
bool clickCloseToRoomGameObject = Vector2.Distance(roomGuiPosition, mouseGuiPosition) < 10f;
if (clickCloseToRoomGameObject) {
Selection.SetActiveObjectWithContext(
voiceOverrideDoor.voiceOverrideRoom.gameObject,
voiceOverrideDoor.voiceOverrideRoom
voiceOverrideDoor.VoiceOverrideRoom.gameObject,
voiceOverrideDoor.VoiceOverrideRoom
);
EditorGUIUtility.PingObject(voiceOverrideDoor.voiceOverrideRoom);
EditorGUIUtility.PingObject(voiceOverrideDoor.VoiceOverrideRoom);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void OnSceneGUI() {
// TODO refactor redundant code
var voiceOverrideDoor = udonSharpBehavior as VoiceOverrideDoor;
if (voiceOverrideDoor != null) {
if (voiceOverrideDoor.voiceOverrideRoom != voiceOverrideRoom) {
if (voiceOverrideDoor.VoiceOverrideRoom != voiceOverrideRoom) {
continue;
}

Expand Down Expand Up @@ -124,7 +124,7 @@ private void UpdateRelevantBehaviours(VoiceOverrideRoom voiceOverrideRoom) {

foreach (var udonBehaviour in Resources.FindObjectsOfTypeAll<UdonBehaviour>()) {
foreach (var betterPlayerAudioOverride in udonBehaviour.gameObject.GetComponents<VoiceOverrideDoor>()) {
if (betterPlayerAudioOverride.voiceOverrideRoom == voiceOverrideRoom) {
if (betterPlayerAudioOverride.VoiceOverrideRoom == voiceOverrideRoom) {
_relevantBehaviours.Add(betterPlayerAudioOverride);
}
}
Expand Down
Loading

0 comments on commit 70d9427

Please sign in to comment.