コード例 #1
0
ファイル: AnnotationManager.cs プロジェクト: imldresden/miria
        private Task OnAnnotationUpdated(MessageContainer obj)
        {
            MessageUpdateAnnotation message = MessageUpdateAnnotation.Unpack(obj);

            if (annotationList.ContainsKey(message.Id))
            {
                var annotation = annotationList[message.Id];
                annotation.transform.localPosition = message.Position;
            }
            else if (AnnotationPrefab)
            {
                var annotation = Instantiate(AnnotationPrefab, worldAnchor);
                annotation.transform.localPosition = message.Position;
                annotation.Id = message.Id;
                annotation.SetColor(message.Color);
                annotationList.Add(annotation.Id, annotation);
            }

            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: AnnotationManager.cs プロジェクト: imldresden/miria
        /// <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
            }
        }
コード例 #3
0
ファイル: AnnotationTag.cs プロジェクト: imldresden/miria
        /// <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());
        }