コード例 #1
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
 private void OffhandGrabbed(Grabbable grabbable)
 {
     if (Grabbable == grabbable)
     {
         GrabbableRelease(Vector3.zero, Vector3.zero);
     }
 }
コード例 #2
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
        private void OnTriggerExit(Collider other)
        {
            Grabbable grabbable = other.GetComponentInParent <Grabbable>();

            if (grabbable == null)
            {
                return;
            }

            // Remove the grabbable
            int  refCount = 0;
            bool found    = GrabCandidates.TryGetValue(grabbable, out refCount);

            if (!found)
            {
                return;
            }

            if (refCount > 1)
            {
                GrabCandidates[grabbable] = refCount - 1;
            }
            else
            {
                GrabCandidates.Remove(grabbable);
            }
        }
コード例 #3
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
        public void ForceRelease(Grabbable grabbable)
        {
            bool canRelease = (
                (Grabbable != null) &&
                (Grabbable == grabbable)
                );

            if (canRelease)
            {
                GrabEnd();
            }
        }
コード例 #4
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
        private void GrabBegin()
        {
            float     closestMagSq             = float.MaxValue;
            Grabbable closestGrabbable         = null;
            Collider  closestGrabbableCollider = null;
            Vector3   closestGrabbableRotation = Vector3.zero;

            foreach (Grabbable grabbable in GrabCandidates.Keys)
            {
                for (int j = 0; j < grabbable.GrabPoints.Length; ++j)
                {
                    Collider grabbableCollider = grabbable.GrabPoints[j];
                    // Store the closest grabbable
                    Vector3 closestPointOnBounds = grabbableCollider.ClosestPointOnBounds(GrabPoint.position);
                    float   grabbableMagSq       = (GrabPoint.position - closestPointOnBounds).sqrMagnitude;
                    if (grabbableMagSq < closestMagSq)
                    {
                        closestMagSq             = grabbableMagSq;
                        closestGrabbable         = grabbable;
                        closestGrabbableCollider = grabbableCollider;
                        closestGrabbableRotation = grabbable.GrabRotations[j];
                    }
                }
            }

            // Disable grab volumes to prevent overlaps
            GrabVolumeEnable(false);

            if (closestGrabbable != null)
            {
                if (closestGrabbable.IsGrabbed)
                {
                    closestGrabbable.GrabbedBy.OffhandGrabbed(closestGrabbable);
                }

                Grabbable = closestGrabbable;
                Grabbable.SetLayer(GrabbableLayerInt);
                Grabbable.GrabBegin(this, closestGrabbableCollider, closestGrabbableRotation);

                // Set up offsets for grabbed object desired position relative to hand.
                GrabObjectPosOffset = -Grabbable.GrabbedCollider.transform.localPosition;
                GrabObjectRotOffset = Quaternion.Euler(Grabbable.GrabbedRotation);

                // TODO: force teleport on grab, to avoid high-speed travel to dest which hits a lot of other objects at high
                // speed and sends them flying. The grabbed object may still teleport inside of other objects.
                MoveGrabbedObject(GrabPoint.transform.position, GrabPoint.transform.rotation);

                RenderersEnable(false);
            }
        }
コード例 #5
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
        private void OnTriggerEnter(Collider other)
        {
            // Get the grab trigger
            Grabbable grabbable = other.GetComponentInParent <Grabbable>();

            if (grabbable == null)
            {
                return;
            }

            // Add the grabbable
            int refCount = 0;

            GrabCandidates.TryGetValue(grabbable, out refCount);
            GrabCandidates[grabbable] = refCount + 1;
        }
コード例 #6
0
ファイル: Grabber.cs プロジェクト: JLPM22/MinecraftVRUnity
 private void GrabbableRelease(Vector3 linearVelocity, Vector3 angularVelocity)
 {
     Grabbable.SetLayer(Grabbable.DefaultLayer);
     Grabbable.GrabEnd(linearVelocity, angularVelocity);
     Grabbable = null;
 }