Snap Target
A Snap Target is what a Snapper snaps to, making it a child in the hierarchy. The Snap Target is also decides which Snapper is allowed to snap to it via the Requirements list (see below)
Requirements are what restrict which Snappers are allowed to snap to it. A Snap Target with no requirements will allow any Snapper to snap to it.
To add a requirement to a Snap Target:
- Expand the Requirements array if not already
- Click the ‘Add Requirement’ button
- Select the desired requirement from the menu
To remove a requirement from a Snap Target:
- Expand the Requirements array if not already
- Right click the requirement to be removed
- Select ‘Delete Array Element’
Snap Target requirements are processed in the order they appear in the list
A number of commonly used requirements are included with the SDK including an ‘Allow List’, ‘Block List’ and ‘Max Angle’ (which only allows snapping within a limited rotation range).
Creating your own requirements is easy. Simply create a Serializable class that inherits the ISnapRequirement
interface. Once created, it will automatically be added to the ‘Add Requirements’ menu.
Below is the implementation for the included Allow List requirement:
/// <summary>
/// A list of allowed Snappers for a SnapTarget
/// </summary>
[Serializable]
public class AllowList : ISnapRequirement
{
/// <summary>
/// Allowed snappers for this target
/// </summary>
/// <remarks>If this list is left empty, all Snappers will be accepted</remarks>
[Tooltip("Allowed snappers for this target")]
public List<Snapper> Allowed = new List<Snapper>();
/// <summary>
/// Check if requirements are met
/// </summary>
/// <param name="snapper">Snapper</param>
/// <param name="snapTarget">Snap Target</param>
/// <returns>Returns true if the Snapper meets the SnapTarget's requirements</returns>
public bool IsAllowed(Snapper snapper, SnapTarget snapTarget)
{
return Allowed.Contains(snapper);
}
}
Snap Targets provide events that can be used for triggering gameplay logic in an experience.
Event | Description |
---|---|
On Snap | Triggered when a Snapper is snapped to the Snap Target |
On Unsnap | Triggered when a Snapper is unsnapped from the Snap Target |
On Hover Enter | Triggered when a valid Snapper is held near the Snap Target |
On Hover Exit | Triggered when a previously valid Snapper leaves the snapping range of the Snap Target |