Ejemplo n.º 1
0
        Color getSelectedColor()
        {
            // Use secondary color if closest grabber is on the left hand
            closestGrabber = grabbable.GetClosestGrabber();
            if (grabbable != null && closestGrabber != null)
            {
                if (closestGrabber.HandSide == ControllerHand.Left)
                {
                    return(RingSecondarySelectedColor);
                }
            }

            return(RingSelectedColor);
        }
Ejemplo n.º 2
0
        void Update()
        {
            // Double check for mainCam
            AssignCamera();


            // Bail if Text Component was removed or doesn't exist
            if (text == null || mainCam == null || grabbable == null)
            {
                return;
            }

            bool grabbersExist = leftGrabber != null && rightGrabber != null;

            // Holding Item
            handsFull = grabbersExist && leftGrabber.HoldingItem && rightGrabber.HoldingItem;

            // Not a valid Grab
            if (grabbersExist && grabbable.GrabButton == GrabButton.Grip && !leftGrabber.FreshGrip && !rightGrabber.FreshGrip)
            {
                handsFull = true;
            }

            bool showRings = handsFull;

            // If being held or not active, immediately hide the ring
            if (grabbable.BeingHeld || !grabbable.isActiveAndEnabled)
            {
                canvas.enabled = false;
                return;
            }

            // Requires another Grabbable to be held. Can exit immediately
            if (grabbable.OtherGrabbableMustBeGrabbed != null && grabbable.OtherGrabbableMustBeGrabbed.BeingHeld == false)
            {
                canvas.enabled = false;
                return;
            }

            // Show if within range
            float currentDistance = Vector3.Distance(transform.position, mainCam.position);

            if (!handsFull && currentDistance <= grabbable.RemoteGrabDistance)
            {
                showRings = true;
            }
            else
            {
                showRings = false;
            }

            // Animate ring opacity in / out
            if (showRings)
            {
                canvas.enabled = true;
                canvas.transform.LookAt(mainCam);

                // Resetting the text refreshes the render
                text.text = "o";

                bool isClosest = grabbable.GetClosestGrabber() != null && grabbable.IsGrabbable();
                // Check if grabpoint was specified
                if (Grabpoint != null)
                {
                }

                // If a valid grabbable, increase size a bit
                if (isClosest)
                {
                    scaler.dynamicPixelsPerUnit = ringSizeGrabbable;

                    text.color = getSelectedColor();
                }
                else
                {
                    scaler.dynamicPixelsPerUnit = ringSizeInRange;
                    text.color = RingColor;
                }

                _currentOpacity += Time.deltaTime * RingFadeSpeed;
                if (_currentOpacity > _initalOpacity)
                {
                    _currentOpacity = _initalOpacity;
                }

                Color colorCurrent = text.color;
                colorCurrent.a = _currentOpacity;
                text.color     = colorCurrent;
            }
            else
            {
                _currentOpacity -= Time.deltaTime * RingFadeSpeed;
                if (_currentOpacity <= 0)
                {
                    _currentOpacity = 0;
                    canvas.enabled  = false;
                }
                else
                {
                    canvas.enabled = true;
                    Color colorCurrent = text.color;
                    colorCurrent.a = _currentOpacity;
                    text.color     = colorCurrent;
                }
            }
        }