Skip to content

Attributes

Carlos Avila edited this page May 9, 2016 · 23 revisions

Overview

The code generator currently supports the following attributes to be used with classes deriving from IComponent :

  • [Pool]: You can use this attribute to make a component be available only in the specified pool(s). e.g., [MyPoolName], [Enemies], [UI], etc.
  • [SingleEntity]: The code generator will generate additional methods to ensure that only one entity with this component exists. It will throw an exception if the group has more than one entity.
  • [CustomPrefix]: Can be used to support custom prefixes for flag components.
  • [DontGenerate]: The code generator will not process components with this attribute.

Pool

This is not an attribute you want to use directly. Instead it's subclassed by the code generator for each pool name configured in the Entitas preference window. The resulting subclasses will be added as individual files in your Generated Folder with the format {PoolName}Attribute.cs.

Example

Add some custom pools in the Entitas preference window and click on "Generate":

Entitas.Unity.CodeGenerator

Now you can use the newly generated attributes in your components:

using Entitas;
using Entitas.CodeGenerator;

[Core, Ui]
public class SceneComponent : IComponent
{
    public Scene Value;
}

[Meta]
public class EditorOnlyVisual : IComponent
{
    public bool ShowInMode;
}

CustomPrefix

This attribute will work only with components that act as flags. Flag components are empty classes, therefore have no fields and act as a form of boolean flag for entities. If this attribute is used in a component with public fields it will silently fail no custom prefix will be generated.

Example

Create a flag component:

using Entitas;
using Entitas.CodeGenerator;

[CustomPrefix("flag")]
public class DestroyComponent : IComponent {
}

What the code generator would normally provide without the attribute:

entity.isDestroy = true;

With the [CustomPrefix] attribute:

entity.flagDestroy = true;

DontGenerate

This attribute is self-explanatory, any component with this attribute will be skipped by the code generator.

Example

using Entitas;
using Entitas.CodeGenerator;

[DontGenerate]
public class FutureFeatureComponent : IComponent {
}
Clone this wiki locally