Adding your own logic

The core of TBE’s API is the RtUnitBhv. Please do not directly modify any values herein.

TBE is already extensible just because of Unity’s component based architecture.

But here we want to talk about some points where and how to best hook into TBE:

Regarding Units

Programmatically instantiate a Unit:

The following code creates a Unit PLUS gives you a place to add your post init logic.

var createdUnit = UnitManager.CreateUnitForPlayer(unitPrefab, player, position);
createdUnit.UnitReady += unit => {
    Debug.Log($"Unit {unit.DisplayName} ready.");
}
CreateUnitForPlayer has an additional overload where you can (aditionally) specify the UnitBase. This is the method that enables using one prefab for multiple different unit types, and thus it will override the UnitBase configured in the prefab.

Listening for created Units:

In order to get informed of ANY created Unit make a MonoBehaviour and add:

private void Start() {
    MessageBus.Singleton.OfType<UnitInitialized>()
        .Subscribe(OnUnitSpawned).AddTo(this);
}

private void OnUnitSpawned(UnitInitialized message) {
    Debug.Log($"Unit: {message.Unit.DisplayName} Initialized.");
}

Adding your own logic to a runtime Unit (RtUnitBhv)

If you want to add your own component (MonoBehaviour) to one or more of your Units, and it requires the Unit to be fully initialized, you can write:

private void UnitIsInitialized() {
   unit = GetComponentInParent<RtUnitBhv>();
}

The initialization logic uses Unity’s BroadcastMessage to call the UnitIsInitialized method.

Unity hint: Other than the name may imply, GetComponentInParent also searches in its own GameObject and not only in its parents. The same is true for GetComponentInChildren.

Add a UnitMotionMapper

Read about Motion Mappers in Animator and Animations

Regarding Abilities

Regarding Buffs

Special Enumerations

TBE has the following special Enumerations:

  • DamageKind

  • UnitAttributeFlag