Skip to content

Commit

Permalink
Release 1.0.0-rc.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Release Automat committed May 3, 2024
1 parent 59ff136 commit 80303c6
Show file tree
Hide file tree
Showing 60 changed files with 4,875 additions and 3,364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,36 @@ namespace TLP.UdonVoiceUtils.Editor.Inspectors
public class PlayerAudioControllerEditor : UnityEditor.Editor
{
private readonly HashSet<PlayerAudioOverride> _relevantBehaviours =
new HashSet<PlayerAudioOverride>();
new HashSet<PlayerAudioOverride>();

private const int RefreshInterval = 60;
private int _refreshCount;


public void OnSceneGUI()
{
public void OnSceneGUI() {
var playerAudioController = (PlayerAudioController)target;
if (!Utilities.IsValid(playerAudioController))
{
if (!Utilities.IsValid(playerAudioController)) {
return;
}

var guiEvent = Event.current;

switch (guiEvent.type)
{
switch (guiEvent.type) {
case EventType.Repaint:
{
// draw lines to each connected element
_refreshCount = (_refreshCount + 1) % RefreshInterval;
if (_refreshCount == 0)
{
if (_refreshCount == 0) {
UpdateRelevantBehaviours(playerAudioController);
}

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

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

Expand All @@ -71,64 +64,53 @@ public void OnSceneGUI()
break;
default:
{
foreach (var udonSharpBehaviour in _relevantBehaviours)
{
foreach (var udonSharpBehaviour in _relevantBehaviours) {
HandleInput(guiEvent, udonSharpBehaviour);
}
}
break;
}
}

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

foreach (var udonBehaviour in Resources.FindObjectsOfTypeAll<UdonBehaviour>())
{
try
{
foreach (var udonBehaviour in Resources.FindObjectsOfTypeAll<UdonBehaviour>()) {
try {
foreach (var betterPlayerAudioOverride in udonBehaviour.gameObject
.GetComponents<PlayerAudioOverride>())
{
if (betterPlayerAudioOverride.PlayerAudioController == playerAudioController)
{
.GetComponents<PlayerAudioOverride>()) {
if (betterPlayerAudioOverride.PlayerAudioController == playerAudioController) {
_relevantBehaviours.Add(betterPlayerAudioOverride);
}
}
}
catch (Exception)
{
catch (Exception) {
// ignored
}
}
}

private void HandleInput(Event guiEvent, UdonSharpBehaviour destination)
{
private void HandleInput(Event guiEvent, UdonSharpBehaviour destination) {
var mouseRay = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);
float drawPlaneHeight = 0;
float dstToDrawPlane = (drawPlaneHeight - mouseRay.origin.y) / mouseRay.direction.y;
var mousePosition = mouseRay.GetPoint(dstToDrawPlane);

if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 &&
guiEvent.modifiers == EventModifiers.None)
{
guiEvent.modifiers == EventModifiers.None) {
HandleLeftMouseDown(mousePosition, destination);
}
}

private void HandleLeftMouseDown(Vector3 mousePosition, UdonSharpBehaviour destination)
{
private void HandleLeftMouseDown(Vector3 mousePosition, UdonSharpBehaviour destination) {
var roomGuiPosition =
HandleUtility.WorldToGUIPoint(destination.transform.position);
HandleUtility.WorldToGUIPoint(destination.transform.position);
var mouseGuiPosition = HandleUtility.WorldToGUIPoint(mousePosition);
bool clickCloseToDestinationGameObject = Vector2.Distance(roomGuiPosition, mouseGuiPosition) < 10f;
if (clickCloseToDestinationGameObject)
{
if (clickCloseToDestinationGameObject) {
Selection.SetActiveObjectWithContext(
destination.gameObject,
destination
destination.gameObject,
destination
);
EditorGUIUtility.PingObject(destination);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ namespace TLP.UdonVoiceUtils.Editor.Inspectors
[CustomEditor(typeof(VoiceOverrideDoor))]
public class VoiceOverrideDoorEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
public override void OnInspectorGUI() {
UdonSharpGUI.DrawDefaultUdonSharpBehaviourHeader(target);
DrawDefaultInspector();
}

public void OnSceneGUI()
{
public void OnSceneGUI() {
var voiceOverrideDoor = (VoiceOverrideDoor)target;
if (!Utilities.IsValid(voiceOverrideDoor))
{
if (!Utilities.IsValid(voiceOverrideDoor)) {
return;
}

Expand All @@ -28,15 +25,13 @@ public void OnSceneGUI()

var guiEvent = Event.current;

switch (guiEvent.type)
{
switch (guiEvent.type) {
case EventType.Repaint:
{
// draw
DrawDoorInfo(voiceOverrideDoor);

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

Handles.color = Color.white;
Expand All @@ -60,10 +55,8 @@ public void OnSceneGUI()
}
}

public static void DrawDoorInfo(VoiceOverrideDoor voiceOverrideDoor)
{
if (!voiceOverrideDoor)
{
public static void DrawDoorInfo(VoiceOverrideDoor voiceOverrideDoor) {
if (!voiceOverrideDoor) {
return;
}

Expand All @@ -85,33 +78,28 @@ public static void DrawDoorInfo(VoiceOverrideDoor voiceOverrideDoor)
Handles.Label(doorPosition - exitDirection, "Inside");
}

private void HandleInput(Event guiEvent, VoiceOverrideDoor voiceOverrideDoor)
{
private void HandleInput(Event guiEvent, VoiceOverrideDoor voiceOverrideDoor) {
var mouseRay = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);
float drawPlaneHeight = 0;
float dstToDrawPlane = (drawPlaneHeight - mouseRay.origin.y) / mouseRay.direction.y;
var mousePosition = mouseRay.GetPoint(dstToDrawPlane);

if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 &&
guiEvent.modifiers == EventModifiers.None)
{
guiEvent.modifiers == EventModifiers.None) {
HandleLeftMouseDown(mousePosition, voiceOverrideDoor);
}
}

private void HandleLeftMouseDown(Vector3 mousePosition, VoiceOverrideDoor voiceOverrideDoor)
{
if (Utilities.IsValid(voiceOverrideDoor.voiceOverrideRoom))
{
private void HandleLeftMouseDown(Vector3 mousePosition, VoiceOverrideDoor voiceOverrideDoor) {
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)
{
if (clickCloseToRoomGameObject) {
Selection.SetActiveObjectWithContext(
voiceOverrideDoor.voiceOverrideRoom.gameObject,
voiceOverrideDoor.voiceOverrideRoom
voiceOverrideDoor.voiceOverrideRoom.gameObject,
voiceOverrideDoor.voiceOverrideRoom
);
EditorGUIUtility.PingObject(voiceOverrideDoor.voiceOverrideRoom);
}
Expand Down
Loading

0 comments on commit 80303c6

Please sign in to comment.