WorldPower
This page uses GameObject from Unity. The glossary says what each one is.
WorldPower tells your mod about blackouts and generators, and lets you control how the player wakes up after a blackout.
WorldPower blackouts, generators and wake-ups
Use ScheduleWakeUp to choose how the player wakes after a blackout, and WakeUp to wake them now.
public static class WorldPower
{
public static event Action BlackoutStarted;
public static event Action<bool> GeneratorToggled;
public static bool IsAvailable { get; }
public static bool IsBlackoutRunning { get; }
public static bool AnyGeneratorRunning { get; }
public static bool ScheduleWakeUp(float fadeOutSpeed, float wakeUpDelay, WakeUpAnimation wakeUpAnimation, bool autoWakeUp);
public static bool WakeUp();
}
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when a blackout or generator event could not be set up. |
IsBlackoutRunning | bool | true while a blackout sequence is playing. |
AnyGeneratorRunning | bool | true while any generator is running with power. |
| Method | Returns | What it does |
|---|---|---|
ScheduleWakeUp(fadeOutSpeed, wakeUpDelay, wakeUpAnimation, autoWakeUp) | bool | Sets how the player wakes after the next level load. |
WakeUp() | bool | Wakes the player now. |
| Event | Gives you | When it fires |
|---|---|---|
BlackoutStarted | Nothing | A blackout has just started. |
GeneratorToggled | bool | A generator was switched. The value is the new On state. |
WakeUpAnimation how the player wakes up
ScheduleWakeUp takes one of these to pick how the player wakes up.
public enum WakeUpAnimation
{
None,
OnGround,
OnGround2
}
| Value | Meaning |
|---|---|
None | No wake-up animation. |
OnGround | The player wakes up on the ground. |
OnGround2 | The player wakes up on the ground, with the game’s second ground animation. |
Things to know
- The game has no single power cut for the whole world. Power belongs to each device.
IsBlackoutRunningis only about the scripted blackout: the fade to black, the theft and the teleport. (Power is per device (PowerSource).IsBlackoutRunningis true while anyBlackoutTriggersequence is in progress.) BlackoutStartedfires when a new blackout sequence starts. Calls made while one is already running do not fire it again. (It fires when aBlackoutTrigger.StartBlackoutcall starts a new sequence.)GeneratorToggledfires when a generator is really switched on or off. The value is the new On state. It does not fire when a generator runs out of fuel, because the game turns that off another way. (It fires when the generator’s On switch changes throughCraftingBase.Toggle.)ScheduleWakeUponly stores the wake-up for later. The wake-up happens on the next level load, which is when the player wakes.ScheduleWakeUpdoes not change the level, so your code must change it, the way the game’s blackout does just before the level change. (It callsBlackoutController.SetScheduleWakeUp. The wake-up takes effect inBlackoutController.OnLoadingGame.BlackoutTriggerchanges the level withSaveController.ChangeLevel.)WakeUpwakes the player now, using the settings the game stored at the last blackout. It does not use the ones fromScheduleWakeUp. A blackout withautoWakeUpset tofalsestores them. With none stored, it runs with the animationNoneand no delay, and it turns the controls back on. (It calls the game’sBlackoutController.TriggerWakeUp, which uses the manual values fromSetPendingFinish.)IsAvailabletells you whether the two events work. It isfalsewhen the blackout change or the generator change is missing or turned off. A missing change stops only its own event, and the other event keeps firing whileIsAvailableisfalse. Reads are not affected.- The light culling system is not a power state. It only hides far-away lights to save work, so it is not here. (It is
LightsController.)
Limits
- Both calls return
falsein some cases: during a save or a load, and when the game’s blackout controller is missing.WakeUpalso returnsfalsewhen the black screen is missing, because the game needs it to finish the wake-up. (BlackoutController.instanceisnull, orBlackCanvas.instanceisnull.FinishWakeUpreadsBlackCanvas.instance.gameObject.)