Пример #1
0
        void Update()
        {
            if (targetHand != null)
            {
                int  inputIndex = inputModule.GetHandToLocalIndex(targetHand);
                bool hasPointer = inputModule.HasCurrentPointTarget(inputIndex);

                // What's the distance to the pointer (if we have one)
                float distance = lastDistance;
                if (hasPointer)
                {
                    Vector3 cursorPos = inputModule.GetCurrentPointPosition(inputIndex);
                    distance = (targetHand.transform.position - cursorPos).magnitude;

                    lastDistance = Mathf.Clamp(distance, 0.1f, 0.6f);
                }

                // Set the laser as visible if we've got a pointer or if we're pointing in the right direction
                bool isPointingAtPanel = IsPointingAtPanel();
                cylinder.SetActive(hasPointer || isPointingAtPanel);

                // Position ourselves
                this.transform.position = targetHand.transform.position;
                this.transform.rotation = targetHand.transform.rotation;

                // Position the laser
                cylinder.transform.localScale = new Vector3(0.002f, distance * 0.5f, 0.002f);
                cylinder.transform.rotation   = targetHand.transform.rotation * Quaternion.Euler(90.0f, 0.0f, 0.0f);
                cylinder.transform.position   = targetHand.transform.position + targetHand.transform.forward * distance * 0.5f;
            }
            else
            {
                cylinder.SetActive(false);
            }
        }
Пример #2
0
        private void UpdateInput(Hand hand, int handIndex, GameObject handObj, ref bool wasButtonDown)
        {
            if (wandInputModule == null)
            {
                return;
            }

            if (handIndex != -1)
            {
                bool isDown = activeBinding.IsInputDown(hand);

                // Add manual input trigger
                if (hand == Hand.Left)
                {
                    isDown |= triggerLeft;
                }
                else
                {
                    isDown |= triggerRight;
                }

                int inputIndex = wandInputModule.GetHandToLocalIndex(handObj);

                if (isDown && !wasButtonDown)
                {
                    wandInputModule.LatchButtonDown(inputIndex);
                }

                if (wasButtonDown && !isDown)
                {
                    wandInputModule.LatchButtonUp(inputIndex);
                }

                wasButtonDown = isDown;
            }
        }