Skip to content

Danmaku Controllers

Carlos Orama edited this page Jun 7, 2021 · 3 revisions

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.

Description

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.

Usage and Creation

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)

Adding a Danmaku Controller to a Danmaku

Given a Danmaku d and a IDanmakuController/DanmakuController delegate danmakuController, call:

d.AddController(danmakuController);

Removing a Danmaku Controller from a Danmaku:

Given a Danmaku d and a IDanmakuController/DanmakuController delegate danmakuController, call:

d.RemoveController(danmakuController);

Danmaku Control Behaviors and Controller Wrapper Behaviors

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.