Design Patterns

Design patterns are commonly used in association with data structures. The Data Structures package includes a different design pattern implementations commonly used in Unity games.


SingletonBehavior

A singleton behavior that can be used to ensure that only one instance of a class is created.

class ExampleBehavior : SingletonBehavior<ExampleBehavior>

UpdateBehavior

Allows a behavior to change the update mode without extra overhead or performance costs.

class ExampleBehavior : UpdateBehavior

Modules

Manages a list of registered entity modules.

Modules<ExampleModule> modules = new Modules<ExampleModule>(8);

ObjectPool

Reuses objects from a shared pool to prevent instantiating new objects. The object pool can have a set capacity or it can grow in size.

ObjectPool<ExampleObject> pool = new ObjectPool<ExampleObject>(8);

ValueAccumulator

Accumulates a set of stored values into a single total value. Supported types:

  • Double
  • Float
  • Int
  • Quaternion
  • Vector2
  • Vector2Int
  • Vector3
  • Vector3Int
  • Vector4