Skip to content

Game.Prefabs.CalendarEvent

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase

Summary:
This Component class represents a configurable calendar event prefab used by the game's event system. It exposes inspector-editable fields for target selection, probabilities, allowed months/times and duration. When used as a prefab, it declares the ECS components required for the event (CalendarEventData, Duration, TargetElement) and initializes the entity's CalendarEventData component with the prefab's configured values during entity initialization. This component is intended to be added to prefabs in the editor (see ComponentMenu attribute) and is consumed by the game's entity creation pipeline.


Fields

  • public EventTargetType m_RandomTargetType = EventTargetType.Couple
    This field selects the type of target to pick when the event is applied (default: Couple). It is serialized for the inspector and copied into the CalendarEventData during Initialize.

  • public Bounds1 m_AffectedProbability = new Bounds1(25f, 25f)
    Defines the probability bounds for the proportion of targets affected by the event. Stored in the prefab and transferred to the ECS component.

  • public Bounds1 m_OccurenceProbability = new Bounds1(100f, 100f)
    Defines the probability bounds for the event occurrence. Stored in the prefab and transferred to the ECS component.

  • [EnumFlag] public CalendarEventMonths m_AllowedMonths
    Flagged enum indicating which months the event is allowed to occur in. Configurable in the inspector and copied to CalendarEventData.

  • [EnumFlag] public CalendarEventTimes m_AllowedTimes
    Flagged enum indicating allowed times of day (time windows) for the event. Configurable and copied during initialization.

  • [Tooltip("In fourths of a day")] public int m_Duration
    Duration of the event expressed in fourths of a day (i.e., 1 = quarter-day). Copied to the CalendarEventData component on entity creation.

Properties

  • None declared in this class.
    This MonoBehaviour-style component only exposes public serialized fields; all data is transferred into an ECS CalendarEventData struct during Initialize.

Constructors

  • public CalendarEvent()
    Default parameterless constructor (compiler-generated). Default field initializers are:
  • m_RandomTargetType = EventTargetType.Couple
  • m_AffectedProbability = new Bounds1(25f, 25f)
  • m_OccurenceProbability = new Bounds1(100f, 100f)
  • m_AllowedMonths = 0 (none selected) — set via inspector
  • m_AllowedTimes = 0 (none selected) — set via inspector
  • m_Duration = 0 — set via inspector

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime ECS component types required on entities created from this prefab. Implementation adds:
  • ComponentType.ReadWrite()
    This indicates that the entity will contain CalendarEventData to store the event's configured values.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds full archetype component set used when creating the entity archetype for this prefab. Implementation adds:

  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
    These components define the ECS archetype for the calendar event entity (the event behavior component plus duration and target storage).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Copies serialized prefab data into an ECS CalendarEventData instance and sets it on the created entity:

  • Creates a CalendarEventData local variable and populates:
    • m_RandomTargetType
    • m_AffectedProbability
    • m_OccurenceProbability
    • m_AllowedMonths
    • m_AllowedTimes
    • m_Duration
  • Calls entityManager.SetComponentData(entity, componentData) to apply the data to the entity. This method is the bridge from the prefab/MonoBehaviour representation to the ECS component representation used at runtime.

Additional notes: - The class is annotated with [ComponentMenu("Events/", new Type[] { typeof(EventPrefab) })], making it available under Events/ in the Unity Add Component menu and indicating its role as an EventPrefab. - The flagged enum fields (m_AllowedMonths, m_AllowedTimes) use [EnumFlag] to allow multi-select in the inspector. - The Unity tooltip on m_Duration clarifies the unit used.

Usage Example

// Typical behavior: the engine/editor creates this prefab and calls Initialize.
// The Initialize override populates CalendarEventData on the created entity:

public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);
    CalendarEventData componentData = default(CalendarEventData);
    componentData.m_RandomTargetType = m_RandomTargetType;
    componentData.m_AffectedProbability = m_AffectedProbability;
    componentData.m_OccurenceProbability = m_OccurenceProbability;
    componentData.m_AllowedMonths = m_AllowedMonths;
    componentData.m_AllowedTimes = m_AllowedTimes;
    componentData.m_Duration = m_Duration;
    entityManager.SetComponentData(entity, componentData);
}

If you want, I can also: - Generate reference docs for the related ECS struct CalendarEventData (if you provide its definition). - Show an example of creating a prefab entity in code that uses this component.