Skip to main content

PlatformLight

A class in Root.Township, Alta.Lighting.

A light that registers with a platform lights controller. On PC it wraps a Unity Light; on Android it uses a fake light mesh instead. Enabling and disabling it adds and removes it from the controller.

Constructors​

MemberWhat it is
PlatformLight()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
Vector3 lastPositionPosition recorded by the last GetPosition call.
11 private and internal fields
MemberWhat it is
private Mesh androidMeshMesh used for the fake light on Android. With none set, no fake light is made.
private Color androidMeshColorColour baked into the Android fake light mesh.
private Color colorSerialized colour value. The Color property reads the Light component instead.
private Renderer fakeLightRendererRenderer of the Android fake light mesh, made in Setup.
private bool hasFakeLightTrue on Android when a fake light mesh was made.
private float intensityIntensity used to build the Android fake light mesh. The Intensity property reads the Light instead.
private bool isNotImportantMarks the light as low priority: deprioritised as a pixel light on PC and ignored for darkness on Android.
private bool isSetupSet once Setup has run, so it only runs once.
private static BaseLightsController lightsControllerBacking field for LightsController, made on first use (Android or PC version).
private float rangeRange used to scale the Android fake light mesh (twice the range).
private Light targetLightBacking field for TargetLight, the Light component on this object.

Properties​

MemberWhat it is
static bool AvoidBake { get; set; }Static flag read during the build bake. Has no effect in this code.
Color Color { get; set; }Colour of the Unity light.
float Intensity { get; set; }Intensity of the Unity light.
bool IsActive { get; set; }Set by the lights controller, probably to say whether the light is currently in use.
bool IsNotImportant { get; }If true, it is a low priority pixel light on PC and does not count against darkness on Android.
static BaseLightsController LightsController { get; }The shared controller for the platform: Android or PC. Made on first use.
static int MaxLightCount { get; }Pixel light budget from quality settings, minus one.
float Range { get; set; }Range of the Unity light.
LightShadows Shadows { get; set; }Shadow mode of the Unity light.
Light TargetLight { get; }The Unity Light on this object.

Methods​

MemberWhat it is
Vector3 GetPosition()Returns the current position and stores it in lastPosition.
void SetEnableFakeLight(bool isEnabled)Shows or hides the Android fake light mesh, if there is one.
5 private and internal methods
MemberWhat it is
private void Awake()Runs Setup if the light hasn't been set up yet.
private void OnDisable()Removes the light from the lights controller and hides the Android fake light mesh.
private void OnEnable()Adds the light to the platform's lights controller.
private void IBuildRendererPostBake.PostBake()Build bake hook. Does nothing in this build apart from reading AvoidBake.
private void Setup()On Android, builds a child "Fake Light" mesh renderer scaled to the range. On PC, caches the Light component.

Used in​

Members of other types that take, return or hold a PlatformLight: