WORK IN PROGRESS
Requires Unity 2021.3+
An object-oriented
entity-component-system
for creating complex action games in Unity.
Entities behavior is defined entirely in c#
//an entity is defined as a "template" which can be used to instantiate
public static EntityTemplate ExampleEnemy()
{
EntityTemplate t = BaseEntity();
//attributes are floats that drive entity behavior and can be modified by behaviors
t.attributes[D_Attribute.MoveSpeed] = new A(Random.Range(20f, 40f));
t.attributes[D_Attribute.MaxMoveSpeed] = new A(Random.Range(20f, 40f));
//behaviors are like monoBehaviors
t.behaviors = new DeepBehavior[]{
new MoveTowardsPlayer(),
new AvoidOtherEntities(D_Team.Enemy,D_EntityType.Actor,60f),
new VFXOnDeath(
new VFX.Sparks(new Color(1f,.256f,.256f),5),
new VFX.SquarePop(new Color(1f,.256f,.256f),5f,.2f)
),
};
t.team = D_Team.Enemy;
t.type = D_EntityType.Actor;
return t;
}
The core gameplay entity has Behaviors, Attributes, Flags, and Resources
A behavior is the replacement for MonoBehaviors that gets attached to entities. It has a Initialize/Destroy method that you can use to hook into the parent entities events.
These events are things like: Update
,OnEnable
,OnCollisionStay
. But also things like: OnDealDamage
,OnBounce
,OnCast
.
public class AreaDamageOnDeath : DeepBehavior
{
private float radius;
private Damage damage;
private D_Team targetTeam;
public AreaDamageOnDeath(float radius, Damage damage, D_Team targetTeam)
{
this.radius = radius;
this.damage = damage;
this.targetTeam = targetTeam;
}
public override void InitializeBehavior()
{
parent.events.OnEntityDie += OnDie;
}
public override void DestroyBehavior()
{
parent.events.OnEntityDie -= OnDie;
}
private void OnDie()
{
DeepActions.AreaDamage(parent.transform.position, radius, damage, targetTeam);
}
}
TODO: explain attributes
TODO: explain resources
The purpose of this is to create a really solid base that allows for a ton flexibility and freedom in design. Beyond freedom, a major goal is creating a system that is very FAST to work with.
I find that doing a system like this through mono-behaviors is very messy and error prone (and a little less performant).
Defining entity behaviors inside c# is both very fast and EXTREMLY flexible. Creating this kind of flexibility in an editor GUI is possible, but a huge waste of time imo.