コード例 #1
0
        private void OnClick(GameObject hitObject)
        {
            if (hitObject == null)
            {
                return;
            }

            var buttonState = CustomHoloLensInputModule.GetInputButtonState();

            if (buttonState.PressedThisFrame() && buttonState.ReleasedThisFrame())
            {
                if ((hitObject.GetComponentInParent <Selectable>() != null) ||
                    (hitObject.GetComponentInChildren <IEventSystemHandler>() != null))
                {
                    bool playSoundAndAnimate = false;

                    if (playSoundAndAnimate)
                    {
                        if (this.currentCursorObj != null)
                        {
                            var animator = this.currentCursorObj.GetComponentInChildren <Animator>();
                            if (animator != null)
                            {
                                animator.Play("Click");
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        void Update()
        {
            RaycastResult raycast = CustomHoloLensInputModule.GetRaycastResult();

            // set active hit object
            SetActiveObject(raycast.gameObject);

            // play sound and animate cursor
            OnClick(raycast.gameObject);

            var position = (raycast.gameObject != null) ? raycast.worldPosition : raycast.worldPosition - (raycast.worldNormal * DefaultCursorDistance);

            this.CursorLocation = position;
            this.CursorRotation = Quaternion.LookRotation(-raycast.worldNormal);

            Vector3    av = currentCursorObj.transform.position;
            Quaternion aq = currentCursorObj.transform.rotation;

            Vector3    bv = this.CursorLocation;
            Quaternion bq = this.CursorRotation;

            var totalDistance = ((bv - Camera.main.transform.position) - (av - Camera.main.transform.position)).sqrMagnitude;

            if (totalDistance < Threshold && totalDistance > -Threshold)
            {
                av = bv = this.CursorLocation;
                aq = bq = this.CursorRotation;
            }

            // position & rotation to match normal
            currentCursorObj.transform.position  = UseLerp ? Vector3.Lerp(av, bv, LerpAmount) : this.CursorLocation;
            currentCursorObj.transform.position += CursorObjectOffset * raycast.worldNormal;// Vector3.Normalize(currentCursorObj.transform.position - Camera.main.transform.position);
            currentCursorObj.transform.rotation  = UseLerp ? Quaternion.Slerp(aq, bq, LerpAmount) : this.CursorRotation;

            if (pressedCursorObj.activeInHierarchy)
            {
                pressedCursorObj.transform.position = currentCursorObj.transform.position;
                pressedCursorObj.transform.forward  = Vector3.ProjectOnPlane(currentCursorObj.transform.forward, Vector3.up);
            }
        }