Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.

Collision Hub

pointcache edited this page Jan 21, 2017 · 2 revisions

Since in URSA we don't store logic in components, but we require to extract collisions from object, we use a relay method implemented as static CollisionHub class.

The idea is that components raise events that systems subscribe to, thus decoupling them. Only components can raise events for CollisionHub, as it requires a sender of a ComponentBase type, but it case of a complex collision rig, you can always use normal monobehaviors to relay those events to one top Component that in turn will send them to CollisionHub.

##Usage

In the component that acts as collider (or receives collisions from somewhere else), simply use one of unity's magic methods to receive standard collision event, inside it send that event to collision hub of the corresponding Component type, and provide the context required.

private void OnCollisionEnter() {
    CollisionHub<Ball>.CollisionEnter(this);
}

Now somewhere in our System we subscribe to that

private void OnEnable() {
    CollisionHub<Ball>.OnCollisionEnter += (x,y)  => URSA.Log.Print("boom");
}

So we can have any amount of systems being subscribed to collision events.

Clone this wiki locally