浏览代码

[Format] Surround Drag&Drop feature with #if pair

/main
iizzaya 5 年前
当前提交
beb230fa
共有 8 个文件被更改,包括 129 次插入93 次删除
  1. 56
      Runtime/editor/editor_mouse_tracking.cs
  2. 17
      Runtime/gestures/binding.cs
  3. 2
      Runtime/gestures/converter.cs
  4. 21
      Runtime/gestures/events.cs
  5. 17
      Runtime/gestures/mouse_tracking.cs
  6. 94
      Runtime/rendering/proxy_box.cs
  7. 2
      Runtime/ui/pointer.cs
  8. 13
      Runtime/widgets/basic.cs

56
Runtime/editor/editor_mouse_tracking.cs


using UnityEditor;
namespace Unity.UIWidgets.gestures {
#if UNITY_EDITOR
public partial class MouseTracker {
bool _enableDragFromEditorRelease = false;

evt is PointerDragFromEditorExitEvent) {
if (!this._lastMouseEvent.ContainsKey(deviceId) ||
this._lastMouseEvent[deviceId].position != evt.position) {
// Only schedule a frame if we have our first event, or if the
// location of the mouse has changed, and only if there are tracked annotations.
this._scheduleDragFromEditorMousePositionCheck();
}

void _scheduleDragFromEditorReleaseCheck() {
DragAndDrop.AcceptDrag();
var lastMouseEvent = new List<(PointerEvent, int)>();
var lastMouseEvent = new List<PointerEvent>();
lastMouseEvent.Add((this._lastMouseEvent[deviceId], deviceId));
}
var _deviceId = deviceId;
lastMouseEvent.Add(this._lastMouseEvent[_deviceId]);
SchedulerBinding.instance.addPostFrameCallback(_ => {
foreach (var lastEvent in lastMouseEvent) {
MouseTrackerAnnotation hit = this.annotationFinder(lastEvent.position);
SchedulerBinding.instance.addPostFrameCallback(_ => {
foreach (var lastEvent in lastMouseEvent) {
MouseTrackerAnnotation hit = this.annotationFinder(lastEvent.Item1.position);
if (hit == null) {
foreach (_TrackedAnnotation trackedAnnotation in this._trackedAnnotations.Values) {
if (trackedAnnotation.activeDevices.Contains(_deviceId)) {
trackedAnnotation.activeDevices.Remove(_deviceId);
}
}
if (hit == null) {
foreach (_TrackedAnnotation trackedAnnotation in this._trackedAnnotations.Values) {
if (trackedAnnotation.activeDevices.Contains(lastEvent.Item2)) {
trackedAnnotation.activeDevices.Remove(lastEvent.Item2);
}
return;
return;
}
_TrackedAnnotation hitAnnotation = this._findAnnotation(hit);
_TrackedAnnotation hitAnnotation = this._findAnnotation(hit);
// release
if (hitAnnotation.activeDevices.Contains(_deviceId)) {
if (hitAnnotation.annotation?.onDragFromEditorRelease != null) {
hitAnnotation.annotation.onDragFromEditorRelease(
PointerDragFromEditorReleaseEvent
.fromDragFromEditorEvent(
lastEvent, DragAndDrop.objectReferences));
}
// release
if (hitAnnotation.activeDevices.Contains(lastEvent.Item2)) {
if (hitAnnotation.annotation?.onDragFromEditorRelease != null) {
hitAnnotation.annotation.onDragFromEditorRelease(
PointerDragFromEditorReleaseEvent
.fromDragFromEditorEvent(
lastEvent.Item1, DragAndDrop.objectReferences));
hitAnnotation.activeDevices.Remove(_deviceId);
}
});
}
hitAnnotation.activeDevices.Remove(lastEvent.Item2);
}
}
});
SchedulerBinding.instance.scheduleFrame();
}

}
}
}
#endif
}

17
Runtime/gestures/binding.cs


if (hitTestResult != null ||
evt is PointerHoverEvent ||
evt is PointerAddedEvent ||
evt is PointerRemovedEvent ||
evt is PointerDragFromEditorHoverEvent ||
evt is PointerDragFromEditorReleaseEvent
evt is PointerRemovedEvent
#if UNITY_EDITOR
|| evt is PointerDragFromEditorHoverEvent
|| evt is PointerDragFromEditorReleaseEvent
#endif
) {
this.dispatchEvent(evt, hitTestResult);
}

if (hitTestResult == null) {
D.assert(evt is PointerHoverEvent ||
evt is PointerAddedEvent ||
evt is PointerRemovedEvent ||
evt is PointerDragFromEditorHoverEvent ||
evt is PointerDragFromEditorReleaseEvent);
evt is PointerRemovedEvent
#if UNITY_EDITOR
|| evt is PointerDragFromEditorHoverEvent
|| evt is PointerDragFromEditorReleaseEvent
#endif
);
try {
this.pointerRouter.route(evt);
}

2
Runtime/gestures/converter.cs


}
}
break;
#if UNITY_EDITOR
case PointerChange.dragFromEditorMove: {
_PointerState state = _ensureStateForPointer(datum, position);
state.startNewPointer();

);
}
break;
#endif
}
}
}

21
Runtime/gestures/events.cs


using System;
using Unity.UIWidgets.ui;
#if UNITY_EDITOR
#endif
namespace Unity.UIWidgets.gestures {
public abstract class PointerEvent {

delta: delta) {
}
}
#if UNITY_EDITOR
public class PointerDragFromEditorEnterEvent : PointerEvent {
public PointerDragFromEditorEnterEvent(
TimeSpan timeStamp,

);
}
}
public class PointerDragFromEditorFailedEvent : PointerEvent {
public PointerDragFromEditorFailedEvent(
TimeSpan timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null
) : base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position
) { }
}
#endif
public class PointerHoverEvent : PointerEvent {
public PointerHoverEvent(

17
Runtime/gestures/mouse_tracking.cs


public MouseTrackerAnnotation(
PointerEnterEventListener onEnter = null,
PointerHoverEventListener onHover = null,
PointerExitEventListener onExit = null,
PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null,
PointerDragFromEditorHoverEventListener onDragFromEditorHover = null,
PointerDragFromEditorExitEventListener onDragFromEditorExit = null,
PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
PointerExitEventListener onExit = null
#if UNITY_EDITOR
, PointerDragFromEditorEnterEventListener onDragFromEditorEnter = null
, PointerDragFromEditorHoverEventListener onDragFromEditorHover = null
, PointerDragFromEditorExitEventListener onDragFromEditorExit = null
, PointerDragFromEditorReleaseEventListener onDragFromEditorRelease = null
#endif
#if UNITY_EDITOR
#endif
}
public readonly PointerEnterEventListener onEnter;

public readonly PointerExitEventListener onExit;
#if UNITY_EDITOR
#endif
public override string ToString() {
return

trackedAnnotation.annotation.onExit(
PointerExitEvent.fromHoverEvent(this._lastMouseEvent[deviceId]));
}
trackedAnnotation.activeDevices.Remove(deviceId);
}
}

94
Runtime/rendering/proxy_box.cs


PointerCancelEventListener onPointerCancel = null,
PointerScrollEventListener onPointerScroll = null,
HitTestBehavior behavior = HitTestBehavior.deferToChild,
RenderBox child = null,
RenderBox child = null
#if UNITY_EDITOR
PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter = null,
PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover = null,
PointerDragFromEditorExitEventListener onPointerDragFromEditorExit = null,
PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease = null
,PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter = null
,PointerDragFromEditorHoverEventListener onPointerDragFromEditorHover = null
,PointerDragFromEditorExitEventListener onPointerDragFromEditorExit = null
,PointerDragFromEditorReleaseEventListener onPointerDragFromEditorRelease = null
#endif
) : base(behavior: behavior, child: child) {
this.onPointerDown = onPointerDown;
this.onPointerMove = onPointerMove;

this._onPointerEnter = onPointerEnter;
this._onPointerHover = onPointerHover;
this._onPointerExit = onPointerExit;
#if UNITY_EDITOR
#endif
this._onPointerExit != null ||
this._onPointerDragFromEditorEnter != null ||
this._onPointerDragFromEditorHover != null ||
this._onPointerDragFromEditorExit != null ||
this._onPointerDragFromEditorRelease != null) {
this._onPointerExit != null
#if UNITY_EDITOR
|| this._onPointerDragFromEditorEnter != null
|| this._onPointerDragFromEditorHover != null
|| this._onPointerDragFromEditorExit != null
|| this._onPointerDragFromEditorRelease != null
#endif
) {
onExit: this._onPointerExit,
onDragFromEditorEnter: this._onPointerDragFromEditorEnter,
onDragFromEditorHover: this._onPointerDragFromEditorHover,
onDragFromEditorExit: this._onPointerDragFromEditorExit,
onDragFromEditorRelease: this._onPointerDragFromEditorRelease
onExit: this._onPointerExit
#if UNITY_EDITOR
,onDragFromEditorEnter: this._onPointerDragFromEditorEnter
,onDragFromEditorHover: this._onPointerDragFromEditorHover
,onDragFromEditorExit: this._onPointerDragFromEditorExit
,onDragFromEditorRelease: this._onPointerDragFromEditorRelease
#endif
public PointerDownEventListener onPointerDown;
public PointerMoveEventListener onPointerMove;
#if UNITY_EDITOR
PointerDragFromEditorEnterEventListener _onPointerDragFromEditorEnter;
public PointerDragFromEditorEnterEventListener onPointerDragFromEditorEnter {

}
}
}
#endif
public PointerEnterEventListener onPointerEnter {
get { return this._onPointerEnter; }

PointerExitEventListener _onPointerExit;
public PointerDownEventListener onPointerDown;
public PointerMoveEventListener onPointerMove;
public PointerUpEventListener onPointerUp;
public PointerCancelEventListener onPointerCancel;

void _updateAnnotations() {
D.assert(this._onPointerEnter != this._hoverAnnotation.onEnter ||
this._onPointerHover != this._hoverAnnotation.onHover ||
this._onPointerExit != this._hoverAnnotation.onExit ||
this._onPointerDragFromEditorEnter != this._hoverAnnotation.onDragFromEditorEnter ||
this._onPointerDragFromEditorHover != this._hoverAnnotation.onDragFromEditorHover ||
this._onPointerDragFromEditorExit != this._hoverAnnotation.onDragFromEditorExit ||
this._onPointerDragFromEditorRelease != this._hoverAnnotation.onDragFromEditorRelease,
() => "Shouldn't call _updateAnnotations if nothing has changed.");
this._onPointerExit != this._hoverAnnotation.onExit
#if UNITY_EDITOR
|| this._onPointerDragFromEditorEnter != this._hoverAnnotation.onDragFromEditorEnter
|| this._onPointerDragFromEditorHover != this._hoverAnnotation.onDragFromEditorHover
|| this._onPointerDragFromEditorExit != this._hoverAnnotation.onDragFromEditorExit
|| this._onPointerDragFromEditorRelease != this._hoverAnnotation.onDragFromEditorRelease
#endif
, () => "Shouldn't call _updateAnnotations if nothing has changed.");
if (this._hoverAnnotation != null && this.attached) {
RendererBinding.instance.mouseTracker.detachAnnotation(this._hoverAnnotation);

this._onPointerHover != null ||
this._onPointerExit != null ||
this._onPointerDragFromEditorEnter != null ||
this._onPointerDragFromEditorHover != null ||
this._onPointerDragFromEditorExit != null ||
this._onPointerDragFromEditorRelease != null) {
this._onPointerExit != null
#if UNITY_EDITOR
|| this._onPointerDragFromEditorEnter != null
|| this._onPointerDragFromEditorHover != null
|| this._onPointerDragFromEditorExit != null
|| this._onPointerDragFromEditorRelease != null
#endif
) {
onExit: this._onPointerExit,
onDragFromEditorEnter: this._onPointerDragFromEditorEnter,
onDragFromEditorHover: this._onPointerDragFromEditorHover,
onDragFromEditorExit: this._onPointerDragFromEditorExit,
onDragFromEditorRelease: this._onPointerDragFromEditorRelease
onExit: this._onPointerExit
#if UNITY_EDITOR
, onDragFromEditorEnter: this._onPointerDragFromEditorEnter
, onDragFromEditorHover: this._onPointerDragFromEditorHover
, onDragFromEditorExit: this._onPointerDragFromEditorExit
, onDragFromEditorRelease: this._onPointerDragFromEditorRelease
#endif
);
if (this.attached) {

2
Runtime/ui/pointer.cs


move,
up,
scroll,
#if UNITY_EDITOR
#endif
}
public enum PointerDeviceKind {

13
Runtime/widgets/basic.cs


HitTestBehavior behavior = HitTestBehavior.deferToChild,
Widget child = null,
#if UNITY_EDITOR
#endif
) : base(key: key, child: child) {
this.onPointerDown = onPointerDown;
this.onPointerMove = onPointerMove;

this.onPointerScroll = onPointerScroll;
this.behavior = behavior;
#if UNITY_EDITOR
#endif
}
public readonly PointerDownEventListener onPointerDown;

public readonly HitTestBehavior behavior;
#if UNITY_EDITOR
#endif
public override RenderObject createRenderObject(BuildContext context) {
return new RenderPointerListener(
onPointerDown: this.onPointerDown,

onPointerScroll: this.onPointerScroll,
behavior: this.behavior,
#if UNITY_EDITOR
#endif
);
}

renderObject.onPointerScroll = this.onPointerScroll;
renderObject.behavior = this.behavior;
#if UNITY_EDITOR
#endif
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {

listeners.Add("scroll");
}
#if UNITY_EDITOR
#endif
properties.add(new EnumerableProperty<string>("listeners", listeners, ifEmpty: "<none>"));
properties.add(new EnumProperty<HitTestBehavior>("behavior", this.behavior));

正在加载...
取消
保存