Utility class providing helper methods for snap point operations. More...
Static Public Member Functions | |
| static void | Align (Transform transform, SnapPoint ownSnapPoint, SnapPoint mateSnapPoint, Quaternion additionalRotation, bool applyRotation=true) |
| Aligns a transform to a snap point connection with rotation handling. | |
| static void | Align (Transform transform, SnapPoint ownSnapPoint, SnapPoint mateSnapPoint) |
| Aligns a transform to a snap point connection with default settings. | |
| static void | AttachTo (Transform transform, SnapPoint snapPoint) |
| Attaches a transform to a snap point by matching position and rotation. | |
| static void | CheckChildSnapPoints (Component component) |
| Checks all child SnapPoint components for connections. | |
| static void | StandardConnect (Transform transform, SnapPoint ownSnapPoint, SnapPoint snapPointMate, bool ismoved, OnSnappedEvent onSnapped) |
| Standard Connect implementation that handles alignment and event invocation. | |
Detailed Description
Utility class providing helper methods for snap point operations.
This class simplifies implementation of ISnapable components by providing reusable alignment and attachment logic. Reduces boilerplate code and ensures consistent behavior across all snapable components.
Key Features:
- Standardized snap point alignment with rotation handling
- Support for SnapIn/SnapOut, SnapLeft/SnapRight connections
- Automatic 180-degree rotation for reverse connections
- Configurable additional rotations for specialized cases
Usage Example: public void Connect(SnapPoint own, SnapPoint mate, ISnapable obj, bool ismoved) { if (ismoved) SnapPointHelper.Align(transform, own, mate, Quaternion.identity); OnSnapped?.Invoke(own, mate); }
Member Function Documentation
◆ Align() [1/2]
|
static |
Aligns a transform to a snap point connection with default settings.
Convenience overload that uses Quaternion.identity for additional rotation.
- Parameters
-
transform The transform to align ownSnapPoint The snap point on the object being moved mateSnapPoint The snap point being connected to
◆ Align() [2/2]
|
static |
Aligns a transform to a snap point connection with rotation handling.
This method handles the standard alignment patterns for snap points:
- SnapOut to SnapIn: Standard forward connection
- SnapIn to SnapOut: Reverse connection with 180° rotation
- Same named snap points: 180° rotation
- SnapLeft/SnapRight: Side connections with appropriate rotation
- Parameters
-
transform The transform to align ownSnapPoint The snap point on the object being moved mateSnapPoint The snap point being connected to additionalRotation Additional rotation to apply after alignment (default: no rotation) applyRotation Whether to apply rotation (default: true)
Example:
◆ AttachTo()
|
static |
Attaches a transform to a snap point by matching position and rotation.
Simpler than Align - just copies the snap point's transform directly.
- Parameters
-
transform The transform to attach snapPoint The snap point to attach to
Example:
◆ CheckChildSnapPoints()
|
static |
Checks all child SnapPoint components for connections.
Common implementation for ISnapable.CheckSnap() method.
- Parameters
-
component The component whose children should be checked
Example:
◆ StandardConnect()
|
static |
Standard Connect implementation that handles alignment and event invocation.
Common implementation for ISnapable.Connect() method.
- Parameters
-
transform The transform to align ownSnapPoint The snap point on the object being moved snapPointMate The snap point being connected to ismoved Whether this object is being moved onSnapped The OnSnapped event to invoke (can be null)
Example: