@@ -14,43 +14,36 @@ namespace TLP.UdonVoiceUtils.Editor.Inspectors
14
14
public class PlayerAudioControllerEditor : UnityEditor . Editor
15
15
{
16
16
private readonly HashSet < PlayerAudioOverride > _relevantBehaviours =
17
- new HashSet < PlayerAudioOverride > ( ) ;
17
+ new HashSet < PlayerAudioOverride > ( ) ;
18
18
19
19
private const int RefreshInterval = 60 ;
20
20
private int _refreshCount ;
21
21
22
22
23
- public void OnSceneGUI ( )
24
- {
23
+ public void OnSceneGUI ( ) {
25
24
var playerAudioController = ( PlayerAudioController ) target ;
26
- if ( ! Utilities . IsValid ( playerAudioController ) )
27
- {
25
+ if ( ! Utilities . IsValid ( playerAudioController ) ) {
28
26
return ;
29
27
}
30
28
31
29
var guiEvent = Event . current ;
32
30
33
- switch ( guiEvent . type )
34
- {
31
+ switch ( guiEvent . type ) {
35
32
case EventType . Repaint :
36
33
{
37
34
// draw lines to each connected element
38
35
_refreshCount = ( _refreshCount + 1 ) % RefreshInterval ;
39
- if ( _refreshCount == 0 )
40
- {
36
+ if ( _refreshCount == 0 ) {
41
37
UpdateRelevantBehaviours ( playerAudioController ) ;
42
38
}
43
39
44
- foreach ( var playerAudioOverride in _relevantBehaviours )
45
- {
40
+ foreach ( var playerAudioOverride in _relevantBehaviours ) {
46
41
// TODO refactor redundant code
47
- if ( ! playerAudioOverride )
48
- {
42
+ if ( ! playerAudioOverride ) {
49
43
continue ;
50
44
}
51
45
52
- if ( playerAudioOverride . PlayerAudioController != playerAudioController )
53
- {
46
+ if ( playerAudioOverride . PlayerAudioController != playerAudioController ) {
54
47
continue ;
55
48
}
56
49
@@ -71,64 +64,53 @@ public void OnSceneGUI()
71
64
break ;
72
65
default :
73
66
{
74
- foreach ( var udonSharpBehaviour in _relevantBehaviours )
75
- {
67
+ foreach ( var udonSharpBehaviour in _relevantBehaviours ) {
76
68
HandleInput ( guiEvent , udonSharpBehaviour ) ;
77
69
}
78
70
}
79
71
break ;
80
72
}
81
73
}
82
74
83
- private void UpdateRelevantBehaviours ( PlayerAudioController playerAudioController )
84
- {
75
+ private void UpdateRelevantBehaviours ( PlayerAudioController playerAudioController ) {
85
76
_relevantBehaviours . Clear ( ) ;
86
77
87
- foreach ( var udonBehaviour in Resources . FindObjectsOfTypeAll < UdonBehaviour > ( ) )
88
- {
89
- try
90
- {
78
+ foreach ( var udonBehaviour in Resources . FindObjectsOfTypeAll < UdonBehaviour > ( ) ) {
79
+ try {
91
80
foreach ( var betterPlayerAudioOverride in udonBehaviour . gameObject
92
- . GetComponents < PlayerAudioOverride > ( ) )
93
- {
94
- if ( betterPlayerAudioOverride . PlayerAudioController == playerAudioController )
95
- {
81
+ . GetComponents < PlayerAudioOverride > ( ) ) {
82
+ if ( betterPlayerAudioOverride . PlayerAudioController == playerAudioController ) {
96
83
_relevantBehaviours . Add ( betterPlayerAudioOverride ) ;
97
84
}
98
85
}
99
86
}
100
- catch ( Exception )
101
- {
87
+ catch ( Exception ) {
102
88
// ignored
103
89
}
104
90
}
105
91
}
106
92
107
- private void HandleInput ( Event guiEvent , UdonSharpBehaviour destination )
108
- {
93
+ private void HandleInput ( Event guiEvent , UdonSharpBehaviour destination ) {
109
94
var mouseRay = HandleUtility . GUIPointToWorldRay ( guiEvent . mousePosition ) ;
110
95
float drawPlaneHeight = 0 ;
111
96
float dstToDrawPlane = ( drawPlaneHeight - mouseRay . origin . y ) / mouseRay . direction . y ;
112
97
var mousePosition = mouseRay . GetPoint ( dstToDrawPlane ) ;
113
98
114
99
if ( guiEvent . type == EventType . MouseDown && guiEvent . button == 0 &&
115
- guiEvent . modifiers == EventModifiers . None )
116
- {
100
+ guiEvent . modifiers == EventModifiers . None ) {
117
101
HandleLeftMouseDown ( mousePosition , destination ) ;
118
102
}
119
103
}
120
104
121
- private void HandleLeftMouseDown ( Vector3 mousePosition , UdonSharpBehaviour destination )
122
- {
105
+ private void HandleLeftMouseDown ( Vector3 mousePosition , UdonSharpBehaviour destination ) {
123
106
var roomGuiPosition =
124
- HandleUtility . WorldToGUIPoint ( destination . transform . position ) ;
107
+ HandleUtility . WorldToGUIPoint ( destination . transform . position ) ;
125
108
var mouseGuiPosition = HandleUtility . WorldToGUIPoint ( mousePosition ) ;
126
109
bool clickCloseToDestinationGameObject = Vector2 . Distance ( roomGuiPosition , mouseGuiPosition ) < 10f ;
127
- if ( clickCloseToDestinationGameObject )
128
- {
110
+ if ( clickCloseToDestinationGameObject ) {
129
111
Selection . SetActiveObjectWithContext (
130
- destination . gameObject ,
131
- destination
112
+ destination . gameObject ,
113
+ destination
132
114
) ;
133
115
EditorGUIUtility . PingObject ( destination ) ;
134
116
}
0 commit comments