Scripting API¶
All runtime classes live in the CyberRevolution.BreakableObjectsSystem.Scripts.Breakable namespace. You can find examples of using breakable objects in the Examples folder.
BreakableObject¶
The component on a breakable object. The Create broken objects window adds and configures it.
Public methods¶
public void Break(Vector3 explosionPosition = default)
Breaks the object. This starts an explosion inside the object, replaces the original mesh with a broken version and applies a force to the shards.
Vector3 explosionPosition— a custom explosion position. If you don't set it, the center of the object is used.
public void Restore()
Instantly restores the object.
Properties¶
public GameObject OriginalObject
Instance of the original object.
public BreakableObjectParams Params
Parameters of the explosion: force, shard lifetime and so on. See Advanced options.
public BrokenObjectCollection BrokenObjectsCollection
The BrokenObjectCollection instance that broken objects are retrieved from.
public bool Broken { get; private set; }
Whether the object is currently broken. It becomes true right after Break is called.
public bool IsBreakingInProgress { get; private set; }
true until the last shard is gone.
BreakByClick¶
Add this component to a breakable object to destroy it by a click or tap.
BreakByCollision¶
Add this component to a breakable object to destroy it by any collision.
OnBreakBehaviourAbstract¶
Derive from this class to create an additional break behaviour. See Example 2.
Public methods¶
public abstract void OnBreak();
OnRestoreBehaviourAbstract¶
Derive from this class to create an additional restore behaviour.
Public methods¶
public abstract void OnRestore();
BrokenObjectPools¶
Public methods¶
public void AddCollectionToPool(BrokenObjectCollection brokenObjectCollection)
Pre-initializes a pool with a broken object collection, so the work isn't done at the moment of the first break. See Example 1.
public BrokenObject GetRandomObjectFromCollection(BrokenObjectCollection collection, Transform parent,
Vector3 position, Quaternion rotation, Vector3 localScale, out int index)
Retrieves a random broken object variant from the target BrokenObjectCollection at the target transform.
public void ReleaseObjectFromCollection(BrokenObjectCollection collection, BrokenObject go, int index)
Releases the broken object back to the collection under the target index.