-
Notifications
You must be signed in to change notification settings - Fork 7
SnapPointMaker
SnapPointMaker is a static class used to create snap points on GameObjects in Unity. A snap point is a specific point on a GameObject where other objects can "snap" or attach to, based on a game's mechanics.
Supported collider types are BoxCollider and SphereCollider. You can specify the types of snap points you want to create using the SnapPointType enumeration.
To register a GameObject for snap points creation, use the AddObjectForSnapPoints method:
SnapPointMaker.AddObjectForSnapPoints(myGameObject);To apply snap points to all registered GameObjects, use the ApplySnapPoints method:
SnapPointMaker.ApplySnapPoints(SnapPointType.Vertices | SnapPointType.Center);This example will apply snap points at the vertices and the center of the registered game objects, given they have either a BoxCollider or a SphereCollider component.
SnapPointType is an enumeration used to specify the types of snap points to create:
-
Vertices: Snap points will be created at the vertices of aBoxCollider. -
Center: A snap point will be created at the center of the collider. -
Poles: Snap points will be created at the top and bottom of aSphereCollider. -
Equator: Snap points will be created at the cardinal directions on the equator of aSphereCollider.
These enumeration values can be combined using the bitwise OR operator (|). For example, SnapPointType.Vertices | SnapPointType.Center will create snap points at both the vertices and the center.
The SnapPointMaker currently supports BoxCollider and SphereCollider types. If your GameObject has a different type of collider, you will need to provide additional logic to determine the snap points. The Unsupported collider type warning will be displayed in the console for unsupported collider types.
The snap points created by the SnapPointMaker are static and do not adjust dynamically if the GameObject changes shape or size. If you require dynamic snap points, you'd have to implement a system that updates snap points in response to changes to the GameObject.