Example #1
0
        protected virtual bool isValidGrabbale(Collider col, Grabbable grab)
        {
            // Object has been deactivated. Remove it
            if (col == null || grab == null || !grab.isActiveAndEnabled || !col.enabled)
            {
                return(false);
            }
            // Not considered grabbable any longer. May have been picked up, marked, etc.
            else if (!grab.IsGrabbable())
            {
                return(false);
            }
            // Snap Zone without an item isn't a valid grab. Want to skip this unless something is inside
            else if (grab.GetComponent <SnapZone>() != null && grab.GetComponent <SnapZone>().HeldItem == null)
            {
                return(false);
            }
            // Position was manually set outside of break distance
            // No longer possible for it to be the closestGrabbable
            else if (grab == ClosestGrabbable)
            {
                if (grab.BreakDistance > 0 && Vector3.Distance(grab.transform.position, transform.position) > grab.BreakDistance)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #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;
                }
            }
        }