Game.Events.SpectatorSite
Assembly:
Namespace: Game.Events
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a spectator site component used by the game's ECS. It stores a reference to an event entity (the "spectated" event) and supports Colossal's serialization API so the entity reference can be saved/loaded. This component can be added to entities to mark them as spectator sites and to associate them with a particular event entity.
Fields
public Unity.Entities.Entity m_Event
Stores the Entity that represents the associated event. This is the core payload of the component — the entity which spectators at this site are observing. When serialized, this field is written/read via the Colossal serialization writer/reader.
Properties
- This type does not declare any properties.
Constructors
public SpectatorSite(Entity _event)
Constructs a new SpectatorSite component and initializes m_Event with the provided event Entity. Useful for creating and attaching the component in code when an association between a site and an event is established.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Event field to the provided writer. Used by the Colossal serialization system to persist the reference to the event entity. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the m_Event field from the provided reader. Restores the association to the event entity when the world/data is loaded.
Usage Example
// Example: creating an entity and adding the SpectatorSite component
// (assumes using Unity.Entities and a valid eventEntity already exists)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
// Create a site entity
Entity siteEntity = entityManager.CreateEntity();
// Associate the site with an event entity
entityManager.AddComponentData(siteEntity, new Game.Events.SpectatorSite(eventEntity));
// Later: read the associated event
var siteComp = entityManager.GetComponentData<Game.Events.SpectatorSite>(siteEntity);
Entity associatedEvent = siteComp.m_Event;