Пример #1
0
        public void attachAnnotation(MouseTrackerAnnotation annotation)
        {
            this._trackedAnnotations[annotation] = new _TrackedAnnotation(annotation);
            this._scheduleMousePositionCheck();

#if UNITY_EDITOR
            this._scheduleDragFromEditorMousePositionCheck();
#endif
        }
Пример #2
0
        _TrackedAnnotation _findAnnotation(MouseTrackerAnnotation annotation)
        {
            if (!this._trackedAnnotations.TryGetValue(annotation, out var trackedAnnotation))
            {
                D.assert(false, () => "Unable to find annotation $annotation in tracked annotations. " +
                         "Check that attachAnnotation has been called for all annotated layers.");
            }

            return(trackedAnnotation);
        }
Пример #3
0
        public void detachAnnotation(MouseTrackerAnnotation annotation)
        {
            _TrackedAnnotation trackedAnnotation = this._findAnnotation(annotation);

            foreach (int deviceId in trackedAnnotation.activeDevices)
            {
                annotation.onExit(PointerExitEvent.fromHoverEvent((PointerHoverEvent)this._lastMouseEvent[deviceId]));
            }

            this._trackedAnnotations.Remove(annotation);
        }
Пример #4
0
        void detachDragFromEditorAnnotation(MouseTrackerAnnotation annotation, int deviceId)
        {
            if (!this.inEditorWindow)
            {
                return;
            }

            if (annotation.onDragFromEditorExit != null)
            {
                annotation.onDragFromEditorExit(
                    PointerDragFromEditorExitEvent.fromDragFromEditorEvent(this._lastMouseEvent[deviceId]));
            }
        }
Пример #5
0
        void _scheduleDragFromEditorReleaseCheck()
        {
            DragAndDrop.AcceptDrag();

            var lastMouseEvent = new List <PointerEvent>();

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

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

                            return;
                        }

                        _TrackedAnnotation hitAnnotation = this._findAnnotation(hit);

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

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

            SchedulerBinding.instance.scheduleFrame();
        }
Пример #6
0
        public void detachAnnotation(MouseTrackerAnnotation annotation)
        {
            _TrackedAnnotation trackedAnnotation = this._findAnnotation(annotation);

            foreach (int deviceId in trackedAnnotation.activeDevices)
            {
                if (annotation.onExit != null)
                {
                    annotation.onExit(
                        PointerExitEvent.fromHoverEvent((PointerHoverEvent)this._lastMouseEvent[deviceId]));
                }
#if UNITY_EDITOR
                this.detachDragFromEditorAnnotation(annotation, deviceId);
#endif
            }

            this._trackedAnnotations.Remove(annotation);
        }
Пример #7
0
 public void attachAnnotation(MouseTrackerAnnotation annotation)
 {
     this._trackedAnnotations[annotation] = new _TrackedAnnotation(annotation);
     this._scheduleMousePositionCheck();
 }
Пример #8
0
 public _TrackedAnnotation(
     MouseTrackerAnnotation annotation)
 {
     this.annotation = annotation;
 }
Пример #9
0
        public void collectMousePositions()
        {
            void exitAnnotation(_TrackedAnnotation trackedAnnotation, int deviceId)
            {
                if (trackedAnnotation.annotation?.onExit != null &&
                    trackedAnnotation.activeDevices.Contains(deviceId))
                {
                    trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent(this._lastMouseEvent[deviceId]));
                    trackedAnnotation.activeDevices.Remove(deviceId);
                }
            }

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

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

                return;
            }

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

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

                    return;
                }

                _TrackedAnnotation hitAnnotation = this._findAnnotation(hit);
                //enter
                if (!hitAnnotation.activeDevices.Contains(deviceId))
                {
                    hitAnnotation.activeDevices.Add(deviceId);
                    if (hitAnnotation.annotation?.onEnter != null)
                    {
                        hitAnnotation.annotation.onEnter(PointerEnterEvent.fromHoverEvent(lastEvent));
                    }
                }

                //hover
                if (hitAnnotation.annotation?.onHover != null)
                {
                    hitAnnotation.annotation.onHover(PointerHoverEvent.fromHoverEvent(lastEvent));
                }

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

                    if (trackedAnnotation.activeDevices.Contains(deviceId))
                    {
                        if (trackedAnnotation.annotation?.onExit != null)
                        {
                            trackedAnnotation.annotation.onExit(PointerExitEvent.fromHoverEvent((PointerHoverEvent)lastEvent));
                        }

                        trackedAnnotation.activeDevices.Remove(deviceId);
                    }
                }
            }
        }
Пример #10
0
 bool isAnnotationAttached(MouseTrackerAnnotation annotation)
 {
     return(this._trackedAnnotations.ContainsKey(annotation));
 }
Пример #11
0
        public void collectDragFromEditorMousePositions()
        {
            void exitAnnotation(_TrackedAnnotation trackedAnnotation, int deviceId)
            {
                if (trackedAnnotation.activeDevices.Contains(deviceId))
                {
                    this._enableDragFromEditorRelease = false;
                    if (trackedAnnotation.annotation?.onDragFromEditorExit != null)
                    {
                        trackedAnnotation.annotation.onDragFromEditorExit(
                            PointerDragFromEditorExitEvent.fromDragFromEditorEvent(
                                this._lastMouseEvent[deviceId]));
                    }

                    trackedAnnotation.activeDevices.Remove(deviceId);
                }
            }

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

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

                return;
            }

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

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

                    return;
                }

                _TrackedAnnotation hitAnnotation = this._findAnnotation(hit);

                // While acrossing two areas, set the flag to true to prevent setting the Pointer Copy VisualMode to None
                bool enterFlag = false;

                // enter
                if (!hitAnnotation.activeDevices.Contains(deviceId))
                {
                    hitAnnotation.activeDevices.Add(deviceId);
                    enterFlag = true;
                    // Both onRelease or onEnter event will enable Copy VisualMode
                    if (hitAnnotation.annotation?.onDragFromEditorRelease != null ||
                        hitAnnotation.annotation?.onDragFromEditorEnter != null)
                    {
                        if (!this._enableDragFromEditorRelease)
                        {
                            this._enableDragFromEditorRelease = true;
                            this._enableDragFromEditorReleaseVisualModeLoop();
                        }

                        if (hitAnnotation.annotation?.onDragFromEditorEnter != null)
                        {
                            hitAnnotation.annotation.onDragFromEditorEnter(
                                PointerDragFromEditorEnterEvent
                                .fromDragFromEditorEvent(lastEvent));
                        }
                    }
                }

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

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

                    if (trackedAnnotation.activeDevices.Contains(deviceId))
                    {
                        if (!enterFlag)
                        {
                            this._enableDragFromEditorRelease = false;
                        }

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

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