Game.UI.InGame.ScheduleSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
UI section used by the in-game transport line inspector to display and control a line's day/night schedule. It reads transport UI configuration (day/night route policy entities), exposes a "setSchedule" trigger binding for the UI to change a line's schedule, updates its visibility based on the selected entity, computes the current schedule from the Route component, and serializes the schedule value. The section interacts with PoliciesUISystem to enable/disable the day/night route policies for the selected transport line.
Fields
-
private PoliciesUISystem m_PoliciesUISystem
Holds a reference to the PoliciesUISystem retrieved from the ECS World. Used to enable/disable policy entities (day/night route policies) on the currently selected transport line. -
private Entity m_NightRoutePolicy
Entity reference to the night route policy prefab as provided by the UI transport configuration prefab. This is set during OnGameLoaded if configuration data is available. -
private Entity m_DayRoutePolicy
Entity reference to the day route policy prefab as provided by the UI transport configuration prefab. This is set during OnGameLoaded if configuration data is available. -
private EntityQuery m_ConfigQuery
EntityQuery used to find UITransportConfigurationData in the world so the section can obtain the singleton UITransportConfigurationPrefab and locate the day/night policy prefabs.
Properties
private RouteSchedule schedule { get; set; }
Stores the current schedule state for the selected route as one of the RouteSchedule enum values (Day, Night, DayAndNight). It is reset to RouteSchedule.DayAndNight in Reset() and updated during OnProcess() by reading the Route component.
Constructors
public ScheduleSection()
Default constructor. Marked with Preserve in the original code — used by the runtime/serialization to ensure the constructor is not stripped. Initialization of systems and bindings happens in OnCreate rather than in the constructor.
Methods
-
protected override string group => "ScheduleSection"
Read-only override returning the UI group name used by bindings ("ScheduleSection"). This is the group used when adding TriggerBinding for the UI. -
protected override void Reset()
Initializes section state when the inspector resets. Sets schedule to RouteSchedule.DayAndNight as the default. -
[Preserve] protected override void OnCreate()
Called when the section is created. Retrieves the PoliciesUISystem from the world, builds an EntityQuery to find UITransportConfigurationData, and registers a TriggerBindingwith the UI: -
Binding: group = "ScheduleSection", name = "setSchedule", callback = OnSetSchedule This method prepares the section to react to UI actions to change the schedule.
-
protected override void OnGameLoaded(Context serializationContext)
Called after the game data is loaded. If a UITransportConfigurationData singleton exists in the world, retrieves the UITransportConfigurationPrefab and resolves the prefab's m_DayRoutePolicy and m_NightRoutePolicy to actual ECS Entity instances via m_PrefabSystem.GetEntity. These Entities are later used in OnSetSchedule to toggle policies. -
private void OnSetSchedule(int newSchedule)
Callback invoked by the "setSchedule" UI trigger. Casts newSchedule to RouteSchedule and applies policies accordingly using m_PoliciesUISystem.SetPolicy(selectedEntity, policyEntity, active): - RouteSchedule.Day: enable day policy, disable night policy
- RouteSchedule.Night: enable night policy, disable day policy
-
default / DayAndNight: disable both day and night policies This method changes the active route policies on the selected transport line.
-
private bool Visible()
Determines whether this UI section should be visible for the currently selected entity. Returns true only if the selected entity has Route and TransportLine components and also has a RouteWaypoint component. Otherwise returns false. -
[Preserve] protected override void OnUpdate()
Called each update; sets base.visible based on the result of Visible(). Ensures the section shows/hides according to the selected entity's components. -
protected override void OnProcess()
Called to update the section's internal display state. Reads the Route component for the selectedEntity, inspects route options using RouteUtils.CheckOption to determine if the route has Day or Night options set, and sets schedule accordingly: - If RouteOption.Day is set => RouteSchedule.Day
- Else if RouteOption.Night is set => RouteSchedule.Night
-
Else => RouteSchedule.DayAndNight Also adds tooltip tags "TransportLine" and "CargoRoute" (via base.tooltipTags) which may be used by the UI.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the current schedule into the JSON writer. Writes a property named "schedule" with an integer representing the current RouteSchedule value. Used by the inspector's serialization pipeline to persist UI state.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire the PoliciesUISystem to toggle policies on the selected line
m_PoliciesUISystem = base.World.GetOrCreateSystemManaged<PoliciesUISystem>();
// Query to find UI transport configuration singleton (to resolve day/night policy prefabs)
m_ConfigQuery = GetEntityQuery(ComponentType.ReadOnly<UITransportConfigurationData>());
// Register UI trigger binding: UI will call "setSchedule" with an int
AddBinding(new TriggerBinding<int>(group, "setSchedule", OnSetSchedule));
}
Notes and tips: - The section depends on m_PrefabSystem and m_PoliciesUISystem; those come from the base InfoSectionBase/context and the ECS World. - To change a line's schedule from UI, the front-end should invoke the "ScheduleSection" group's "setSchedule" trigger with an int matching the RouteSchedule enum. - If the UITransportConfigurationPrefab is missing or the config query is empty, day/night policy entities will not be set and OnSetSchedule will attempt to operate on null/empty entities — ensure the configuration prefab is present for policy toggling to work.