Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
                    }
                }
            }
        }