Пример #1
0
        public override void DropItem(Grabber droppedBy)
        {
            if (droppedBy != null)
            {
                player.RemoveClimber(droppedBy);
            }

            base.DropItem(droppedBy);
        }
        /// <summary>
        /// Item has been grabbed by a Grabber
        /// </summary>
        /// <param name="grabber"></param>
        public override void OnGrab(Grabber grabber)
        {
            base.OnGrab(grabber);

            if (onGrab != null)
            {
                onGrab.Invoke(grabber);
            }
        }
Пример #3
0
        // Start is called before the first frame update
        void Start()
        {
            transform.parent        = HandAnchor;
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;

            grabber = GetComponentInChildren <Grabber>();
            input   = GameObject.FindGameObjectWithTag("Player").GetComponent <InputBridge>();
        }
Пример #4
0
        void checkClimbing()
        {
            GrippingClimbable = grippingAtLeastOneClimbable();;

            if (GrippingClimbable)
            {
                pControl.enabled = false;

                moveDirection = Vector3.zero;

                int count = 0;
                for (int i = 0; i < climbers.Count; i++)
                {
                    Grabber climber = climbers[i];
                    if (climber != null && climber.HoldingItem)
                    {
                        Vector3 climberMoveAmount = climber.PreviousPosition - climber.transform.position;

                        if (count == 0)
                        {
                            moveDirection += climberMoveAmount;
                        }
                        else
                        {
                            moveDirection += climberMoveAmount - moveDirection;
                        }

                        count++;
                    }
                }

                characterController.Move(moveDirection);
            }
            else
            {
                pControl.enabled = true;
            }


            // Update any climber previous position
            for (int x = 0; x < climbers.Count; x++)
            {
                Grabber climber = climbers[x];
                if (climber != null && climber.HoldingItem)
                {
                    if (climber.DummyTransform != null)
                    {
                        // Use climber position if possible
                        climber.PreviousPosition = climber.DummyTransform.position;
                    }
                    else
                    {
                        climber.PreviousPosition = climber.transform.position;
                    }
                }
            }
        }
Пример #5
0
        public override void OnGrab(Grabber grabber)
        {
            // Play Sound
            if (SoundToPlay)
            {
                VRUtils.Instance.PlaySpatialClipAt(SoundToPlay, transform.position, 1f, 1f);
            }

            base.OnGrab(grabber);
        }
Пример #6
0
        public override void DropItem(Grabber droppedBy)
        {
            if (droppedBy != null)
            {
                Debug.Log("Dropping " + droppedBy.HandSide);
                bngController.RemoveClimber(droppedBy);
            }

            base.DropItem(droppedBy);
        }
Пример #7
0
        public override void OnGrab(Grabber grabber)
        {
            // Store grabber so we can use it if we need to vibrate the controller
            currentGrabber = grabber;

            if (HapticsOnGrab)
            {
                doHaptics(grabber.HandSide);
            }
        }
Пример #8
0
        public void UnhighlightItem()
        {
            // Disable our line
            if (LineToDraw)
            {
                LineToDraw.enabled = false;
            }

            lineToGrabber = null;
        }
Пример #9
0
        public override void GrabItem(Grabber grabbedBy)
        {
            // Add the climber so we can track it's position for Character movement
            if (playerClimbing)
            {
                playerClimbing.AddClimber(this, grabbedBy);
            }

            base.GrabItem(grabbedBy);
        }
Пример #10
0
        void Start()
        {
            LeftGrabber = GameObject.Find("LeftController").GetComponentInChildren <Grabber>();
            gitLeft     = LeftGrabber.GetComponent <GrabbablesInTrigger>();

            RightGrabber = GameObject.Find("RightController").GetComponentInChildren <Grabber>();
            gitRight     = RightGrabber.GetComponent <GrabbablesInTrigger>();

            requestedGrabbables = new Dictionary <int, double>();
        }
Пример #11
0
        void OnTriggerExit(Collider other)
        {
            // Grabber exited grab area. No longer able to grab an arrow
            Grabber grabObject = other.GetComponent <Grabber>();

            if (theBow.ClosestGrabber != null && grabObject != null && theBow.ClosestGrabber == grabObject)
            {
                theBow.CanGrabArrow   = false;
                theBow.ClosestGrabber = null;
            }
        }
Пример #12
0
        void setGrabber(Grabber theGrabber)
        {
            currentGrabber = theGrabber;

            dummyGrabbable.CanBeDropped = false;
            dummyGrabbable.BeingHeld    = true;

            currentGrabber.HeldGrabbable = dummyGrabbable;

            UpdateGrabPoint(closestPoint);
        }
Пример #13
0
        public void RemoveClimber(Grabber grab)
        {
            if (climbers.Contains(grab))
            {
                // Reset grabbable parent
                grab.DummyTransform.parent        = grab.transform;
                grab.DummyTransform.localPosition = Vector3.zero;

                climbers.Remove(grab);
            }
        }
Пример #14
0
        public override void GrabItem(Grabber grabbedBy)
        {
            // Add the climber so we can track it's position for Character movement
            if (bngController == null)
            {
                bngController = GameObject.FindGameObjectWithTag("Player").GetComponent <BNGPlayerController>();
            }
            bngController.AddClimber(this, grabbedBy);

            base.GrabItem(grabbedBy);
        }
Пример #15
0
 public override void OnGrab(Grabber grabber)
 {
     // Primary or secondary that grabbed us?
     if (grabber == SecondaryGrabber)
     {
         previousSecondaryPosition = transform.InverseTransformPoint(SecondaryGrabber.transform.position);
     }
     else
     {
         previousPrimaryPosition = transform.InverseTransformPoint(PrimaryGrabber.transform.position);
     }
 }
Пример #16
0
        void OnTriggerExit(Collider other)
        {
            Grabber grab = other.GetComponent <Grabber>();

            if (grab != null)
            {
                if (grabbers.Contains(grab))
                {
                    grabbers.Remove(grab);
                }
            }
        }
Пример #17
0
        public void AddValidGrabber(Grabber grabber)
        {
            if (validGrabbers == null)
            {
                validGrabbers = new List <Grabber>();
            }

            if (!validGrabbers.Contains(grabber))
            {
                validGrabbers.Add(grabber);
            }
        }
Пример #18
0
        void setupConfigJoint(Grabber g)
        {
            connectedJoint = g.GetComponent <ConfigurableJoint>();
            connectedJoint.autoConfigureConnectedAnchor = false;
            connectedJoint.connectedBody = rigid;

            float anchorOffsetVal = (1 / g.transform.localScale.x) * -1;

            connectedJoint.anchor = Vector3.zero;

            connectedJoint.connectedAnchor = GrabPositionOffset;
        }
Пример #19
0
        void addGrabber(Grabber g)
        {
            if (heldByGrabbers == null)
            {
                heldByGrabbers = new List <Grabber>();
            }

            if (!heldByGrabbers.Contains(g))
            {
                heldByGrabbers.Add(g);
            }
        }
Пример #20
0
        void Update()
        {
            // Grabber may have been deactivated
            if (grabber == null || !grabber.isActiveAndEnabled)
            {
                grabber     = GetComponentInChildren <Grabber>();
                GripAmount  = 0;
                PointAmount = 0;
                ThumbAmount = 0;
                return;
            }

            if (grabber.HandSide == ControllerHand.Left)
            {
                GripAmount   = input.LeftGrip;
                PointAmount  = 1 - input.LeftTrigger;                                                    // Range between 0 and 1. 1 == Finger all the way out
                PointAmount *= InputBridge.Instance.InputSource == XRInputSource.SteamVR ? 0.25F : 0.5F; // Reduce the amount our finger points out if Oculus or XRInput

                // If not near the trigger, point finger all the way out
                if (input.SupportsIndexTouch && input.LeftTriggerNear == false && PointAmount != 0)
                {
                    PointAmount = 1f;
                }

                ThumbAmount = input.LeftThumbNear ? 0 : 1;
            }
            else if (grabber.HandSide == ControllerHand.Right)
            {
                GripAmount   = input.RightGrip;
                PointAmount  = 1 - input.RightTrigger;                                                   // Range between 0 and 1. 1 == Finger all the way out
                PointAmount *= InputBridge.Instance.InputSource == XRInputSource.SteamVR ? 0.25F : 0.5F; // Reduce the amount our finger points out if Oculus or XRInput

                // If not near the trigger, point finger all the way out
                if (input.SupportsIndexTouch && input.RightTriggerNear == false && PointAmount != 0)
                {
                    PointAmount = 1f;
                }

                ThumbAmount = input.RightThumbNear ? 0 : 1;
            }

            // Try getting child animator
            if (HandAnimator == null || !HandAnimator.isActiveAndEnabled)
            {
                HandAnimator = GetComponentInChildren <Animator>();
            }

            if (HandAnimator != null)
            {
                updateAnimimationStates();
            }
        }
Пример #21
0
        public void ResetGrabbing()
        {
            if (rigid)
            {
                rigid.isKinematic = wasKinematic;
            }

            flyingTo = null;

            remoteGrabbing = false;

            collisions = new List <Collider>();
        }
Пример #22
0
        /// <summary>
        /// Update GripAmount, PointAmount, and ThumbAmount based raw input from InputBridge
        /// </summary>
        public virtual void UpdateFromInputs()
        {
            // Grabber may have been deactivated
            if (grabber == null || !grabber.isActiveAndEnabled)
            {
                grabber     = GetComponentInChildren <Grabber>();
                GripAmount  = 0;
                PointAmount = 0;
                ThumbAmount = 0;
                return;
            }

            if (grabber.HandSide == ControllerHand.Left)
            {
                GripAmount   = input.LeftGrip;
                PointAmount  = 1 - input.LeftTrigger;                                                    // Range between 0 and 1. 1 == Finger all the way out
                PointAmount *= InputBridge.Instance.InputSource == XRInputSource.SteamVR ? 0.25F : 0.5F; // Reduce the amount our finger points out if Oculus or XRInput

                // If not near the trigger, point finger all the way out
                if (input.SupportsIndexTouch && input.LeftTriggerNear == false && PointAmount != 0)
                {
                    PointAmount = 1f;
                }
                // Does not support touch, stick finger out as if pointing if no trigger found
                else if (!input.SupportsIndexTouch && input.LeftTrigger == 0)
                {
                    PointAmount = 1;
                }

                ThumbAmount = input.LeftThumbNear ? 0 : 1;
            }
            else if (grabber.HandSide == ControllerHand.Right)
            {
                GripAmount   = input.RightGrip;
                PointAmount  = 1 - input.RightTrigger;                                                   // Range between 0 and 1. 1 == Finger all the way out
                PointAmount *= InputBridge.Instance.InputSource == XRInputSource.SteamVR ? 0.25F : 0.5F; // Reduce the amount our finger points out if Oculus or XRInput

                // If not near the trigger, point finger all the way out
                if (input.SupportsIndexTouch && input.RightTriggerNear == false && PointAmount != 0)
                {
                    PointAmount = 1f;
                }
                // Does not support touch, stick finger out as if pointing if no trigger found
                else if (!input.SupportsIndexTouch && input.RightTrigger == 0)
                {
                    PointAmount = 1;
                }

                ThumbAmount = input.RightThumbNear ? 0 : 1;
            }
        }
Пример #23
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);
        }
Пример #24
0
        /// <summary>
        /// This is typically called by the GrabAction on the SnapZone
        /// </summary>
        /// <param name="grabber"></param>
        public void GrabEquipped(Grabber grabber)
        {
            if (grabber != null)
            {
                if (HeldItem)
                {
                    // Not allowed to be removed
                    if (!CanBeRemoved())
                    {
                        return;
                    }

                    var g = HeldItem;
                    if (DuplicateItemOnGrab)
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Instantiate the object before it is grabbed
                        GameObject go   = Instantiate(g.gameObject, transform.position, Quaternion.identity) as GameObject;
                        Grabbable  grab = go.GetComponent <Grabbable>();

                        // Ok to attach it to snap zone now
                        this.GrabGrabbable(grab);

                        // Finish Grabbing the desired object
                        grabber.GrabGrabbable(g);
                    }
                    else
                    {
                        ReleaseAll();

                        // Position next to grabber if somewhat far away
                        if (Vector3.Distance(g.transform.position, grabber.transform.position) > 0.2f)
                        {
                            g.transform.position = grabber.transform.position;
                        }

                        // Do grab
                        grabber.GrabGrabbable(g);
                    }
                }
            }
        }
Пример #25
0
        public void HighlightItem(Grabber touchingGrabber)
        {
            if (LineToDraw == null)
            {
                return;
            }

            // Draw our bezier curve
            if (!LineToDraw.enabled)
            {
                LineToDraw.enabled = true;
            }

            lineToGrabber = touchingGrabber;
        }
Пример #26
0
        void OnTriggerExit(Collider other)
        {
            Grabber grab = other.GetComponent <Grabber>();

            // No longer inside trigger
            if (grab != null && grab == grabberInTrigger)
            {
                grabberInTrigger = null;
            }

            // Release grabber if out
            if (grab != null && grab == currentGrabber)
            {
                ReleaseGrabber();
            }
        }
Пример #27
0
        public Grabber GetSecondaryGrabber()
        {
            if (grab.HeldByGrabbers != null)
            {
                for (int x = 0; x < grab.HeldByGrabbers.Count; x++)
                {
                    Grabber g = grab.HeldByGrabbers[x];
                    if (g.HandSide == ControllerHand.Left)
                    {
                        return(g);
                    }
                }
            }

            return(null);
        }
Пример #28
0
        public virtual void GrabRemoteItem(Grabber grabbedBy)
        {
            flyingTo                       = grabbedBy;
            grabTransform.parent           = grabbedBy.transform;
            grabTransform.localEulerAngles = Vector3.zero;
            grabTransform.localPosition    = Vector3.zero - GrabPositionOffset;

            grabTransform.transform.localEulerAngles = GrabRotationOffset;

            if (rigid)
            {
                rigid.collisionDetectionMode = CollisionDetectionMode.Discrete;
                rigid.isKinematic            = true;
            }

            remoteGrabbing = true;
        }
Пример #29
0
        bool grabberHasWeapon(Grabber g)
        {
            if (g == null || g.HeldGrabbable == null)
            {
                return(false);
            }

            // Holding shotgun, pistol, or rifle
            string grabName = g.HeldGrabbable.transform.name;

            if (grabName.Contains("Shotgun") || grabName.Contains("Pistol") || grabName.Contains("Rifle"))
            {
                return(true);
            }

            return(false);
        }
Пример #30
0
        void OnTriggerEnter(Collider other)
        {
            Grabber grab = other.GetComponent <Grabber>();

            if (grab != null)
            {
                if (grabbers == null)
                {
                    grabbers = new List <Grabber>();
                }

                if (!grabbers.Contains(grab))
                {
                    grabbers.Add(grab);
                }
            }
        }