Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit fe58e9d

Browse files
committed
[Feature] reformat the code with #if
1 parent fa928ea commit fe58e9d

File tree

6 files changed

+39
-64
lines changed

6 files changed

+39
-64
lines changed

Runtime/gestures/binding.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ void _handlePointerEvent(PointerEvent evt) {
9494
if (hitTestResult != null ||
9595
evt is PointerHoverEvent ||
9696
evt is PointerAddedEvent ||
97-
evt is PointerRemovedEvent
98-
#if UNITY_EDITOR
99-
|| evt is PointerDragFromEditorHoverEvent
100-
|| evt is PointerDragFromEditorReleaseEvent
101-
#endif
97+
evt is PointerRemovedEvent ||
98+
evt is PointerDragFromEditorHoverEvent ||
99+
evt is PointerDragFromEditorReleaseEvent
102100
) {
103101
this.dispatchEvent(evt, hitTestResult);
104102
}
@@ -121,11 +119,9 @@ public void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult) {
121119
if (hitTestResult == null) {
122120
D.assert(evt is PointerHoverEvent ||
123121
evt is PointerAddedEvent ||
124-
evt is PointerRemovedEvent
125-
#if UNITY_EDITOR
126-
|| evt is PointerDragFromEditorHoverEvent
127-
|| evt is PointerDragFromEditorReleaseEvent
128-
#endif
122+
evt is PointerRemovedEvent ||
123+
evt is PointerDragFromEditorHoverEvent ||
124+
evt is PointerDragFromEditorReleaseEvent
129125
);
130126
try {
131127
this.pointerRouter.route(evt);

Runtime/gestures/events.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using Unity.UIWidgets.ui;
3-
#if UNITY_EDITOR
43
using Object = UnityEngine.Object;
5-
#endif
64

75
namespace Unity.UIWidgets.gestures {
86
public abstract class PointerEvent {
@@ -90,7 +88,6 @@ public PointerScrollEvent(
9088
}
9189
}
9290

93-
#if UNITY_EDITOR
9491
public class PointerDragFromEditorEnterEvent : PointerEvent {
9592
public PointerDragFromEditorEnterEvent(
9693
TimeSpan timeStamp,
@@ -198,7 +195,6 @@ public static PointerDragFromEditorReleaseEvent fromDragFromEditorEvent(PointerE
198195
);
199196
}
200197
}
201-
#endif
202198

203199
public class PointerHoverEvent : PointerEvent {
204200
public PointerHoverEvent(

Runtime/gestures/mouse_tracking.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ namespace Unity.UIWidgets.gestures {
1010

1111
public delegate void PointerExitEventListener(PointerExitEvent evt);
1212

13-
#if UNITY_EDITOR
1413
public delegate void PointerDragFromEditorEnterEventListener(PointerDragFromEditorEnterEvent evt);
1514

1615
public delegate void PointerDragFromEditorHoverEventListener(PointerDragFromEditorHoverEvent evt);
1716

1817
public delegate void PointerDragFromEditorExitEventListener(PointerDragFromEditorExitEvent evt);
1918

2019
public delegate void PointerDragFromEditorReleaseEventListener(PointerDragFromEditorReleaseEvent evt);
21-
#endif
2220

2321
/// The annotation object used to annotate layers that are interested in mouse
2422
/// movements.
@@ -27,24 +25,20 @@ public class MouseTrackerAnnotation {
2725
public MouseTrackerAnnotation(
2826
PointerEnterEventListener onEnter = null,
2927
PointerHoverEventListener onHover = null,
30-
PointerExitEventListener onExit = null
31-
#if UNITY_EDITOR
32-
, PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null
33-
, PointerDragFromEditorHoverEventListener onDragFromEditorHover = null
34-
, PointerDragFromEditorExitEventListener onDragFromEditorExit = null
35-
, PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
36-
#endif
28+
PointerExitEventListener onExit = null,
29+
PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null,
30+
PointerDragFromEditorHoverEventListener onDragFromEditorHover = null,
31+
PointerDragFromEditorExitEventListener onDragFromEditorExit = null,
32+
PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
3733
) {
3834
this.onEnter = onEnter;
3935
this.onHover = onHover;
4036
this.onExit = onExit;
4137

42-
#if UNITY_EDITOR
4338
this.onDragFromEditorEnter = onDragFromEditorEnter;
4439
this.onDragFromEditorHover = onDragFromEditorHover;
4540
this.onDragFromEditorExit = onDragFromEditorExit;
4641
this.onDragFromEditorRelease = onDragFromEditorRelease;
47-
#endif
4842
}
4943

5044
public readonly PointerEnterEventListener onEnter;
@@ -53,12 +47,10 @@ public MouseTrackerAnnotation(
5347

5448
public readonly PointerExitEventListener onExit;
5549

56-
#if UNITY_EDITOR
5750
public readonly PointerDragFromEditorEnterEventListener onDragFromEditorEnter;
5851
public readonly PointerDragFromEditorHoverEventListener onDragFromEditorHover;
5952
public readonly PointerDragFromEditorExitEventListener onDragFromEditorExit;
6053
public readonly PointerDragFromEditorReleaseEventListener onDragFromEditorRelease;
61-
#endif
6254

6355
public override string ToString() {
6456
return
@@ -82,11 +74,16 @@ public _TrackedAnnotation(
8274
public partial class MouseTracker {
8375
public MouseTracker(
8476
PointerRouter router,
85-
MouseDetectorAnnotationFinder annotationFinder) {
77+
MouseDetectorAnnotationFinder annotationFinder,
78+
bool inEditor = false
79+
) {
8680
router.addGlobalRoute(this._handleEvent);
8781
this.annotationFinder = annotationFinder;
82+
this.inEditor = inEditor;
8883
}
8984

85+
readonly bool inEditor;
86+
9087
readonly Dictionary<int, PointerEvent> _lastMouseEvent = new Dictionary<int, PointerEvent>();
9188

9289
public bool mouseIsConnected {
@@ -101,8 +98,11 @@ public bool mouseIsConnected {
10198
public void attachAnnotation(MouseTrackerAnnotation annotation) {
10299
this._trackedAnnotations[annotation] = new _TrackedAnnotation(annotation);
103100
this._scheduleMousePositionCheck();
101+
104102
#if UNITY_EDITOR
105-
this._scheduleDragFromEditorMousePositionCheck();
103+
if (this.inEditor) {
104+
this._scheduleDragFromEditorMousePositionCheck();
105+
}
106106
#endif
107107
}
108108

@@ -114,7 +114,7 @@ public void detachAnnotation(MouseTrackerAnnotation annotation) {
114114
PointerExitEvent.fromHoverEvent((PointerHoverEvent) this._lastMouseEvent[deviceId]));
115115
}
116116
#if UNITY_EDITOR
117-
if (annotation.onDragFromEditorExit != null) {
117+
if (this.inEditor && annotation.onDragFromEditorExit != null) {
118118
annotation.onDragFromEditorExit(
119119
PointerDragFromEditorExitEvent.fromDragFromEditorEvent(this._lastMouseEvent[deviceId]));
120120
#endif
@@ -162,7 +162,9 @@ evt is PointerHoverEvent ||
162162
}
163163

164164
#if UNITY_EDITOR
165-
this._handleDragFromEditorEvent(evt, deviceId);
165+
if (this.inEditor) {
166+
this._handleDragFromEditorEvent(evt, deviceId);
167+
}
166168
#endif
167169
}
168170

Runtime/rendering/proxy_box.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,13 +1941,11 @@ public RenderPointerListener(
19411941
HitTestBehavior behavior = HitTestBehavior.deferToChild,
19421942
RenderBox child = null
19431943

1944-
#if UNITY_EDITOR
19451944
// Drag & Drop
19461945
,PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter = null
19471946
,PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover = null
19481947
,PointerDragFromEditorExitEventListener onPointerDragFromEditorExit = null
19491948
,PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease = null
1950-
#endif
19511949
) : base(behavior: behavior, child: child) {
19521950
this.onPointerDown = onPointerDown;
19531951
this.onPointerMove = onPointerMove;
@@ -1959,39 +1957,32 @@ public RenderPointerListener(
19591957
this._onPointerHover = onPointerHover;
19601958
this._onPointerExit = onPointerExit;
19611959

1962-
#if UNITY_EDITOR
19631960
// Drag & Drop
19641961
this._onPointerDragFromEditorEnter = onPointerDragFromEditorEnter;
19651962
this._onPointerDragFromEditorHover = onPointerDragFromEditorHover;
19661963
this._onPointerDragFromEditorExit = onPointerDragFromEditorExit;
19671964
this._onPointerDragFromEditorRelease = onPointerDragFromEditorRelease;
1968-
#endif
19691965

19701966
if (this._onPointerEnter != null ||
19711967
this._onPointerHover != null ||
1972-
this._onPointerExit != null
1973-
#if UNITY_EDITOR
1974-
|| this._onPointerDragFromEditorEnter != null
1975-
|| this._onPointerDragFromEditorHover != null
1976-
|| this._onPointerDragFromEditorExit != null
1977-
|| this._onPointerDragFromEditorRelease != null
1978-
#endif
1968+
this._onPointerExit != null ||
1969+
this._onPointerDragFromEditorEnter != null ||
1970+
this._onPointerDragFromEditorHover != null ||
1971+
this._onPointerDragFromEditorExit != null ||
1972+
this._onPointerDragFromEditorRelease != null
19791973
) {
19801974
this._hoverAnnotation = new MouseTrackerAnnotation(
19811975
onEnter: this._onPointerEnter,
19821976
onHover: this._onPointerHover,
1983-
onExit: this._onPointerExit
1984-
#if UNITY_EDITOR
1985-
,onDragFromEditorEnter: this._onPointerDragFromEditorEnter
1986-
,onDragFromEditorHover: this._onPointerDragFromEditorHover
1987-
,onDragFromEditorExit: this._onPointerDragFromEditorExit
1988-
,onDragFromEditorRelease: this._onPointerDragFromEditorRelease
1989-
#endif
1977+
onExit: this._onPointerExit,
1978+
onDragFromEditorEnter: this._onPointerDragFromEditorEnter,
1979+
onDragFromEditorHover: this._onPointerDragFromEditorHover,
1980+
onDragFromEditorExit: this._onPointerDragFromEditorExit,
1981+
onDragFromEditorRelease: this._onPointerDragFromEditorRelease
19901982
);
19911983
}
19921984
}
19931985

1994-
#if UNITY_EDITOR
19951986
PointerDragFromEditorEnterEventListener _onPointerDragFromEditorEnter;
19961987

19971988
public PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter {
@@ -2039,7 +2030,6 @@ public PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease
20392030
}
20402031
}
20412032
}
2042-
#endif
20432033

20442034
public PointerEnterEventListener onPointerEnter {
20452035
get { return this._onPointerEnter; }

Runtime/ui/pointer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ public enum PointerChange {
1111
move,
1212
up,
1313
scroll,
14-
#if UNITY_EDITOR
1514
dragFromEditorMove, // Drag & Drop
1615
dragFromEditorRelease
17-
#endif
1816
}
1917

2018
public enum PointerDeviceKind {

Runtime/widgets/basic.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,13 +1977,11 @@ public Listener(
19771977
HitTestBehavior behavior = HitTestBehavior.deferToChild,
19781978
Widget child = null,
19791979

1980-
#if UNITY_EDITOR
19811980
// Drag & Drop
19821981
PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter = null,
19831982
PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover = null,
19841983
PointerDragFromEditorExitEventListener onPointerDragFromEditorExit = null,
19851984
PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease = null
1986-
#endif
19871985
) : base(key: key, child: child) {
19881986
this.onPointerDown = onPointerDown;
19891987
this.onPointerMove = onPointerMove;
@@ -1994,14 +1992,12 @@ public Listener(
19941992
this.onPointerEnter = onPointerEnter;
19951993
this.onPointerScroll = onPointerScroll;
19961994
this.behavior = behavior;
1997-
1998-
#if UNITY_EDITOR
1995+
19991996
// Drag & Drop
20001997
this.onPointerDragFromEditorEnter = onPointerDragFromEditorEnter;
20011998
this.onPointerDragFromEditorHover = onPointerDragFromEditorHover;
20021999
this.onPointerDragFromEditorExit = onPointerDragFromEditorExit;
20032000
this.onPointerDragFromEditorRelease = onPointerDragFromEditorRelease;
2004-
#endif
20052001
}
20062002

20072003
public readonly PointerDownEventListener onPointerDown;
@@ -2021,14 +2017,13 @@ public Listener(
20212017
public readonly PointerScrollEventListener onPointerScroll;
20222018

20232019
public readonly HitTestBehavior behavior;
2024-
2025-
#if UNITY_EDITOR
2020+
20262021
// Drag & Drop
20272022
public readonly PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter;
20282023
public readonly PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover;
20292024
public readonly PointerDragFromEditorExitEventListener onPointerDragFromEditorExit;
20302025
public readonly PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease;
2031-
#endif
2026+
20322027
public override RenderObject createRenderObject(BuildContext context) {
20332028
return new RenderPointerListener(
20342029
onPointerDown: this.onPointerDown,
@@ -2040,14 +2035,12 @@ public override RenderObject createRenderObject(BuildContext context) {
20402035
onPointerHover: this.onPointerHover,
20412036
onPointerScroll: this.onPointerScroll,
20422037
behavior: this.behavior,
2043-
2044-
#if UNITY_EDITOR
2038+
20452039
// Drag & Drop
20462040
onPointerDragFromEditorEnter: this.onPointerDragFromEditorEnter,
20472041
onPointerDragFromEditorHover: this.onPointerDragFromEditorHover,
20482042
onPointerDragFromEditorExit: this.onPointerDragFromEditorExit,
20492043
onPointerDragFromEditorRelease: this.onPointerDragFromEditorRelease
2050-
#endif
20512044
);
20522045
}
20532046

0 commit comments

Comments
 (0)