Beispiel #1
0
        /// <summary>
        /// This method adds a new annotation.
        /// </summary>
        public void AddAnnotation()
        {
            if (!AnnotationPrefab)
            {
                return;
            }

            Transform cameraTransform = CameraCache.Main ? CameraCache.Main.transform : null;

            foreach (var source in CoreServices.InputSystem.DetectedInputSources)
            {
                // Only look for hands
                if (source.SourceType == Microsoft.MixedReality.Toolkit.Input.InputSourceType.Hand)
                {
                    foreach (var pointer in source.Pointers)
                    {
                        if (pointer is IMixedRealityNearPointer || true)
                        {
                            Vector3 position;
                            if (pointer.Result != null)
                            {
                                position = pointer.Result.Details.Point;
                            }
                            else
                            {
                                position = pointer.Position;
                            }

                            if (cameraTransform != null)
                            {
                                if ((cameraTransform.position - position).magnitude > 3)
                                {
                                    position = cameraTransform.position + ((position - cameraTransform.position) * 0.5f);
                                }
                            }

                            var annotation = Instantiate(AnnotationPrefab, worldAnchor);
                            annotation.transform.position = position;
                            annotation.Id = Guid.NewGuid();
                            annotation.SetColor(Services.UserManager().Color);
                            annotationList.Add(annotation.Id, annotation);

                            var message = new MessageUpdateAnnotation(annotation.Id, annotation.transform.localPosition, annotation.Color);
                            Services.NetworkManager().SendMessage(message.Pack());

                            return; // only take first valid pointer
                        }
                    }
                }
            }

            if (cameraTransform != null)
            {
                Vector3 position   = cameraTransform.position;
                var     annotation = Instantiate(AnnotationPrefab, worldAnchor);
                annotation.transform.position = position;
                annotation.Id = Guid.NewGuid();
                annotation.SetColor(Services.UserManager().Color);
                annotationList.Add(annotation.Id, annotation);

                var message = new MessageUpdateAnnotation(annotation.Id, annotation.transform.localPosition, annotation.Color);
                Services.NetworkManager().SendMessage(message.Pack());

                return; // only take first valid pointer
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sends the current position and color over network when the position has been updated.
        /// </summary>
        public void PositionUpdated()
        {
            var message = new MessageUpdateAnnotation(Id, transform.localPosition, Color);

            Services.NetworkManager().SendMessage(message.Pack());
        }