Esempio n. 1
0
        void AttachObj(GameObject obj_attached, Grabbable grabbable, Vector3 pos_offset, Vector3 rot_offset, AttachmentFlags flags)

        {
            if (flags == 0)
            {
                flags = defaultAttachmentFlags;
            }
            AttachedObject attachedObject = new AttachedObject();

            attachedObject.attachmentFlags = flags;
            //Make sure top object on stack is non-null
            CleanUpAttachedObjectStack();

            //Detach the object if it is already attached so that it can get re-attached at the top of the stack
            if (ObjectIsAttached(obj_attached))
            {
                DetachObject(obj_attached);
            }

            //Detach from the other hand if requested
            if (attachedObject.HasAttachFlag(AttachmentFlags.DetachFromOtherHand))
            {
                otherHand.DetachObject(obj_attached);
            }

            if (attachedObject.HasAttachFlag(AttachmentFlags.DetachOthers))
            {
                //Detach all the objects from the stack
                while (attachedObjects.Count > 0)
                {
                    DetachObject(attachedObjects[0].attachedObject);
                }
            }

            if (currentAttachedObject)
            {
                currentAttachedObject.SendMessage("OnHandFocusLost", this, SendMessageOptions.DontRequireReceiver);
            }

            attachedObject.attachedObject = obj_attached;

            SetInteractaleAttachedObject(ref attachedObject, grabbable);
            attachedObject.originalParent = obj_attached.transform.parent != null ? obj_attached.transform.parent.gameObject : null;
            MaybeParentToHand(ref attachedObject, obj_attached);
            MaybeSnap(ref attachedObject, obj_attached.transform, pos_offset, rot_offset);

            SetPhysicsAttachedObject(ref attachedObject, obj_attached);
            attachedObjects.Add(attachedObject);
            UpdateHovering();
            HandDebugLog("AttachObject " + obj_attached.name);
            obj_attached.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver);
        }
Esempio n. 2
0
        void SetPhysicsAttachedObject(ref AttachedObject ao, GameObject obj_attached)
        {
            Debug.Log("hwjdshfsk");
            ao.attachedRigidbody = obj_attached.GetComponent <Rigidbody>();
            if (ao.attachedRigidbody == null)
            {
                return;
            }


            Grabbable grabbable = ao.grabbable;

            if (grabbable != null && grabbable.attachedToHand != null) //already attached to another hand
            {
                //if it was attached to another hand, get the flags from that hand

                for (int i = 0; i < grabbable.attachedToHand.attachedObjects.Count; i++)
                {
                    AttachedObject attachedObjectInList = grabbable.attachedToHand.attachedObjects[i];
                    if (attachedObjectInList.grabbable == grabbable)
                    {
                        ao.attachedRigidbodyWasKinematic = attachedObjectInList.attachedRigidbodyWasKinematic;
                        ao.attachedRigidbodyUsedGravity  = attachedObjectInList.attachedRigidbodyUsedGravity;
                        ao.originalParent = attachedObjectInList.originalParent;
                    }
                }
            }
            else
            {
                ao.attachedRigidbodyWasKinematic = ao.attachedRigidbody.isKinematic;
                ao.attachedRigidbodyUsedGravity  = ao.attachedRigidbody.useGravity;
            }

            if (ao.HasAttachFlag(AttachmentFlags.TurnOnKinematic))
            {
                Debug.LogError("YOOOO");
                ao.collisionDetectionMode = ao.attachedRigidbody.collisionDetectionMode;
                if (ao.collisionDetectionMode == CollisionDetectionMode.Continuous)
                {
                    ao.attachedRigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
                }
                ao.attachedRigidbody.isKinematic = true;
            }
            if (ao.HasAttachFlag(AttachmentFlags.TurnOffGravity))
            {
                ao.attachedRigidbody.useGravity = false;
            }
        }
Esempio n. 3
0
 void MaybeParentToHand(ref AttachedObject ao, GameObject obj_attached)
 {
     ao.isParentedToHand = ao.HasAttachFlag(AttachmentFlags.ParentToHand);
     //Parent the object to the hand
     if (ao.isParentedToHand)
     {
         obj_attached.transform.parent = this.transform;
     }
 }
Esempio n. 4
0
 void AttachmentsFixedUpdate()
 {
     if (currentAttachedObject != null)
     {
         AttachedObject attachedInfo = currentAttachedObjectInfo.Value;
         if (attachedInfo.attachedObject != null)
         {
             if (attachedInfo.HasAttachFlag(AttachmentFlags.VelocityMovement))
             {
                 UpdateAttachedVelocity(attachedInfo);
             }
         }
     }
 }
Esempio n. 5
0
        // Detach this GameObject from the attached object stack of this Hand
        // objectToDetach - The GameObject to detach from this Hand
        public void DetachObject(GameObject objectToDetach, bool restoreOriginalParent = true)
        {
            int index = attachedObjects.FindIndex(l => l.attachedObject == objectToDetach);

            if (index != -1)
            {
                HandDebugLog("DetachObject " + objectToDetach);

                GameObject     prevTopObject = currentAttachedObject;
                AttachedObject a_obj         = attachedObjects[index];


                Grabbable grabbable = a_obj.grabbable;
                if (grabbable != null)
                {
                    if (grabbable.parameters.hideHandOnAttach)
                    {
                        SetVisibility(true);
                    }
                    if (grabbable.parameters.hideSkeletonOnAttach && mainRenderModel != null && mainRenderModel.displayHandByDefault)
                    {
                        SetSkeletonVisibility(true);
                    }
                    if (grabbable.parameters.hideControllerOnAttach && mainRenderModel != null && mainRenderModel.displayControllerByDefault)
                    {
                        SetControllerVisibility(true);
                    }
                    if (grabbable.parameters.handAnimationOnPickup1 != RenderModel.AnimationState.Rest)
                    {
                        StopAnimation();
                    }
                    if (grabbable.parameters.setRangeOfMotionOnPickup != SkeletalMotionRangeChange.None)
                    {
                        ResetTemporarySkeletonRangeOfMotion();
                    }
                }

                Transform parentTransform = null;
                if (a_obj.isParentedToHand)
                {
                    if (restoreOriginalParent && (a_obj.originalParent != null))
                    {
                        parentTransform = a_obj.originalParent.transform;
                    }
                    a_obj.attachedObject.transform.parent = parentTransform;
                }

                if (a_obj.HasAttachFlag(AttachmentFlags.TurnOnKinematic))
                {
                    if (a_obj.attachedRigidbody != null)
                    {
                        a_obj.attachedRigidbody.isKinematic            = a_obj.attachedRigidbodyWasKinematic;
                        a_obj.attachedRigidbody.collisionDetectionMode = a_obj.collisionDetectionMode;
                    }
                }

                if (a_obj.HasAttachFlag(AttachmentFlags.TurnOffGravity))
                {
                    if (a_obj.attachedRigidbody != null)
                    {
                        a_obj.attachedRigidbody.useGravity = a_obj.attachedRigidbodyUsedGravity;
                    }
                }

                if (grabbable == null || (grabbable != null && grabbable.isDestroying == false))
                {
                    a_obj.attachedObject.SetActive(true);
                    a_obj.attachedObject.SendMessage("OnDetachedFromHand", this, SendMessageOptions.DontRequireReceiver);
                    attachedObjects.RemoveAt(index);
                }
                else
                {
                    attachedObjects.RemoveAt(index);
                }

                CleanUpAttachedObjectStack();

                GameObject newTopObject = currentAttachedObject;

                hoverLocked = false;


                //Give focus to the top most object on the stack if it changed
                if (newTopObject != null && newTopObject != prevTopObject)
                {
                    newTopObject.SetActive(true);
                    newTopObject.SendMessage("OnHandFocusAcquired", this, SendMessageOptions.DontRequireReceiver);
                }
            }

            CleanUpAttachedObjectStack();

            if (mainRenderModel != null)
            {
                mainRenderModel.MatchHandToTransform(mainRenderModel.transform);
            }
            if (hoverhighlightRenderModel != null)
            {
                hoverhighlightRenderModel.MatchHandToTransform(hoverhighlightRenderModel.transform);
            }
        }