Skip to content

Game.Prefabs.WeatherObject

Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
WeatherObject is a prefab component that encodes simple weather-based placement requirements for an object prefab. It exposes two inspector-accessible booleans to mark a prefab as requiring snow or forbidding snow, and during LateInitialize it appends an ObjectRequirementElement into the prefab/entity buffer so the game can enforce those requirements at runtime. The class is decorated with ComponentMenu to appear under "Objects/" with the specified prefab types.


Fields

  • public bool m_RequireSnow
    Flag (usually set in the prefab) indicating that the object requires snow conditions. When true, the component sets the corresponding ObjectRequirementFlags.Snow bit for the requirement added to the entity's ObjectRequirementElement buffer.

  • public bool m_ForbidSnow
    Flag (usually set in the prefab) indicating that the object forbids snow conditions. When true, the component sets the corresponding forbidden ObjectRequirementFlags.Snow bit for the ObjectRequirementElement added to the entity's buffer.

Properties

  • (none)

Constructors

  • public WeatherObject()
    The default parameterless constructor (compiler-provided). WeatherObject is typically configured via the inspector on the prefab rather than constructed manually at runtime.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the required component type to the provided set so the prefab's entity will have a DynamicBuffer. Specifically it calls: components.Add(ComponentType.ReadWrite());

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components are added by this prefab component (method intentionally empty).

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs final initialization on the entity representing the prefab:

  • Calls base.LateInitialize(entityManager, entity).
  • Obtains the DynamicBuffer for the entity.
  • Reads the current buffer length to determine the index to store in the new element.
  • Builds an ObjectRequirementFlags bitmask for required and forbidden flags based on m_RequireSnow and m_ForbidSnow.
  • Adds a new ObjectRequirementElement(requiredFlags, forbiddenFlags, index) to the buffer so the game's systems know the new requirement for this prefab.

This is the place where the prefab's inspector settings are translated into runtime EC S data for the placement/validation systems.

Usage Example

// WeatherObject is typically attached to a prefab and configured in the editor.
// At runtime, LateInitialize is called and will append an ObjectRequirementElement
// to the prefab entity's buffer reflecting the m_RequireSnow / m_ForbidSnow settings.

public override void LateInitialize(EntityManager entityManager, Entity entity)
{
    base.LateInitialize(entityManager, entity);
    DynamicBuffer<ObjectRequirementElement> buffer = entityManager.GetBuffer<ObjectRequirementElement>(entity);
    int length = buffer.Length;
    ObjectRequirementFlags required = 0;
    ObjectRequirementFlags forbidden = 0;

    if (m_RequireSnow)
        required |= ObjectRequirementFlags.Snow;
    if (m_ForbidSnow)
        forbidden |= ObjectRequirementFlags.Snow;

    buffer.Add(new ObjectRequirementElement(required, forbidden, length));
}

Additional notes: - ObjectRequirementElement and ObjectRequirementFlags are part of the game's placement/requirement system; the flags are used to mark environment constraints (here, Snow). - Since GetArchetypeComponents is empty, the dynamic buffer is requested via GetPrefabComponents to ensure the entity has the buffer component.