Skip to content

Game.Prefabs.BrushPrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: PrefabBase

Summary:
Represents a brush prefab used by in-game tools. Stores brush texture and priority and is responsible for declaring the ECS components required by the prefab and creating the runtime archetype for brush entities. During late initialization it collects all component definitions present on the prefab, builds an archetype (including Created and Updated tags), and writes a BrushData component to the prefab entity containing the created archetype, priority and initial resolution. Intended for modders to subclass when creating custom brush prefabs or to override RefreshArchetype to influence archetype construction.


Fields

  • public UnityEngine.Texture2D m_Texture
    Texture used by the brush (brush mask/visual). Can be assigned in the prefab to define the brush shape or appearance.

  • public int m_Priority
    Integer priority used by brush systems; assigned into the BrushData written to the prefab entity and used at runtime to order brushes.

Properties

  • None declared in this class.

Constructors

  • public BrushPrefab()
    Default constructor (inherits initialization behavior from PrefabBase). No extra initialization logic in this class; a derived class may add initialization.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that should be present on the prefab entity. This implementation calls base.GetPrefabComponents(...) and then adds ReadWrite() and ReadWrite(). These components describe data stored on the prefab entity itself.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that new instantiated brush entities should have. Calls base then adds ReadWrite() to indicate brush instances should include the Brush component.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called during prefab late initialization. Calls the base LateInitialize and then calls RefreshArchetype(entityManager, entity) to create and store the runtime archetype for this brush prefab.

  • protected virtual void RefreshArchetype(EntityManager entityManager, Entity entity)
    Collects all ComponentBase instances attached to this prefab (via GetComponents), queries each for their archetype component set, accumulates them into a HashSet, ensures Created and Updated tags are present, creates an EntityArchetype from that set and stores it into a BrushData struct on the prefab entity. Also sets BrushData.m_Priority from m_Priority and initializes m_Resolution to 0. This is the central method that converts prefab component definitions into a concrete runtime archetype for spawning brush entities. Because it is virtual, modders can override it to customize which components are included or to add additional setup before/after the archetype is created.

Notes and implementation details: - Uses PrefabUtils.ToArray(hashSet) to convert the HashSet to the array required by EntityManager.CreateArchetype. - Adds Created and Updated marker components to ensure standard lifecycle tags exist on the archetype. - Writes the resulting archetype and metadata into the prefab entity via EntityManager.SetComponentData(entity, componentData). - Depends on Unity.Entities types (EntityManager, Entity, ComponentType, EntityArchetype) and on the BrushData/Brush/BrushCell component definitions elsewhere in the codebase.

Usage Example

// Example: a derived prefab overriding RefreshArchetype to add a custom component
public class MyCustomBrushPrefab : BrushPrefab
{
    protected override void RefreshArchetype(EntityManager entityManager, Entity entity)
    {
        // Optionally modify prefab fields or perform custom logic here
        m_Priority = Math.Max(0, m_Priority);

        // Call base to collect components from child ComponentBase instances
        base.RefreshArchetype(entityManager, entity);

        // If needed, read back the BrushData and perform additional configuration
        // var brushData = entityManager.GetComponentData<BrushData>(entity);
        // ... custom post-processing ...
    }
}