Ejemplo n.º 1
0
    public void GrabUpdateCustom()
    {
        if (grabPoser)
        {
            skeleton.BlendToPoser(grabPoser, 0);

            posSavePoser = grabPoser.transform.localPosition;
            rotSavePoser = grabPoser.transform.localEulerAngles;

            grabPoser.transform.rotation = transform.rotation * grabPoser.GetBlendedPose(skeleton).rotation;
            grabPoser.transform.position = transform.TransformPoint(grabPoser.GetBlendedPose(skeleton).position);

            PivotUpdate();

            inverceLocalPosition = grabPoser.transform.InverseTransformPoint(transform.position);

            grabPoser.transform.localPosition    = posSavePoser;
            grabPoser.transform.localEulerAngles = rotSavePoser;

            skeleton.transform.position = grabPoser.transform.TransformPoint(inverceLocalPosition);
            skeleton.transform.rotation = grabPoser.transform.rotation * Quaternion.Inverse(grabPoser.GetBlendedPose(skeleton).rotation);
            BlendControll(false);
            skeleton.skeletonBlend = blendToAnimation;
        }
    }
Ejemplo n.º 2
0
    public void GrabUpdateCustom()
    {
        if (grabPoser)
        {
            skeleton.BlendToPoser(grabPoser, 0);

            posSavePoser = grabPoser.transform.localPosition;
            rotSavePoser = grabPoser.transform.localEulerAngles;

            grabPoser.transform.rotation = transform.rotation * grabPoser.GetBlendedPose(skeleton).rotation;
            grabPoser.transform.position = transform.TransformPoint(grabPoser.GetBlendedPose(skeleton).position);

            PivotUpdate();

            inverceLocalPosition = grabPoser.transform.InverseTransformPoint(transform.position);

            grabPoser.transform.localPosition    = posSavePoser;
            grabPoser.transform.localEulerAngles = rotSavePoser;

            skeleton.transform.position = grabPoser.transform.TransformPoint(inverceLocalPosition);
            skeleton.transform.rotation = grabPoser.transform.rotation * Quaternion.Inverse(grabPoser.GetBlendedPose(skeleton).rotation);
            if (blend > 0)
            {
                blendToAnimation -= 1f / blend * Time.deltaTime;
                blendToAnimation  = Mathf.Clamp01(blendToAnimation);
                blendToPose      -= 1f / blendPosition * Time.deltaTime;
                blendToPose       = Mathf.Clamp01(blendToPose);
            }
            else
            {
                blendToAnimation = 0;
            }
            skeleton.skeletonBlend = blendToAnimation;
        }
    }
Ejemplo n.º 3
0
    private void Grip()
    {
        GameObject NewObject = grabber.ClosestGrabbable();              //get the closest grabbable

        if (NewObject != null)                                          //if it is defined
        {
            OffsetObject    = grabber.ClosestGrabbable().transform;     //set the offset
            ConnectedObject = OffsetObject.transform.parent.gameObject; //set the root of the grabbable as the connected object
            ConnectedObject.GetComponent <Rigidbody>().useGravity = false;
            ConnectedObject.GetComponent <Block>().PickedUp();
            ConnectedObject.GetComponent <Rigidbody>().mass = 1;

            if (ConnectedObject.GetComponent <Interactable>().gripped)//if the object has already been grabbed (we know that it's not a grip point that has already been grabbed since those arn't put in the grabbable array)
            {
                SecondGrip = true;
                ConnectedObject.GetComponent <Interactable>().SecondGripped = true;
                grabber.WeakGrip.connectedBody   = ConnectedObject.GetComponent <Rigidbody>(); //attach the correct joint.
                grabber.WeakGrip.connectedAnchor = OffsetObject.localPosition;                 //set the offest
            }
            else//if we are the first to grab it
            {
                ConnectedObject.GetComponent <Interactable>().Hand    = Hand;
                ConnectedObject.GetComponent <Interactable>().gripped = true;
            }
            if (OffsetObject.GetComponent <SteamVR_Skeleton_Poser>() && HandSkeleton)//if the object has a defined skeleton poser update our hand
            {
                HandSkeleton.transform.SetParent(OffsetObject, false);
                HandSkeleton.BlendToPoser(OffsetObject.GetComponent <SteamVR_Skeleton_Poser>(), 0f);
            }
        }
    }
Ejemplo n.º 4
0
 public void OnGripPose(SteamVR_Behaviour_Skeleton skeleton)
 {
     if (skeletonPoser != null && skeleton != null)
     {
         Debug.Log("On Pose");
         skeleton.BlendToPoser(skeletonPoser, blendToPoseTime);
     }
 }
Ejemplo n.º 5
0
        void OnItemEquipped(Inventory inventory, Item item, int equipSlot, bool quickEquipped)
        {
            if (equipSlot != myEquipIndex)
            {
                return;
            }

            if (quickEquipped)
            {
                if (item.itemBehavior.equipType != Inventory.EquipType.Static && item.rigidbody != null)
                {
                    GetComponent <VelocityEstimator>().BeginEstimatingVelocity();
                }
            }

            VRItemAddon vr_item = item.GetComponent <VRItemAddon>();

            if (!vr_item)
            {
                Debug.LogError(item.name + " :: does not have a vr item component");
                return;
            }

            if (vr_item.hideHandOnAttach)
            {
                Hide();
            }



            // if (vr_item.handAnimationOnPickup != 0) {
            //         // Debug.LogError("animation state");

            //     SetAnimationState(vr_item.handAnimationOnPickup);
            // }

            if (vr_item.setRangeOfMotionOnPickup != SkeletalMotionRangeChange.None)
            {
                // Debug.LogError("range of mot ion");
                SetTemporarySkeletonRangeOfMotion(vr_item.setRangeOfMotionOnPickup);
            }

            if (vr_item.usePose)
            {
                // if (!string.IsNullOrEmpty(vr_item.poseName)) {//.skeletonPoser != null)
                // if (vr_item.skeletonPoser != null && skeleton != null) {

                // Debug.LogError("blendign to poser");
                skeleton.BlendToPoser(vr_item.poseName, vr_item.poseInfluence, blendToPoseTime);
                // }
            }

            if (vr_item.activateActionSetOnAttach != null)
            {
                vr_item.activateActionSetOnAttach.Activate(handType);
            }
        }
Ejemplo n.º 6
0
    private void Grip()
    {
        GameObject NewObject = grabber.ClosestGrabbable();

        if (NewObject != null)
        {
            OffsetObject    = grabber.ClosestGrabbable().transform;
            ConnectedObject = OffsetObject.GetComponent <GrabPoint>().ParentInteractable.gameObject;//find the Closest Grabbable and set it to the connected object
            ConnectedObject.GetComponent <Rigidbody>().useGravity = false;

            OffsetObject.GetComponent <GrabPoint>().Gripped = true;
            if (ConnectedObject.GetComponent <Interactable>().gripped)
            {
                ConnectedObject.GetComponent <Interactable>().SecondGripped = true;
                if (OffsetObject.GetComponent <GrabPoint>().HelperGrip)
                {
                    DomanantGrip = false;
                    grabber.WeakGrip.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();
                    grabber.WeakGrip.connectedAnchor = OffsetObject.GetComponent <GrabPoint>().Offset;
                }
                grabber.WeakGrip.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();
                grabber.WeakGrip.connectedAnchor = OffsetObject.GetComponent <GrabPoint>().Offset;
            }
            else
            {
                ConnectedObject.GetComponent <Interactable>().Hand    = Hand;
                ConnectedObject.GetComponent <Interactable>().gripped = true;
                if (!OffsetObject.GetComponent <GrabPoint>().HelperGrip)
                {
                    DomanantGrip = true;
                    ConnectedObject.GetComponent <Interactable>().GrippedBy = transform.parent.gameObject;
                }
            }
            if (OffsetObject.GetComponent <SteamVR_Skeleton_Poser>() && HandSkeleton)
            {
                HandSkeleton.transform.SetParent(OffsetObject, false);
                HandSkeleton.BlendToPoser(OffsetObject.GetComponent <SteamVR_Skeleton_Poser>(), 0f);
            }
        }
    }
Ejemplo n.º 7
0
    private bool SecondGrip;                        //are we the second hand to grip the object
    private void Update()
    {
        if (ConnectedObject != null)
        {
            Debug.Log(ConnectedObject.name);
        }

        if (ConnectedObject != null)                                                                                                               //If we are holding something
        {
            if (!SecondGrip)                                                                                                                       //and we are not the second hand
            {
                if (ConnectedObject.GetComponent <Interactable>().touchCount == 0 && !ConnectedObject.GetComponent <Interactable>().SecondGripped) //If the held object isn't touching anything
                {
                    grabber.FixedJoint.connectedBody = null;                                                                                       //disconnect the rigid jont to reset it
                    //grabber.StrongGrip.connectedBody = null;//and all the other joints just to be sure
                    //these two lines move the connected object to the hands position over time to give a snappy feel to picking stuff up, otherwise you could just teleport the object to the right position

                    ConnectedObject.transform.position = Vector3.MoveTowards(ConnectedObject.transform.position, transform.position - (ConnectedObject.transform.rotation * OffsetObject.GetComponent <GrabPoint>().Offset), .1f); //move and rotate the object to the hands position
                    ConnectedObject.transform.rotation = Quaternion.RotateTowards(ConnectedObject.transform.rotation, transform.rotation * Quaternion.Inverse(OffsetObject.localRotation), 10);
                    grabber.FixedJoint.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();                                                                                                                               //reconnect the rigid joint
                }
                else if (ConnectedObject.GetComponent <Interactable>().touchCount > 0 || ConnectedObject.GetComponent <Interactable>().SecondGripped)                                                                              //the object is touching something so use a configurable joint.
                {
                    grabber.FixedJoint.connectedBody = null;
                    //grabber.StrongGrip.connectedAnchor = OffsetObject.GetComponent<GrabPoint>().Offset;
                    //grabber.StrongGrip.connectedBody = ConnectedObject.GetComponent<Rigidbody>();
                }
            }
            else if (SecondGrip)                                            // if we are the second hand just use the weak grip that doesnt have an agular drive
            {
                if (!ConnectedObject.GetComponent <Interactable>().gripped) //if the other hand lets go use a configurable joint
                {
                    grabber.FixedJoint.connectedBody = null;
                    //grabber.StrongGrip.connectedAnchor = OffsetObject.GetComponent<GrabPoint>().Offset;
                    //grabber.StrongGrip.connectedBody = ConnectedObject.GetComponent<Rigidbody>();
                }
                else
                {
                    grabber.FixedJoint.connectedBody = null;
                    //grabber.StrongGrip.connectedBody = null;
                    //grabber.WeakGrip.connectedBody = ConnectedObject.GetComponent<Rigidbody>();
                }
            }
            if (ToggleGripButton.GetStateUp(Hand))//check for if we want to let go
            {
                Release();
            }
            if (PreviewSkeleton)//hide the preview hand since we are holding somthing
            {
                PreviewSkeleton.transform.gameObject.SetActive(false);
            }
        }
        else//if we arn't holding anything
        {
            if (grabber.ClosestGrabbable() && PreviewSkeleton)//if there is somthing close and we have a preview hand assigned
            {
                PreviewSkeleton.transform.gameObject.SetActive(true);                                                                                                                                                                                                     //activate the hand
                OffsetObject = grabber.ClosestGrabbable().transform;                                                                                                                                                                                                      //parent it to the object
                if (grabber.ClosestGrabbable().GetComponent <SteamVR_Skeleton_Poser>())                                                                                                                                                                                   //if the object has a skeleton poser
                {
                    if (!OffsetObject.GetComponent <GrabPoint>().SubGrip&& !OffsetObject.transform.parent.GetComponent <Interactable>().gripped || OffsetObject.GetComponent <GrabPoint>().SubGrip&& OffsetObject.transform.parent.GetComponent <Interactable>().gripped) //if the object is not gripped at all or is gripped by both hands
                    {
                        PreviewSkeleton.transform.SetParent(OffsetObject, false);
                        PreviewSkeleton.BlendToPoser(OffsetObject.GetComponent <SteamVR_Skeleton_Poser>(), 0f);
                    }
                }
            }
            else//if there is no object in range deactivate the hand
            {
                PreviewSkeleton.transform.gameObject.SetActive(false);
            }
            if (ToggleGripButton.GetStateDown(Hand))//check for if we want to grip
            {
                Grip();
            }
        }
    }
Ejemplo n.º 8
0
    private void Update()
    {
        if (ConnectedObject != null)
        {
            if (DomanantGrip || !ConnectedObject.GetComponent <Interactable>().SecondGripped)
            {
                if (ConnectedObject.GetComponent <Interactable>().touchCount == 0 && !ConnectedObject.GetComponent <Interactable>().SecondGripped)
                {
                    grabber.FixedJoint.connectedBody = null;
                    grabber.StrongGrip.connectedBody = null;

                    ConnectedObject.transform.position = Vector3.MoveTowards(ConnectedObject.transform.position, transform.position - ConnectedObject.transform.rotation * OffsetObject.GetComponent <GrabPoint>().Offset, .25f);
                    ConnectedObject.transform.rotation = Quaternion.RotateTowards(ConnectedObject.transform.rotation, transform.rotation * Quaternion.Inverse(OffsetObject.GetComponent <GrabPoint>().RotationOffset), 10);
                    grabber.FixedJoint.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();
                }
                else if (ConnectedObject.GetComponent <Interactable>().touchCount > 0 || ConnectedObject.GetComponent <Interactable>().SecondGripped)
                {
                    grabber.FixedJoint.connectedBody   = null;
                    grabber.StrongGrip.connectedAnchor = OffsetObject.GetComponent <GrabPoint>().Offset;
                    grabber.StrongGrip.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();
                }
                else if (ConnectedObject.GetComponent <Interactable>().touchCount < 0)
                {
                    ConnectedObject.GetComponent <Interactable>().touchCount = 0;
                }
            }
            else
            {
                grabber.FixedJoint.connectedBody = null;
                grabber.StrongGrip.connectedBody = null;
                grabber.WeakGrip.connectedBody   = ConnectedObject.GetComponent <Rigidbody>();
            }
            if (ToggleGripButton.GetStateUp(Hand))
            {
                Release();
            }
            if (PreviewSkeleton)
            {
                PreviewSkeleton.transform.gameObject.SetActive(false);
            }
        }
        else
        {
            if (grabber.ClosestGrabbable() && PreviewSkeleton)
            {
                PreviewSkeleton.transform.gameObject.SetActive(true);
                OffsetObject = grabber.ClosestGrabbable().transform;
                if (grabber.ClosestGrabbable().GetComponent <SteamVR_Skeleton_Poser>())
                {
                    if (!OffsetObject.GetComponent <GrabPoint>().Gripped)
                    {
                        PreviewSkeleton.transform.SetParent(OffsetObject, false);
                        PreviewSkeleton.BlendToPoser(OffsetObject.GetComponent <SteamVR_Skeleton_Poser>(), 0f);
                    }
                }
            }
            else
            {
                PreviewSkeleton.transform.gameObject.SetActive(false);
            }
            if (ToggleGripButton.GetStateDown(Hand))
            {
                Grip();
            }
        }
    }
Ejemplo n.º 9
0
 internal void NotifyAttachedTo(SteamVR_Skeleton_Poser poser)
 {
     _skeleton.BlendToPoser(poser);
 }