Exemple #1
0
        //-------------------------------------------------
        // Attach a GameObject to this GameObject
        //
        // objectToAttach - The GameObject to attach
        // flags - The flags to use for attaching the object
        // attachmentPoint - Name of the GameObject in the hierarchy of this Hand which should act as the attachment point for this GameObject
        //-------------------------------------------------
        public void AttachObject(GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags, string attachmentPoint = "")
        {
            if (flags == 0)
            {
                flags = defaultAttachmentFlags;
            }

            //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
            DetachObject(objectToAttach);

            //Detach from the other hand if requested
            if (((flags & AttachmentFlags.DetachFromOtherHand) == AttachmentFlags.DetachFromOtherHand) && otherHand)
            {
                otherHand.DetachObject(objectToAttach);
            }

            if ((flags & AttachmentFlags.DetachOthers) == 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 = new AttachedObject();

            attachedObject.attachedObject = objectToAttach;
            attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null;
            if ((flags & AttachmentFlags.ParentToHand) == AttachmentFlags.ParentToHand)
            {
                //Parent the object to the hand
                objectToAttach.transform.parent = GetAttachmentTransform(attachmentPoint);
                attachedObject.isParentedToHand = true;
            }
            else
            {
                attachedObject.isParentedToHand = false;
            }
            attachedObjects.Add(attachedObject);

            if ((flags & AttachmentFlags.SnapOnAttach) == AttachmentFlags.SnapOnAttach)
            {
                objectToAttach.transform.localPosition = Vector3.zero;
                objectToAttach.transform.localRotation = Quaternion.identity;
            }

            HandDebugLog("AttachObject " + objectToAttach);
            objectToAttach.SendMessage("OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver);

            UpdateHovering();
        }
Exemple #2
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);
        }
Exemple #3
0
 internal static uint ParseAttachmentFlags(AttachmentFlags flags)
 {
     if (flags == AttachmentFlags.InvisibleInHtml)
     {
         return(1);
     }
     else if (flags == AttachmentFlags.InvisibleInRtf)
     {
         return(2);
     }
     else
     {
         return(0);
     }
 }
	/// <summary>
	/// Attach a GameObject to this GameObject.
	/// </summary>
	/// <param name="objectToAttach">The GameObject to attach.</param>
	/// <param name="flags">The flags to use for attaching the object.</param>
	/// <param name="attachmentPoint">Name of the GameObject in the hierarchy of this VRHand which should act as the attachment point for this GameObject.</param>
	/// <seealso cref="DetachObject"/>
	public void AttachObject( GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags, string attachmentPoint = "" )
	{
		if ( flags == 0 )
		{
			flags = defaultAttachmentFlags;
		}

		//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
		DetachObject( objectToAttach );

		//Detach from the other hand if requested
		if ( ( ( flags & AttachmentFlags.DetachFromOtherHand ) == AttachmentFlags.DetachFromOtherHand ) && otherHand )
		{
			otherHand.DetachObject( objectToAttach );
		}

		if ( ( flags & AttachmentFlags.DetachOthers ) == 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 = new AttachedObject();
		attachedObject.attachedObject = objectToAttach;
		attachedObject.originalParent = objectToAttach.transform.parent != null ? objectToAttach.transform.parent.gameObject : null;
		if ( ( flags & AttachmentFlags.ParentToHand ) == AttachmentFlags.ParentToHand )
		{
			//Parent the object to the hand
			objectToAttach.transform.parent = GetAttachmentTransform( attachmentPoint );
			attachedObject.isParentedToHand = true;
		}
		else
		{
			attachedObject.isParentedToHand = false;
		}
		attachedObjects.Add( attachedObject );

		if ( ( flags & AttachmentFlags.SnapOnAttach ) == AttachmentFlags.SnapOnAttach )
		{
			objectToAttach.transform.localPosition = Vector3.zero;
			objectToAttach.transform.localRotation = Quaternion.identity;
		}

		VRHandDebugLog( "AttachObject " + objectToAttach );
		objectToAttach.SendMessage( "OnAttachedToHand", this, SendMessageOptions.DontRequireReceiver );

		UpdateHovering();
	}
Exemple #5
0
 public bool HasAttachFlag(AttachmentFlags flag)
 {
     return((attachmentFlags & flag) == flag);
 }
Exemple #6
0
 // Attach a GameObject to this GameObject
 // objectToAttach - The GameObject to attach
 // flags - The flags to use for attaching the object
 // attachmentPoint - Name of the GameObject in the hierarchy of this Hand which should act as the attachment point for this GameObject
 public void AttachGameObject(GameObject objectToAttach, AttachmentFlags flags = defaultAttachmentFlags)
 {
     AttachObj(objectToAttach, null, Vector3.zero, Vector3.zero, flags);
 }
Exemple #7
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);
        }