-
Notifications
You must be signed in to change notification settings - Fork 53
Danmaku Controllers
Normally, fired Danmaku stay a fixed size, color, sprite, velocity, and angular velocity: a static bullet with static behavior. For 90+% of the bullets fired, these will work just fine. However, if there is special constant behavior that the Danmaku must exhibit, Danmaku Controllers can be defined and added.
Danmaku Controllers are special objects passed into Danmaku to add custom, parametric behavior which will update it appropriately every frame.
For example, AccelerationControllers applies a linear acceleration to the bullets it affects. Over time, the bullets using the AccelerationController will speed up or slow down over time.
A single Danmaku Controller can be applied to multiple bullets. Editing the parameters of that single Danmaku Controller will affect all Danmaku using it.
A single Danmaku can have multiple Danmaku Controllers.
Danmaku Controllers can be defined in one of two ways:
- Create a class that derives from
IDanmakuController
and implement its abstract members. - Create a delegate of any function with the method signature of
void UpdateDanmaku(Danmaku danmaku, float dt)
Given a Danmaku d
and a IDanmakuController/DanmakuController delegate danmakuController
, call:
d.AddController(danmakuController);
Given a Danmaku d
and a IDanmakuController/DanmakuController delegate danmakuController
, call:
d.RemoveController(danmakuController);
Danmaku Controllers (the implementers of IDanmakuController
) are not necessarily sublclasses of UnityEngine.Object
, and thus it may be impossible to allow it to be attached to Unity GameObjects directly.
To circumvent this, DanmakuControlBehaviors are IDanmakuController implementers that also are subclasses of MonoBehavior and can be used as Danmaku Controllers as needed, and can be defined from the Inspector.
If you already have a normal System.Object
Danmaku Controller and would rather not completely rewrite the code, there is a quick way of creating a Danmaku Controller Behavior from a non-UnityEngine object: Controller Wrapper Behaviors.
Given a any IDanmakuController implementer class DmkController
, the following code generates a Danmaku Control Behavior type CustomDanmakuController
. (Note, IDanmakuController types used in this manner needs to be marked with the System.Serializeable
attribute).
public CustomDanmakuController : ControllerWrapperBehavior<DmkController> {
}
All elements of DmkController
should now be exposed as a useable Danmaku Control Behavior.