6
6
// Should warn about not having a canvas or parent canvas assigned.
7
7
// Should warn about ray-casted UI consuming events.
8
8
9
-
9
+ /// <summary>
10
+ /// A passive UI visualization of an on-screen control in Unity UI (UGUI).
11
+ /// </summary>
10
12
[ ExecuteInEditMode ]
11
13
public class OnScreenControlUI : MonoBehaviour
12
14
{
@@ -17,41 +19,6 @@ public class OnScreenControlUI : MonoBehaviour
17
19
public RectTransform bounds ;
18
20
public RectTransform knob ;
19
21
20
- private void OnDrawGizmosSelected ( )
21
- {
22
- // This will not produce meaningful results unless we have a rect transform (ISXB-915, ISXB-916).
23
- var parentRectTransform = transform . parent as RectTransform ;
24
- if ( parentRectTransform == null )
25
- return ;
26
-
27
- Gizmos . matrix = parentRectTransform . localToWorldMatrix ;
28
-
29
- var startPos = parentRectTransform . anchoredPosition ;
30
-
31
- /*var startPos = parentRectTransform.anchoredPosition;
32
- if (Application.isPlaying)
33
- startPos = m_StartPos;
34
- */
35
- Gizmos . color = new Color32 ( 84 , 173 , 219 , 255 ) ;
36
-
37
- var center = startPos ;
38
- /*if (Application.isPlaying && m_Behaviour == Behaviour.ExactPositionWithDynamicOrigin)
39
- center = m_PointerDownPos;*/
40
-
41
- var radius = UnitConverter . MillimetersToPixels ( control . stickRadiusMillimeters ) ;
42
- ScreenGizmos . DrawGizmoCircle ( center , radius ) ;
43
-
44
- //if (m_Behaviour != Behaviour.ExactPositionWithDynamicOrigin) return;
45
-
46
- //Gizmos.color = new Color32(158, 84, 219, 255);
47
- //DrawGizmoCircle(startPos, m_DynamicOriginRange);
48
- }
49
-
50
- // Start is called once before the first execution of Update after the MonoBehaviour is created
51
- void Start ( )
52
- {
53
- }
54
-
55
22
void OnEnable ( )
56
23
{
57
24
if ( canvas == null )
@@ -118,8 +85,11 @@ void Update()
118
85
var stickRadiusPixels = UnitConverter . MillimetersToPixels ( control . stickRadiusMillimeters ) ;
119
86
var stickCenter = control . stickCenter ;
120
87
var stickViewport = camera . ScreenToViewportPoint ( new Vector2 ( stickRadiusPixels , stickRadiusPixels ) ) ;
121
- var stickRect = new Rect ( stickCenter . x - stickViewport . x ,
122
- stickCenter . y - stickViewport . y , stickViewport . x * 2 , stickViewport . y * 2 ) ;
88
+ var stickRect = new Rect (
89
+ x : stickCenter . x - stickViewport . x ,
90
+ y : stickCenter . y - stickViewport . y ,
91
+ width : stickViewport . x * 2 ,
92
+ height : stickViewport . y * 2 ) ;
123
93
124
94
// Optionally transform a UI object to represent the interactable area in viewport space.
125
95
if ( area != null )
0 commit comments