{"_id":"5b1f8576c2505d00031254a2","category":{"_id":"5b1f8576c2505d0003125425","version":"5b1f8576c2505d00031254db","project":"571fa55ca0acd42000af9545","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-07-31T16:56:01.612Z","from_sync":false,"order":1,"slug":"prefabs","title":"Prefabs"},"user":"571fa519db52d01700f5cf3d","parentDoc":null,"project":"571fa55ca0acd42000af9545","version":{"_id":"5b1f8576c2505d00031254db","project":"571fa55ca0acd42000af9545","__v":4,"forked_from":"594949e52be16d0026ec04cd","createdAt":"2017-06-20T16:14:29.816Z","releaseDate":"2017-06-20T16:14:29.816Z","categories":["5b1f8576c2505d0003125424","5b1f8576c2505d0003125425","5b1f8576c2505d0003125426","5b1f8576c2505d0003125427","5b1f8576c2505d0003125428","5b1f8576c2505d0003125429","5b1f8576c2505d000312542a","5b1f8576c2505d000312542b","5b1f8576c2505d000312542c","5b1f8576c2505d000312542d","5b1f8576c2505d000312542e","5b1f8576c2505d000312542f","5b1f8576c2505d0003125430","5b1f8576c2505d0003125431","5b1f8576c2505d0003125432","5b1f8576c2505d0003125433","5b1f8576c2505d0003125434","5b1f8576c2505d0003125435","5b1f8576c2505d0003125436","5b1f8576c2505d0003125437","5b1f8576c2505d0003125438","5b1f8aab9c683000032979e7","5b1f8b2f3073470003ffa5da","5b1f8bd9fd653400031d94f4","5b1f900bd4c5f000036b57bd"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Mangalica","version_clean":"3.3.0","version":"3.3.0"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:35:11.740Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":8,"body":"## Overview\n\nProvides a predefined zone where a valid interactable object can be dropped and upon dropping it snaps to the set snap drop zone transform position, rotation and scale.\n\n**Prefab Usage:**\n * Place the `VRTK/Prefabs/SnapDropZone/SnapDropZone` prefab into the scene hierarchy.\n * Provide the SnapDropZone with an optional `Highlight Object Prefab` to generate an object outline in the scene that determines the final position, rotation and scale of the snapped object.\n * If no `VRTK_BaseHighlighter` derivative is applied to the SnapDropZone then the default MaterialColorSwap Highlighter will be used.\n * The collision zone that activates the SnapDropZone is a `Sphere Collider` by default but can be amended or replaced on the SnapDropZone GameObject.\n * If the `Use Joint` Snap Type is selected then a custom Joint component is required to be added to the `SnapDropZone` Game Object and upon release the interactable object's rigidbody will be linked to this joint as the `Connected Body`.\n\n## Inspector Parameters\n\n * **Highlight Object Prefab:** A game object that is used to draw the highlighted destination for within the drop zone. This object will also be created in the Editor for easy placement.\n * **Snap Type:** The Snap Type to apply when a valid interactable object is dropped within the snap zone.\n * **Snap Duration:** The amount of time it takes for the object being snapped to move into the new snapped position, rotation and scale.\n * **Apply Scaling On Snap:** If this is checked then the scaled size of the snap drop zone will be applied to the object that is snapped to it.\n * **Clone New On Unsnap:** If this is checked then when the snapped object is unsnapped from the drop zone, a clone of the unsnapped object will be snapped back into the drop zone.\n * **Highlight Color:** The colour to use when showing the snap zone is active. This is used as the highlight colour when no object is hovering but `Highlight Always Active` is true.\n * **Valid Highlight Color:** The colour to use when showing the snap zone is active and a valid object is hovering. If this is `Color.clear` then the `Highlight Color` will be used.\n * **Highlight Always Active:** The highlight object will always be displayed when the snap drop zone is available even if a valid item isn't being hovered over.\n * **Valid Object List Policy:** A specified VRTK_PolicyList to use to determine which interactable objects will be snapped to the snap drop zone on release.\n * **Display Drop Zone In Editor:** If this is checked then the drop zone highlight section will be displayed in the scene editor window.\n * **Default Snapped Interactable Object:** The Interactable Object to snap into the dropzone when the drop zone is enabled. The Interactable Object must be valid in any given policy list to snap.\n\n## Class Variables\n\n * `public enum SnapTypes` - The types of snap on release available.\n   * `UseKinematic` - Will set the interactable object rigidbody to `isKinematic = true`.\n   * `UseJoint` - Will attach the interactable object's rigidbody to the provided joint as it's `Connected Body`.\n   * `UseParenting` - Will set the SnapDropZone as the interactable object's parent and set it's rigidbody to `isKinematic = true`.\n\n## Class Events\n\n * `ObjectEnteredSnapDropZone` - Emitted when a valid interactable object enters the snap drop zone trigger collider.\n * `ObjectExitedSnapDropZone` - Emitted when a valid interactable object exists the snap drop zone trigger collider.\n * `ObjectSnappedToDropZone` - Emitted when an interactable object is successfully snapped into a drop zone.\n * `ObjectUnsnappedFromDropZone` - Emitted when an interactable object is removed from a snapped drop zone.\n\n## Unity Events\n\nAdding the `VRTK_SnapDropZone_UnityEvents` component to `VRTK_SnapDropZone` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * All C# delegate events are mapped to a Unity Event with the `On` prefix. e.g. `MyEvent` -> `OnMyEvent`.\n\n## Event Payload\n\n * `GameObject snappedObject` - The interactable object that is dealing with the snap drop zone.\n\n## Class Methods\n\n### InitaliseHighlightObject/1\n\n  > `public virtual void InitaliseHighlightObject(bool removeOldObject = false)`\n\n * Parameters\n   * `bool removeOldObject` - If this is set to true then it attempts to delete the old highlight object if it exists. Defaults to `false`\n * Returns\n   * _none_\n\nThe InitaliseHighlightObject method sets up the highlight object based on the given Highlight Object Prefab.\n\n### ForceSnap/1\n\n  > `public virtual void ForceSnap(GameObject objectToSnap)`\n\n * Parameters\n   * `GameObject objectToSnap` - The GameObject to attempt to snap.\n * Returns\n   * _none_\n\nthe ForceSnap method attempts to automatically attach a valid GameObject to the snap drop zone.\n\n### ForceUnsnap/0\n\n  > `public virtual void ForceUnsnap()`\n\n * Parameters\n   * _none_\n * Returns\n   * _none_\n\nThe ForceUnsnap method attempts to automatically remove the current snapped game object from the snap drop zone.\n\n### ValidSnappableObjectIsHovering/0\n\n  > `public virtual bool ValidSnappableObjectIsHovering()`\n\n * Parameters\n   * _none_\n * Returns\n   * `bool` - Returns true if a valid object is currently in the snap drop zone area.\n\nThe ValidSnappableObjectIsHovering method determines if any valid objects are currently hovering in the snap drop zone area.\n\n### IsObjectHovering/1\n\n  > `public virtual bool IsObjectHovering(GameObject checkObject)`\n\n * Parameters\n   * `GameObject checkObject` - The GameObject to check to see if it's hovering in the snap drop zone area.\n * Returns\n   * `bool` - Returns true if the given GameObject is hovering (but not snapped) in the snap drop zone area.\n\nThe IsObjectHovering method determines if the given GameObject is currently howvering (but not snapped) in the snap drop zone area.\n\n### IsInteractableObjectHovering/1\n\n  > `public virtual bool IsInteractableObjectHovering(VRTK_InteractableObject checkObject)`\n\n * Parameters\n   * `VRTK_InteractableObject checkObject` - The Interactable Object script to check to see if it's hovering in the snap drop zone area.\n * Returns\n   * `bool` - Returns true if the given Interactable Object script is hovering (but not snapped) in the snap drop zone area.\n\nThe IsInteractableObjectHovering method determines if the given Interactable Object script is currently howvering (but not snapped) in the snap drop zone area.\n\n### GetHoveringObjects/0\n\n  > `public virtual List<GameObject> GetHoveringObjects()`\n\n * Parameters\n   * _none_\n * Returns\n   * `List<GameObject>` - The List of valid GameObjects that are hovering (but not snapped) in the snap drop zone area.\n\nThe GetHoveringObjects method returns a List of valid GameObjects that are currently hovering (but not snapped) in the snap drop zone area.\n\n### GetHoveringInteractableObjects/0\n\n  > `public virtual List<VRTK_InteractableObject> GetHoveringInteractableObjects()`\n\n * Parameters\n   * _none_\n * Returns\n   * `List<VRTK_InteractableObject>` - The List of valid Interactable Object scripts that are hovering (but not snapped) in the snap drop zone area.\n\nThe GetHoveringInteractableObjects method returns a List of valid Interactable Object scripts that are currently hovering (but not snapped) in the snap drop zone area.\n\n### GetCurrentSnappedObject/0\n\n  > `public virtual GameObject GetCurrentSnappedObject()`\n\n * Parameters\n   * _none_\n * Returns\n   * `GameObject` - The GameObject that is currently snapped in the snap drop zone area.\n\nThe GetCurrentSnappedObejct method returns the GameObject that is currently snapped in the snap drop zone area.\n\n### GetCurrentSnappedInteractableObject/0\n\n  > `public virtual VRTK_InteractableObject GetCurrentSnappedInteractableObject()`\n\n * Parameters\n   * _none_\n * Returns\n   * `VRTK_InteractableObject` - The Interactable Object script that is currently snapped in the snap drop zone area.\n\nThe GetCurrentSnappedInteractableObject method returns the Interactable Object script that is currently snapped in the snap drop zone area.\n\n### Clone/1\n\n  > `public virtual GameObject Clone(Vector3 position)`\n\n * Parameters\n   * `Vector3 position` - Position of the cloned GameObject\n * Returns\n   * `GameObject` - The GameObject of the clone\n\nThe Clone method returns the GameObject of the cloned snap drop zone\n\n### Clone/0\n\n  > `public virtual GameObject Clone()`\n\n * Parameters\n   * _none_\n * Returns\n   * `GameObject` - The GameObject of the clone\n\nThe Clone method returns the GameObject of the cloned snap drop zone\n\n## Example\n\n`VRTK/Examples/041_Controller_ObjectSnappingToDropZones` uses the `VRTK_SnapDropZone` prefab to set up pre-determined snap zones for a range of objects and demonstrates how only objects of certain types can be snapped into certain areas.","excerpt":"","slug":"snap-drop-zone","type":"basic","title":"Snap Drop Zone"}
## Overview Provides a predefined zone where a valid interactable object can be dropped and upon dropping it snaps to the set snap drop zone transform position, rotation and scale. **Prefab Usage:** * Place the `VRTK/Prefabs/SnapDropZone/SnapDropZone` prefab into the scene hierarchy. * Provide the SnapDropZone with an optional `Highlight Object Prefab` to generate an object outline in the scene that determines the final position, rotation and scale of the snapped object. * If no `VRTK_BaseHighlighter` derivative is applied to the SnapDropZone then the default MaterialColorSwap Highlighter will be used. * The collision zone that activates the SnapDropZone is a `Sphere Collider` by default but can be amended or replaced on the SnapDropZone GameObject. * If the `Use Joint` Snap Type is selected then a custom Joint component is required to be added to the `SnapDropZone` Game Object and upon release the interactable object's rigidbody will be linked to this joint as the `Connected Body`. ## Inspector Parameters * **Highlight Object Prefab:** A game object that is used to draw the highlighted destination for within the drop zone. This object will also be created in the Editor for easy placement. * **Snap Type:** The Snap Type to apply when a valid interactable object is dropped within the snap zone. * **Snap Duration:** The amount of time it takes for the object being snapped to move into the new snapped position, rotation and scale. * **Apply Scaling On Snap:** If this is checked then the scaled size of the snap drop zone will be applied to the object that is snapped to it. * **Clone New On Unsnap:** If this is checked then when the snapped object is unsnapped from the drop zone, a clone of the unsnapped object will be snapped back into the drop zone. * **Highlight Color:** The colour to use when showing the snap zone is active. This is used as the highlight colour when no object is hovering but `Highlight Always Active` is true. * **Valid Highlight Color:** The colour to use when showing the snap zone is active and a valid object is hovering. If this is `Color.clear` then the `Highlight Color` will be used. * **Highlight Always Active:** The highlight object will always be displayed when the snap drop zone is available even if a valid item isn't being hovered over. * **Valid Object List Policy:** A specified VRTK_PolicyList to use to determine which interactable objects will be snapped to the snap drop zone on release. * **Display Drop Zone In Editor:** If this is checked then the drop zone highlight section will be displayed in the scene editor window. * **Default Snapped Interactable Object:** The Interactable Object to snap into the dropzone when the drop zone is enabled. The Interactable Object must be valid in any given policy list to snap. ## Class Variables * `public enum SnapTypes` - The types of snap on release available. * `UseKinematic` - Will set the interactable object rigidbody to `isKinematic = true`. * `UseJoint` - Will attach the interactable object's rigidbody to the provided joint as it's `Connected Body`. * `UseParenting` - Will set the SnapDropZone as the interactable object's parent and set it's rigidbody to `isKinematic = true`. ## Class Events * `ObjectEnteredSnapDropZone` - Emitted when a valid interactable object enters the snap drop zone trigger collider. * `ObjectExitedSnapDropZone` - Emitted when a valid interactable object exists the snap drop zone trigger collider. * `ObjectSnappedToDropZone` - Emitted when an interactable object is successfully snapped into a drop zone. * `ObjectUnsnappedFromDropZone` - Emitted when an interactable object is removed from a snapped drop zone. ## Unity Events Adding the `VRTK_SnapDropZone_UnityEvents` component to `VRTK_SnapDropZone` object allows access to `UnityEvents` that will react identically to the Class Events. * All C# delegate events are mapped to a Unity Event with the `On` prefix. e.g. `MyEvent` -> `OnMyEvent`. ## Event Payload * `GameObject snappedObject` - The interactable object that is dealing with the snap drop zone. ## Class Methods ### InitaliseHighlightObject/1 > `public virtual void InitaliseHighlightObject(bool removeOldObject = false)` * Parameters * `bool removeOldObject` - If this is set to true then it attempts to delete the old highlight object if it exists. Defaults to `false` * Returns * _none_ The InitaliseHighlightObject method sets up the highlight object based on the given Highlight Object Prefab. ### ForceSnap/1 > `public virtual void ForceSnap(GameObject objectToSnap)` * Parameters * `GameObject objectToSnap` - The GameObject to attempt to snap. * Returns * _none_ the ForceSnap method attempts to automatically attach a valid GameObject to the snap drop zone. ### ForceUnsnap/0 > `public virtual void ForceUnsnap()` * Parameters * _none_ * Returns * _none_ The ForceUnsnap method attempts to automatically remove the current snapped game object from the snap drop zone. ### ValidSnappableObjectIsHovering/0 > `public virtual bool ValidSnappableObjectIsHovering()` * Parameters * _none_ * Returns * `bool` - Returns true if a valid object is currently in the snap drop zone area. The ValidSnappableObjectIsHovering method determines if any valid objects are currently hovering in the snap drop zone area. ### IsObjectHovering/1 > `public virtual bool IsObjectHovering(GameObject checkObject)` * Parameters * `GameObject checkObject` - The GameObject to check to see if it's hovering in the snap drop zone area. * Returns * `bool` - Returns true if the given GameObject is hovering (but not snapped) in the snap drop zone area. The IsObjectHovering method determines if the given GameObject is currently howvering (but not snapped) in the snap drop zone area. ### IsInteractableObjectHovering/1 > `public virtual bool IsInteractableObjectHovering(VRTK_InteractableObject checkObject)` * Parameters * `VRTK_InteractableObject checkObject` - The Interactable Object script to check to see if it's hovering in the snap drop zone area. * Returns * `bool` - Returns true if the given Interactable Object script is hovering (but not snapped) in the snap drop zone area. The IsInteractableObjectHovering method determines if the given Interactable Object script is currently howvering (but not snapped) in the snap drop zone area. ### GetHoveringObjects/0 > `public virtual List<GameObject> GetHoveringObjects()` * Parameters * _none_ * Returns * `List<GameObject>` - The List of valid GameObjects that are hovering (but not snapped) in the snap drop zone area. The GetHoveringObjects method returns a List of valid GameObjects that are currently hovering (but not snapped) in the snap drop zone area. ### GetHoveringInteractableObjects/0 > `public virtual List<VRTK_InteractableObject> GetHoveringInteractableObjects()` * Parameters * _none_ * Returns * `List<VRTK_InteractableObject>` - The List of valid Interactable Object scripts that are hovering (but not snapped) in the snap drop zone area. The GetHoveringInteractableObjects method returns a List of valid Interactable Object scripts that are currently hovering (but not snapped) in the snap drop zone area. ### GetCurrentSnappedObject/0 > `public virtual GameObject GetCurrentSnappedObject()` * Parameters * _none_ * Returns * `GameObject` - The GameObject that is currently snapped in the snap drop zone area. The GetCurrentSnappedObejct method returns the GameObject that is currently snapped in the snap drop zone area. ### GetCurrentSnappedInteractableObject/0 > `public virtual VRTK_InteractableObject GetCurrentSnappedInteractableObject()` * Parameters * _none_ * Returns * `VRTK_InteractableObject` - The Interactable Object script that is currently snapped in the snap drop zone area. The GetCurrentSnappedInteractableObject method returns the Interactable Object script that is currently snapped in the snap drop zone area. ### Clone/1 > `public virtual GameObject Clone(Vector3 position)` * Parameters * `Vector3 position` - Position of the cloned GameObject * Returns * `GameObject` - The GameObject of the clone The Clone method returns the GameObject of the cloned snap drop zone ### Clone/0 > `public virtual GameObject Clone()` * Parameters * _none_ * Returns * `GameObject` - The GameObject of the clone The Clone method returns the GameObject of the cloned snap drop zone ## Example `VRTK/Examples/041_Controller_ObjectSnappingToDropZones` uses the `VRTK_SnapDropZone` prefab to set up pre-determined snap zones for a range of objects and demonstrates how only objects of certain types can be snapped into certain areas.