Example #1
0
 void Start()
 {
     rigidBody_        = GetComponent <Rigidbody>();
     collider_         = GetComponent <Collider>();
     collider_.enabled = false;
     XRDevice.DisableAutoXRCameraTracking(GetComponent <Camera>(), true);
     handMRManager_ = GetComponentInParent <HandMRManager>();
 }
Example #2
0
        void Start()
        {
            handVRMain_    = FindObjectOfType <HandVRMain>();
            handMRManager_ = FindObjectOfType <HandMRManager>();
            renderer_      = transform.GetComponentInChildren <Renderer>();

            defaultColor_ = renderer_.material.GetColor("_Color");
            renderer_.material.SetColor("_Color",
                                        new Color(defaultColor_.r, defaultColor_.g, defaultColor_.b, 0f));
            defaultColorInner_ = renderer_.material.GetColor("_ColorInner");
            renderer_.material.SetColor("_ColorInner",
                                        new Color(defaultColorInner_.r, defaultColorInner_.g, defaultColorInner_.b, 0f));
        }
Example #3
0
        void Start()
        {
            handVRMain_    = FindObjectOfType <HandVRMain>();
            handMRManager_ = FindObjectOfType <HandMRManager>();

            foreach (Transform child in transform)
            {
                HandVRPosition posObj = child.GetComponent <HandVRPosition>();
                if (posObj != null)
                {
                    fingers_[posObj.Index] = child;
                    posObj.ThisEitherHand  = ThisEitherHand;
                }
            }

            startInputDevice();
        }
Example #4
0
        void Reset()
        {
            try
            {
                HandMRManagerObj        = FindObjectOfType <HandMRManager>();
                HologlaCameraManagerObj = HandMRManagerObj.GetComponentInChildren <HologlaCameraManager>().gameObject;
                HandVRMainObj           = HandMRManagerObj.GetComponentInChildren <HandVRMain>();

                var hologlaInput = HandMRManagerObj.GetComponentInChildren <HologlaInput>();
                LeftButton  = hologlaInput.LeftButtonComp.transform;
                RightButton = hologlaInput.RightButtonComp.transform;
            }
            catch (NullReferenceException)
            {
                Debug.Log("Setting SettingFromPlayerPrefs is failed.\nPlease setting from Inspector.");
            }

            var handArea = FindObjectOfType <HandArea>();

            if (handArea != null)
            {
                HandAreaObj = handArea.gameObject;
            }
        }
Example #5
0
        public override void Process()
        {
            if (handMRManager_ == null)
            {
                handMRManager_ = FindObjectOfType <HandMRManager>();
            }
            if (colliders_.Count <= 0)
            {
                addColliderToSelectable();
            }

            bool noHands = true;

            foreach (var hand in Hands)
            {
                if (hand.IsTrackingHand)
                {
                    noHands = false;
                    break;
                }
            }
            if (noHands)
            {
                if (Time.time - prevDetectTime_ > LeaveTime)
                {
                    Selectable[] selectables2 = Selectable.allSelectablesArray;
                    changeEnabledSelectable(true, selectables2);
                    base.Process();
                    reEnabledSelectable(selectables2);
                }
                return;
            }

            Transform         cameraTrans = handMRManager_.GetCameraTransform();
            List <RaycastHit> tempHits    = new List <RaycastHit>();

            bool handIsOpened = false;

            foreach (var hand in Hands)
            {
                if (!hand.IsTrackingHand)
                {
                    continue;
                }

                bool grabed = false;
                if (GrabDetect)
                {
#if false
                    grabed = true;
                    bool opened = true;
                    for (int loop = 1; loop < 5; loop++)
                    {
                        if (hand.GetFingerOpened(loop))
                        {
                            grabed = false;
                        }
                        else
                        {
                            opened = false;
                        }
                    }
                    if (Vector3.Distance(hand.GetFinger(4).position, hand.GetFinger(8).position) < 0.03f)
                    {
                        grabed = true;
                        opened = false;
                    }
                    if (opened)
                    {
                        handIsOpened = true;
                    }
#endif
                    grabed       = hand.IsGrab;
                    handIsOpened = !grabed;
                }

                Vector3 forward = (hand.GetFinger(8).position - cameraTrans.position).normalized;

                RaycastHit[] hits = Physics.RaycastAll(cameraTrans.position, forward,
                                                       Mathf.Infinity, 1 << LayerMask.NameToLayer("UI"), QueryTriggerInteraction.Collide);

                if (hits != null && hits.Length > 0)
                {
                    float      nearDistance = float.PositiveInfinity;
                    GameObject nearObj      = null;
                    RaycastHit nearHit      = hits[0];
                    foreach (RaycastHit hit in hits)
                    {
                        if (hit.distance < nearDistance)
                        {
                            nearDistance = hit.distance;
                            nearObj      = hit.transform.gameObject;
                            nearHit      = hit;
                        }
                    }

                    float distance = Vector3.Distance(nearHit.point, hand.GetFinger(8).position);
                    if (grabed || (distance <= TouchDistance && TouchDistance > 0f))
                    {
                        uiDetectControl(nearObj, nearHit.point, grabed);
                        return;
                    }
                    else
                    {
                        tempHits.AddRange(hits);
                    }
                }
            }

            if (handIsOpened)
            {
                isGrabDetected_ = false;
            }

            if (tempHits.Count > 0)
            {
                float      nearDistance = float.PositiveInfinity;
                GameObject nearObj      = null;
                foreach (RaycastHit hit in tempHits)
                {
                    if (hit.distance < nearDistance)
                    {
                        nearDistance = hit.distance;
                        nearObj      = hit.transform.gameObject;
                    }
                }

                if (eventSystem.currentSelectedGameObject != nearObj)
                {
                    eventSystem.SetSelectedGameObject(nearObj);
                }
                return;
            }

            if (prevDetectObj_ != null && submitPointerData_ != null)
            {
                GameObject submitObj = ExecuteEvents.GetEventHandler <ISubmitHandler>(prevDetectObj_);
                if (submitObj != null)
                {
                    ExecuteEvents.Execute(submitObj, submitPointerData_, ExecuteEvents.submitHandler);
                    addColliderToSelectable();
                    prevDetectTime_ = Time.time;
                }
                submitPointerData_ = null;
            }

            if (Time.time - prevDetectTime_ > LeaveTime)
            {
                resetSelect();
                prevDetectObj_ = null;

                Selectable[] selectables = Selectable.allSelectablesArray;
                changeEnabledSelectable(true, selectables);
                base.Process();
                reEnabledSelectable(selectables);
            }
        }