{"_id":"594949e92be16d0026ec054c","category":{"_id":"594949e62be16d0026ec04cf","version":"594949e52be16d0026ec04cd","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":"594949e52be16d0026ec04cd","project":"571fa55ca0acd42000af9545","__v":2,"createdAt":"2017-06-20T16:14:29.816Z","releaseDate":"2017-06-20T16:14:29.816Z","categories":["594949e62be16d0026ec04ce","594949e62be16d0026ec04cf","594949e62be16d0026ec04d0","594949e62be16d0026ec04d1","594949e62be16d0026ec04d2","594949e62be16d0026ec04d3","594949e62be16d0026ec04d4","594949e62be16d0026ec04d5","594949e62be16d0026ec04d6","594949e62be16d0026ec04d7","594949e62be16d0026ec04d8","594949e62be16d0026ec04d9","594949e62be16d0026ec04da","594949e62be16d0026ec04db","594949e62be16d0026ec04dc","594949e62be16d0026ec04dd","594949e62be16d0026ec04de","594949e62be16d0026ec04df","594949e62be16d0026ec04e0","594949e62be16d0026ec04e1","59497219f4a8980024dd0631"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Kunekune","version_clean":"3.2.0","version":"3.2.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:35:11.740Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"## Overview\n\nThis sets up a predefined zone where an existing interactable object can be dropped and upon dropping it snaps to the set snap drop zone transform position, rotation and scale.\n\nThe position, rotation and scale of the `SnapDropZone` Game Object will be used to determine the final position of the dropped interactable object if it is dropped within the drop zone collider volume.\n\nThe provided Highlight Object Prefab is used to create the highlighting object (also within the Editor for easy placement) and by default the standard Material Color Swap highlighter is used.\n\nAn alternative highlighter can also be added to the `SnapDropZone` Game Object and this new highlighter component will be used to show the interactable object position on release.\n\nThe prefab is a pre-built game object that contains a default trigger collider (Sphere Collider) and a kinematic rigidbody (to ensure collisions occur).\n\nIf an alternative collider is required, then the default Sphere Collider can be removed and another collider added.\n\nIf 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.\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 Object:** The game object to snap into the dropzone when the drop zone is enabled. The game 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 game object 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### 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### 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## 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 This sets up a predefined zone where an existing interactable object can be dropped and upon dropping it snaps to the set snap drop zone transform position, rotation and scale. The position, rotation and scale of the `SnapDropZone` Game Object will be used to determine the final position of the dropped interactable object if it is dropped within the drop zone collider volume. The provided Highlight Object Prefab is used to create the highlighting object (also within the Editor for easy placement) and by default the standard Material Color Swap highlighter is used. An alternative highlighter can also be added to the `SnapDropZone` Game Object and this new highlighter component will be used to show the interactable object position on release. The prefab is a pre-built game object that contains a default trigger collider (Sphere Collider) and a kinematic rigidbody (to ensure collisions occur). If an alternative collider is required, then the default Sphere Collider can be removed and another collider added. 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. * **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 Object:** The game object to snap into the dropzone when the drop zone is enabled. The game 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 game object 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. ### 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. ### 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. ## 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.