From 3079a08b40a8e751a40a676346687a68f6b76b97 Mon Sep 17 00:00:00 2001 From: Harvey Ball Date: Mon, 15 May 2017 20:56:22 +0100 Subject: [PATCH] feat(SnapDropZone): add getter method for drop zone object Two new methods have been added to get the current hovered objects and the current snapped object from within a snap drop zone. Previously, the only way of knowing what was in a snap drop zone was to register for the event when an item was hovered or snapped into the zone. Now these two new methods provide a way of directly accessing the info on the snap drop zone without needing to use the event. --- .../Resources/Scripts/VRTK_SnapDropZone.cs | 18 +++++++++++++++ DOCUMENTATION.md | 22 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_SnapDropZone.cs b/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_SnapDropZone.cs index b7e30b8e6..a2f069730 100644 --- a/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_SnapDropZone.cs +++ b/Assets/VRTK/Prefabs/Resources/Scripts/VRTK_SnapDropZone.cs @@ -226,6 +226,24 @@ public virtual bool IsObjectHovering(GameObject checkObject) return currentValidSnapObjects.Contains(checkObject); } + /// + /// The GetHoveringObjects method returns a List of valid GameObjects that are currently hovering (but not snapped) in the snap drop zone area. + /// + /// The List of valid GameObjects that are hovering (but not snapped) in the snap drop zone area. + public virtual List GetHoveringObjects() + { + return currentValidSnapObjects; + } + + /// + /// The GetCurrentSnappedObejct method returns the GameObject that is currently snapped in the snap drop zone area. + /// + /// The GameObject that is currently snapped in the snap drop zone area. + public virtual GameObject GetCurrentSnappedObject() + { + return currentSnappedObject; + } + protected virtual void Awake() { if (Application.isPlaying) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 884bd2e6c..1acd2c198 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -391,6 +391,28 @@ The ValidSnappableObjectIsHovering method determines if any valid objects are cu 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 GetHoveringObjects()` + + * Parameters + * _none_ + * Returns + * `List` - 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.