private void StartTrackingController(InteractionSource source)
        {
#if WANT_VISUALIZERS_MTAULTY
            string key = GenerateKey(source);

            MotionControllerInfo controllerInfo;
            if (source.kind == InteractionSourceKind.Controller)
            {
                if (!controllerDictionary.ContainsKey(key) && !loadingControllers.Contains(key))
                {
                    StartCoroutine(LoadControllerModel(source));
                }
                else if (controllerDictionary.TryGetValue(key, out controllerInfo))
                {
                    if (controllerInfo.Handedness == InteractionSourceHandedness.Left)
                    {
                        leftControllerModel = controllerInfo;
                    }
                    else if (controllerInfo.Handedness == InteractionSourceHandedness.Right)
                    {
                        rightControllerModel = controllerInfo;
                    }

                    controllerInfo.ControllerParent.SetActive(true);

                    if (OnControllerModelLoaded != null)
                    {
                        OnControllerModelLoaded(controllerInfo);
                    }
                }
            }
#endif
        }
Beispiel #2
0
        protected override void AddControllerTransform(MotionControllerInfo newController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (!IsAttached && newController.Handedness == Handedness)
            {
                base.AddControllerTransform(newController);

                // Parent ourselves under the element and set our offsets
                transform.parent           = ElementTransform;
                transform.localPosition    = PositionOffset;
                transform.localEulerAngles = RotationOffset;

                if (SetScaleOnAttach)
                {
                    transform.localScale = ScaleOffset;
                }

                SetChildrenActive(true);

                // Announce that we're attached
                OnAttachToController();

                IsAttached = true;
            }
#endif
        }
Beispiel #3
0
        private void AttachElementToController(MotionControllerInfo newController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            // Check handedness
            if (!IsAttached && newController.Handedness == handedness)
            {
                // Get specific element of the controller
                if (!newController.TryGetElement(element, out elementTransform))
                {
                    Debug.LogError("Unable to find element of type " + element + " under controller " + newController.ControllerParent.name + "; not attaching.");
                    return;
                }

                controller = newController;

                SetChildrenActive(true);

                // Parent ourselves under the element and set our offsets
                transform.parent           = elementTransform;
                transform.localPosition    = positionOffset;
                transform.localEulerAngles = rotationOffset;
                if (setScaleOnAttach)
                {
                    transform.localScale = scale;
                }

                // Announce that we're attached
                OnAttachToController();

                IsAttached = true;
            }
#endif
        }
Beispiel #4
0
        public static bool Update(this MotionControllerInfo currentController, InteractionSourceState sourceState,
                                  InteractionSourceNode nodeType, bool updatePosition = true, bool updateRotation = false)
        {
            Vector3 newPosition;
            bool    retValPosition = false, retValRotation = false;

            if (updatePosition && (retValPosition = sourceState.sourcePose.TryGetPosition(out newPosition, nodeType)))
            {
#if DEBUG
                if (newPosition.IsDebugValid())
#endif
                {
                    currentController.ControllerParent.transform.localPosition = newPosition;
                }
#if DEBUG
                else
                {
                    Debug.Log("Skipping newPosition:" + newPosition.ToString());
                }
#endif
            }
            Quaternion newRotation;
            if (updateRotation && (retValRotation = sourceState.sourcePose.TryGetRotation(out newRotation, nodeType)))
            {
                currentController.ControllerParent.transform.localRotation = newRotation;
            }

            // TraceHelper.Log(string.Format("{0}:Pos{1},Rot{2}", nodeType, newPosition, newRotation));
            // TraceHelper.Assert( retValPosition && retValRotation, "Update should not fail");
            return(retValRotation && retValPosition);
        }
        /// <summary>
        /// When a controller is lost, the model is destroyed and the controller object
        /// is removed from the tracking dictionary.
        /// </summary>
        /// <param name="obj">The source event args to be used to determine the controller model to be removed.</param>
        private void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs obj)
        {
            InteractionSource source = obj.state.source;

            if (source.kind == InteractionSourceKind.Controller)
            {
                MotionControllerInfo controllerInfo;
                if (controllerDictionary != null && controllerDictionary.TryGetValue(GenerateKey(source), out controllerInfo))
                {
                    if (OnControllerModelUnloaded != null)
                    {
                        OnControllerModelUnloaded(controllerInfo);
                    }

                    if (controllerInfo.Handedness == InteractionSourceHandedness.Left)
                    {
                        leftControllerModel = null;
                    }
                    else if (controllerInfo.Handedness == InteractionSourceHandedness.Right)
                    {
                        rightControllerModel = null;
                    }

                    controllerInfo.ControllerParent.SetActive(false);
                }
            }
        }
        private void FinishControllerSetup(GameObject controllerModelGameObject, InteractionSourceHandedness handedness, string dictionaryKey)
        {
            var parentGameObject = new GameObject
            {
                name = handedness + "Controller"
            };

            parentGameObject.transform.parent          = transform;
            controllerModelGameObject.transform.parent = parentGameObject.transform;

            var newControllerInfo = new MotionControllerInfo(parentGameObject, handedness);

            newControllerInfo.LoadInfo(controllerModelGameObject.GetComponentsInChildren <Transform>());

            if (handedness == InteractionSourceHandedness.Left)
            {
                leftControllerModel = newControllerInfo;
            }
            else if (handedness == InteractionSourceHandedness.Right)
            {
                rightControllerModel = newControllerInfo;
            }

            if (OnControllerModelLoaded != null)
            {
                OnControllerModelLoaded(newControllerInfo);
            }

            loadingControllers.Remove(dictionaryKey);
            controllerDictionary.Add(dictionaryKey, newControllerInfo);
        }
Beispiel #7
0
        private void AttachElementToControl(MotionControllerInfo newController)
        {
            if (!IsAttached && newController.Handedness == handedness)
            {
                Debug.LogError("Unable to find element of type " + element + " under controller " + newController.ControllerParent.name + ": not attaching.");
                return;
            }

            controller = newController;

            SetChildrenActive(true);

            //Parent ourselves under the element and set our offset
            transform.parent           = elementTransform;
            transform.localPosition    = positionOffset;
            transform.localEulerAngles = rotationOffset;
            if (setScaleOnAttach)
            {
                transform.localScale = scale;
            }

            // Announce that we are attached
            OnAttachToController();
            IsAttached = true;
        }
        /// <summary>
        /// Lets all listeners know that the controller was lost, then resets the cached info
        /// and transform, potentially in preparation of a new controller.
        /// </summary>
        private void ResetControllerTransform()
        {
            OnControllerLost();

            ControllerInfo   = null;
            ElementTransform = null;
        }
        private void FinishControllerSetup(GameObject controllerModelGameObject, InteractionSourceHandedness handedness, string dictionaryKey)
        {
            Debug.Log("Make Comtroller");

            var parentGameObject = new GameObject
            {
                name = handedness + "Controller"
            };

            parentGameObject.transform.parent          = transform;
            controllerModelGameObject.transform.parent = parentGameObject.transform;

            var newControllerInfo = new MotionControllerInfo(parentGameObject, handedness);

            newControllerInfo.LoadInfo(controllerModelGameObject.GetComponentsInChildren <Transform>());

            if (handedness == InteractionSourceHandedness.Left)
            {
                leftControllerModel = newControllerInfo;
            }
            else if (handedness == InteractionSourceHandedness.Right)
            {
                rightControllerModel = newControllerInfo;
            }

            if (OnControllerModelLoaded != null)
            {
                OnControllerModelLoaded(newControllerInfo);
            }

            loadingControllers.Remove(dictionaryKey);
            controllerDictionary.Add(dictionaryKey, newControllerInfo);

            //컨트롤러가 생성되면 찾아서 태그를 바꾸어 준다//
            conL = GameObject.Find("LeftController");
            conR = GameObject.Find("RightController");
            if (conL != null)
            {
                //컨트롤러 레이져 봉 추가//
                lineL.SetActive(true);
                lineL.transform.parent        = conL.transform;
                lineL.transform.localPosition = Vector3.zero;
                //레이어 위치 변경//
                //conL.layer = 9;
                ChangeLayer(conL.transform, 9);
                Debug.Log("왼쪽 컨트롤러 생성!::: " + conL.layer);
            }
            if (conR != null)
            {
                //컨트롤러 레이져 봉 추가//
                lineR.SetActive(true);
                lineR.transform.parent        = conR.transform;
                lineR.transform.localPosition = Vector3.zero;

                //레이어 위치 변경//
                //conR.layer = 9;
                ChangeLayer(conR.transform, 9);
                Debug.Log("오른쪽 컨트롤러 생성!::: " + conR.layer);
            }
        }
        protected virtual void RemoveControllerTransform(MotionControllerInfo oldController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (oldController.Handedness == handedness)
            {
                ResetControllerTransform();
            }
#endif
        }
Beispiel #11
0
        protected virtual void RemoveControllerTransform(MotionControllerInfo oldController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (oldController.Handedness == handedness)
            {
                OnControllerLost();

                ControllerInfo   = null;
                ElementTransform = null;
            }
#endif
        }
        private void DetachElementFromController(MotionControllerInfo oldController)
        {
            if (IsAttached && oldController.Handedness == handedness)
            {
                OnDetachFromController();

                controller       = null;
                transform.parent = null;

                SetChildrenActive(false);

                IsAttached = false;
            }
        }
Beispiel #13
0
        private void DetachElementFromController(MotionControllerInfo oldController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (IsAttached && oldController.Handedness == handedness)
            {
                OnDetachFromController();

                controller       = null;
                transform.parent = null;

                SetChildrenActive(false);

                IsAttached = false;
            }
#endif
        }
Beispiel #14
0
        protected virtual void AddControllerTransform(MotionControllerInfo newController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (newController.Handedness == handedness && !newController.Equals(ControllerInfo))
            {
                if (!newController.TryGetElement(element, out elementTransform))
                {
                    //Debug.LogError("Unable to find element of type " + element + " under controller " + newController.ControllerParent.name + "; not attaching.");
                    return;
                }
                ControllerInfo = newController;
                // update elementTransform for consumption
                ControllerInfo.TryGetElement(element, out elementTransform);
                ElementTransform = elementTransform;
            }
#endif
        }
Beispiel #15
0
        protected override void RemoveControllerTransform(MotionControllerInfo oldController)
        {
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
            if (IsAttached && oldController.Handedness == Handedness)
            {
                base.RemoveControllerTransform(oldController);

                OnDetachFromController();

                SetChildrenActive(false);

                transform.parent = null;

                IsAttached = false;
            }
#endif
        }
 public bool TryGetControllerModel(InteractionSourceHandedness handedness, out MotionControllerInfo controller)
 {
     if (handedness == InteractionSourceHandedness.Left && leftControllerModel != null)
     {
         controller = leftControllerModel;
         return(true);
     }
     else if (handedness == InteractionSourceHandedness.Right && rightControllerModel != null)
     {
         controller = rightControllerModel;
         return(true);
     }
     else
     {
         controller = null;
         return(false);
     }
 }
Beispiel #17
0
        public static bool Update(this MotionControllerInfo currentController, InteractionSourceState sourceState, object unused)
        {
            Vector3 newPosition;
            bool    retValPosition, retValRotation;

            if (retValPosition = sourceState.sourcePose.TryGetPosition(out newPosition))
            {
                currentController.ControllerParent.transform.localPosition = newPosition;
            }
            Quaternion newRotation;

            if (retValRotation = sourceState.sourcePose.TryGetRotation(out newRotation))
            {
                currentController.ControllerParent.transform.localRotation = newRotation;
            }

            // TraceHelper.Log(string.Format("{0}:Pos{1},Rot{2}", nodeType, newPosition, newRotation));
            TraceHelper.Assert(retValPosition && retValRotation, "Update should not fail");
            return(retValRotation && retValPosition);
        }
        private void FinishControllerSetup(GameObject controllerModelGameObject, string handedness, uint id)
        {
            var parentGameObject = new GameObject
            {
                name = handedness + "Controller"
            };

            parentGameObject.transform.parent          = transform;
            controllerModelGameObject.transform.parent = parentGameObject.transform;

            var newControllerInfo = new MotionControllerInfo()
            {
                ControllerParent = parentGameObject
            };

            if (AnimateControllerModel)
            {
                newControllerInfo.LoadInfo(controllerModelGameObject.GetComponentsInChildren <Transform>(), this);
            }
            controllerDictionary.Add(id, newControllerInfo);
        }
        /// <summary>
        /// When a controller is lost, the model is destroyed and the controller object
        /// is removed from the tracking dictionary.
        /// </summary>
        /// <param name="obj">The source event args to be used to determine the controller model to be removed.</param>
        private void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs obj)
        {
            InteractionSource source = obj.state.source;

            if (source.kind == InteractionSourceKind.Controller)
            {
                MotionControllerInfo controllerInfo;
                string key = GenerateKey(source);
                if (controllerDictionary != null && controllerDictionary.TryGetValue(key, out controllerInfo))
                {
                    if (OnControllerModelUnloaded != null)
                    {
                        OnControllerModelUnloaded(controllerInfo);
                    }

                    if (controllerInfo.Handedness == InteractionSourceHandedness.Left)
                    {
                        leftControllerModel = null;

                        if (!AlwaysUseAlternateLeftModel && leftModelIsAlternate)
                        {
                            controllerDictionary.Remove(key);
                            Destroy(controllerInfo.ControllerParent);
                        }
                    }
                    else if (controllerInfo.Handedness == InteractionSourceHandedness.Right)
                    {
                        rightControllerModel = null;

                        if (!AlwaysUseAlternateRightModel && rightModelIsAlternate)
                        {
                            controllerDictionary.Remove(key);
                            Destroy(controllerInfo.ControllerParent);
                        }
                    }

                    controllerInfo.ControllerParent.SetActive(false);
                }
            }
        }