Sprite Breaker - Unity Component

Sprite Breaker API

Methods

The following methods are available for SpriteBreaker component instances:

Break() Uses current breaker data (or SpriteBreakerDataAsset from dataAsset field) to generate shards and begin simulation.

Clear() Deletes all spawned shards, and re-enables SpriteRenderer.

Generate() Uses generation parameters to replace current breaker data with generated polygons.

RestartSimulation(bool resetShardPositions=true) Resets clock for timeToLive and fadeAfter, and restarts physics simulation. resetShardPositions parameter makes shards move to their spawn positions.

Properties

The following public properties are available for SpriteBreaker component instances:

SpriteBreakerData data Object containing the shard shape data.

SpriteBreakerDataAsset dataAsset If assigned, SpriteBreaker without data will copy data from asset when broken.

Sprite sprite Sprite used to generate fragments. If this field is not assigned, a sprite from attached SpriteRenderer will be used.

GameObject shardPrototype An optional gameObject prefab used to generate shards.

Transform shardsParent If set, this transform used as a parent for generated shards.

bool updateShardsColor Update spawned shards renderer color every frame.

ShadowCastingMode castShadows Shards' MeshRenderer shadow casting mode.

bool receiveShadows Shards' MeshRenderer shadow receive mode.

Color shardsColor Overall color/alpha of all shards, multiplied into each spawned fragment's renderer.

ShardEvent OnShardCreated This event is called for each generated shard.

bool drawEditorGizmos Determines if Unity Editor should draw shards preview.

Color gizmoColor Draw shards preview with this color.

bool disableRendererOnBreak Should attached SpriteRenderer be disabled/enabled on Break/Clear.

CreateColliders createColliders If set, a collider and rigidbody will be added/updated to each shard with polygon edges. One of CreateColliders enum: None, Collider2D, Collider3D, FakePhysics.

float colliderThickness For 3D collider how thick should the generated collider mesh be.

Vector3 fakeGravity Gravity for fake physics createColliders mode.

float massMultiplier Rigid bodies mass will be computed by multiplying this value by the shard polygon area. If this value is negative, the mass is set as an absolute value (polygon size doesn't affect mass).

float initialRadialImpulse Apply this impulse radially from origin to each shard on break.

float initialRadialImpulsePlusMinus Plus or minus randomness % variation for radial impulse.

Vector3 initialLinearImpulse Apply this impulse linearly to each shard on break.

float initialLinearImpulsePlusMinus Plus or minus randomness % multiplier for linear impulse.

Vector3 initialRotationalImpulse Apply this impulse to shard rotation on break.

float initialRotationalImpulsePlusMinus Plus or minus randomness % multiplier for rotational impulse.

float timeToLive Time to live (seconds). If set to non-0, the shards will be destroyed after this time interval after Break() is called.

float fadeAfter If timeToLive is set, the shards will fade to alpha=0 after this time.

float timeBroken returns Time.time value when Break() was called.

EndAction endAction If timeToLive is set, what to do when time expires after Break(). One of EndAction enum values: DestroyObject, DestroyParent, ClearShards, DeactivateShards, Reset, ClearDataAndReset, Restart, DoNothing.

BreakerEvent OnTimeToLiveExpired If timeToLive is set, this event is called after time expires.

float csgUpscale How much to upscale coordinates when performing CSG operations.

int csgEpsilon Epsilon precision value used during CSG. 10 to the -X power (or 10e-X), where X is this value.

int generateSeed Generation seed - if set to 0, the seed is random.

BreakerGenerateFrom generateFrom Generation start point. One of BreakerGenerateFrom enum: Quad, Data, Asset.

float generateRandomness Generation randomness multiplier.

float generateAngle Generation features start angle

float generateSpacing Generation features spacing.

float generateFrequency Generation features frequency (breaks shards into smaller pieces).

Vector2 generateOrigin Generation origin point (0.5, 0.5 is center of the sprite).

GameObject[] shards Returns currently spawned shards as GameObjects.

bool autoBreakOnAwake automatically calls Break() on Awake

bool hasShards returns true if GameObjects are attached to polygons

bool canBreak returns true if breaking is possible - i.e. there's a sprite, and breaker data