Ejemplo n.º 1
0
 private void Awake()
 {
     selfRenderers = this.GetComponentsInChildren <Renderer>();
     grabbable     = this.GetComponent <Grabbable>();
     rigidbody     = this.GetComponent <Rigidbody>();
     colliders     = this.GetComponentsInChildren <Collider>();
 }
Ejemplo n.º 2
0
        void SetInteractaleAttachedObject(ref AttachedObject ao, Grabbable grabbable)
        {
            ao.grabbable = grabbable;

            if (grabbable == null)
            {
                return;
            }

            if (grabbable.parameters.hideHandOnAttach)
            {
                SetVisibility(false);
            }
            if (grabbable.parameters.hideSkeletonOnAttach && mainRenderModel != null && mainRenderModel.displayHandByDefault)
            {
                SetSkeletonVisibility(false);
            }
            if (grabbable.parameters.hideControllerOnAttach && mainRenderModel != null && mainRenderModel.displayControllerByDefault)
            {
                SetControllerVisibility(false);
            }
            if (grabbable.parameters.handAnimationOnPickup1 != RenderModel.AnimationState.Rest)
            {
                SetAnimationState(grabbable.parameters.handAnimationOnPickup1);
            }
            if (grabbable.parameters.setRangeOfMotionOnPickup != SkeletalMotionRangeChange.None)
            {
                SetTemporarySkeletonRangeOfMotion(grabbable.parameters.setRangeOfMotionOnPickup);
            }
        }
Ejemplo n.º 3
0
        // Attach a GameObject to this GameObject
        // objectToAttach - The GameObject to attach
        // attachmentPoint - Name of the GameObject in the hierarchy of this Hand which should act as the attachment point for this GameObject
        public void AttachGrabbable(Grabbable interactable_to_attach)//, GrabTypes grabbedWithType, Transform attachmentOffset = null)
        {
            AttachmentFlags flags = interactable_to_attach.parameters.attachmentFlags;

            AttachObj(interactable_to_attach.gameObject,
                      interactable_to_attach, interactable_to_attach.parameters.attach_position_offset,
                      interactable_to_attach.parameters.attach_rotation_offset, flags);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
 private void Start()
 {
     initialScale = transform.localScale;
     grabbable    = GetComponent <Grabbable>();
 }
Ejemplo n.º 8
0
        //-------------------------------------------------
        void Awake()
        {
            grabbable = GetComponentInParent <Grabbable>();

            //
            // Create child game object for see thru renderer
            //
            seeThru = new GameObject("_see_thru");
            seeThru.transform.parent        = transform;
            seeThru.transform.localPosition = Vector3.zero;
            seeThru.transform.localRotation = Quaternion.identity;
            seeThru.transform.localScale    = Vector3.one;

            //
            // Copy mesh filter
            //
            MeshFilter sourceMeshFilter = GetComponent <MeshFilter>();

            if (sourceMeshFilter != null)
            {
                MeshFilter destMeshFilter = seeThru.AddComponent <MeshFilter>();
                destMeshFilter.sharedMesh = sourceMeshFilter.sharedMesh;
            }

            //
            // Copy mesh renderer
            //
            MeshRenderer sourceMeshRenderer = GetComponent <MeshRenderer>();

            if (sourceMeshRenderer != null)
            {
                sourceRenderer = sourceMeshRenderer;
                destRenderer   = seeThru.AddComponent <MeshRenderer>();
            }

            //
            // Copy skinned mesh renderer
            //
            SkinnedMeshRenderer sourceSkinnedMeshRenderer = GetComponent <SkinnedMeshRenderer>();

            if (sourceSkinnedMeshRenderer != null)
            {
                SkinnedMeshRenderer destSkinnedMeshRenderer = seeThru.AddComponent <SkinnedMeshRenderer>();

                sourceRenderer = sourceSkinnedMeshRenderer;
                destRenderer   = destSkinnedMeshRenderer;

                destSkinnedMeshRenderer.sharedMesh          = sourceSkinnedMeshRenderer.sharedMesh;
                destSkinnedMeshRenderer.rootBone            = sourceSkinnedMeshRenderer.rootBone;
                destSkinnedMeshRenderer.bones               = sourceSkinnedMeshRenderer.bones;
                destSkinnedMeshRenderer.quality             = sourceSkinnedMeshRenderer.quality;
                destSkinnedMeshRenderer.updateWhenOffscreen = sourceSkinnedMeshRenderer.updateWhenOffscreen;
            }

            //
            // Create see thru materials
            //
            if (sourceRenderer != null && destRenderer != null)
            {
                int        materialCount         = sourceRenderer.sharedMaterials.Length;
                Material[] destRendererMaterials = new Material[materialCount];
                for (int i = 0; i < materialCount; i++)
                {
                    destRendererMaterials[i] = seeThruMaterial;
                }
                destRenderer.sharedMaterials = destRendererMaterials;

                for (int i = 0; i < destRenderer.materials.Length; i++)
                {
                    destRenderer.materials[i].renderQueue = 2001;                     // Rendered after geometry
                }

                for (int i = 0; i < sourceRenderer.materials.Length; i++)
                {
                    if (sourceRenderer.materials[i].renderQueue == 2000)
                    {
                        sourceRenderer.materials[i].renderQueue = 2002;
                    }
                }
            }

            seeThru.gameObject.SetActive(false);
        }