Exemple #1
0
        void _scheduleDragFromEditorReleaseCheck()
        {
            DragAndDrop.AcceptDrag();

            var lastMouseEvent = new List <PointerEvent>();

            foreach (int deviceId in _lastMouseEvent.Keys)
            {
                var _deviceId   = deviceId;
                var deviceEvent = _lastMouseEvent[_deviceId];

                //only process PointerEditorDragEvents
                if (!(deviceEvent is PointerDragFromEditorEnterEvent ||
                      deviceEvent is PointerDragFromEditorHoverEvent ||
                      deviceEvent is PointerDragFromEditorExitEvent))
                {
                    continue;
                }

                lastMouseEvent.Add(_lastMouseEvent[_deviceId]);
                SchedulerBinding.instance.addPostFrameCallback(_ => {
                    foreach (var lastEvent in lastMouseEvent)
                    {
                        EditorMouseTrackerAnnotation hit = annotationFinder(lastEvent.position);

                        if (hit == null)
                        {
                            foreach (_EditorTrackedAnnotation trackedAnnotation in _trackedAnnotations.Values)
                            {
                                if (trackedAnnotation.activeDevices.Contains(_deviceId))
                                {
                                    trackedAnnotation.activeDevices.Remove(_deviceId);
                                }
                            }

                            return;
                        }

                        _EditorTrackedAnnotation hitAnnotation = _findAnnotation(hit);

                        // release
                        if (hitAnnotation.activeDevices.Contains(_deviceId))
                        {
                            if (hitAnnotation.annotation?.onDragFromEditorRelease != null)
                            {
                                hitAnnotation.annotation.onDragFromEditorRelease(
                                    PointerDragFromEditorReleaseEvent
                                    .fromDragFromEditorEvent(
                                        lastEvent, DragAndDrop.objectReferences, DragAndDrop.paths));
                            }

                            hitAnnotation.activeDevices.Remove(_deviceId);
                        }
                    }
                });
            }

            SchedulerBinding.instance.scheduleFrame();
        }
Exemple #2
0
 public void attachDragFromEditorAnnotation(EditorMouseTrackerAnnotation annotation)
 {
     _trackedAnnotations[annotation] = new _EditorTrackedAnnotation(annotation);
     _scheduleDragFromEditorMousePositionCheck();
 }
Exemple #3
0
        public void collectDragFromEditorMousePositions()
        {
            void exitAnnotation(_EditorTrackedAnnotation trackedAnnotation, int deviceId)
            {
                if (trackedAnnotation.activeDevices.Contains(deviceId))
                {
                    if (trackedAnnotation.annotation?.onDragFromEditorExit != null)
                    {
                        trackedAnnotation.annotation.onDragFromEditorExit(
                            PointerDragFromEditorExitEvent.fromDragFromEditorEvent(
                                _lastMouseEvent[deviceId]));
                    }

                    trackedAnnotation.activeDevices.Remove(deviceId);
                }
            }

            void exitAllDevices(_EditorTrackedAnnotation trackedAnnotation)
            {
                if (trackedAnnotation.activeDevices.isNotEmpty())
                {
                    HashSet <int> deviceIds = new HashSet <int>(trackedAnnotation.activeDevices);
                    foreach (int deviceId in deviceIds)
                    {
                        exitAnnotation(trackedAnnotation, deviceId);
                    }
                }
            }

            if (!mouseIsConnected)
            {
                foreach (var annotation in _trackedAnnotations.Values)
                {
                    exitAllDevices(annotation);
                }

                return;
            }

            foreach (int deviceId in _lastMouseEvent.Keys)
            {
                PointerEvent lastEvent           = _lastMouseEvent[deviceId];
                EditorMouseTrackerAnnotation hit = annotationFinder(lastEvent.position);

                if (hit == null)
                {
                    foreach (_EditorTrackedAnnotation trackedAnnotation in _trackedAnnotations.Values)
                    {
                        exitAnnotation(trackedAnnotation, deviceId);
                    }

                    return;
                }

                _EditorTrackedAnnotation hitAnnotation = _findAnnotation(hit);

                // While acrossing two areas, set the flag to true to prevent setting the Pointer Copy VisualMode to None
                // enter
                if (!hitAnnotation.activeDevices.Contains(deviceId))
                {
                    hitAnnotation.activeDevices.Add(deviceId);
                    // Both onRelease or onEnter event will enable Copy VisualMode
                    if (hitAnnotation.annotation?.onDragFromEditorRelease != null ||
                        hitAnnotation.annotation?.onDragFromEditorEnter != null)
                    {
                        if (hitAnnotation.annotation?.onDragFromEditorEnter != null)
                        {
                            hitAnnotation.annotation.onDragFromEditorEnter(
                                PointerDragFromEditorEnterEvent
                                .fromDragFromEditorEvent(lastEvent, DragAndDrop.objectReferences, DragAndDrop.paths));
                        }
                    }
                }

                // hover
                if (hitAnnotation.annotation?.onDragFromEditorHover != null)
                {
                    hitAnnotation.annotation.onDragFromEditorHover(
                        PointerDragFromEditorHoverEvent.fromDragFromEditorEvent(lastEvent));
                }

                // leave
                foreach (_EditorTrackedAnnotation trackedAnnotation in _trackedAnnotations.Values)
                {
                    if (hitAnnotation == trackedAnnotation)
                    {
                        continue;
                    }

                    if (trackedAnnotation.activeDevices.Contains(deviceId))
                    {
                        if (trackedAnnotation.annotation?.onDragFromEditorExit != null)
                        {
                            trackedAnnotation.annotation.onDragFromEditorExit(
                                PointerDragFromEditorExitEvent
                                .fromDragFromEditorEvent(lastEvent));
                        }

                        trackedAnnotation.activeDevices.Remove(deviceId);
                    }
                }
            }
        }