1 [
EntityEditorProps(
category:
"GameScripted/BaseInteractiveLightComponent", description:
"Handling behaviour of interactive (can be turned on / off) light on prefabs.")]
5 private ref array<ref SCR_BaseLightData> m_aLightData;
7 [
Attribute(
"0", UIWidgets.CheckBox,
"Gradual lighting?")]
8 private bool m_bGradualLightning;
10 [
Attribute(
"0", UIWidgets.EditBox,
"LV of light effect")]
23 bool IsGradualLightningOn()
25 return m_bGradualLightning;
30 ref array<ref SCR_BaseLightData> GetLightData()
43 class SCR_BaseInteractiveLightComponent : SCR_BaseLightComponent
45 protected ref array<LightEntity>
m_aLights;
54 protected const static float MATERIAL_EMISSIVITY_STEP = 0.1;
55 protected const static int MATERIAL_EMISSIVITY_ON = 30;
56 protected const static float LIGHT_EMISSIVITY_START = 0.1;
57 protected const static int MATERIAL_EMISSIVITY_START = 1;
58 protected const static int LIGHT_EMISSIVITY_OFF = 0;
59 protected const static int UPDATE_LIGHT_TIME = 100;
61 [
Attribute(defvalue:
"0", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(ELightState))]
73 case ELightState.LIT_ON_SPAWN:
98 void ToggleLight(
bool turnOn,
bool skipTransition =
false,
bool playSound =
true)
108 TurnOn(componentData, skipTransition, playSound);
110 TurnOff(componentData, playSound);
119 vector lightDirection;
123 if (!System.IsConsoleApp())
127 SoundComponent soundComponent = SoundComponent.Cast(owner.FindComponent(SoundComponent));
132 SignalsManagerComponent signalsManagerComponent = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
133 if (signalsManagerComponent)
134 signalsManagerComponent.SetSignalValue(signalsManagerComponent.AddOrFindSignal(
"Trigger"), 1);
147 owner.GetTransform(mat);
149 lightOffset = lightData.GetLightOffset();
150 lightDirection = (lightData.GetLightConeDirection().Multiply4(mat) - lightOffset.Multiply4(mat)).Normalized();
151 pos = owner.GetOrigin() + lightOffset;
153 light =
CreateLight(lightData, pos, lightDirection, LIGHT_EMISSIVITY_START);
157 owner.AddChild(light, -1, EAddChildFlags.AUTO_TRANSFORM | EAddChildFlags.RECALC_LOCAL_TRANSFORM);
158 light.SetFlags(EntityFlags.PROXY);
166 if (skipTransition || !componentData.IsGradualLightningOn())
171 for (
int i = 0, count =
m_aLights.Count(); i < count; i++)
173 m_aLights[i].SetColor(Color.FromVector(componentData.GetLightData()[i].GetLightColor()), componentData.GetLightLV());
180 m_fCurEM = MATERIAL_EMISSIVITY_START;
181 m_fLightEmisivityStep = componentData.GetLightLV() / ((MATERIAL_EMISSIVITY_ON - MATERIAL_EMISSIVITY_START) / MATERIAL_EMISSIVITY_STEP);
183 SetEventMask(
GetOwner(), EntityEvent.VISIBLE);
190 if (!System.IsConsoleApp())
193 SignalsManagerComponent signalsManagerComponent = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
197 SoundComponent soundComponent = SoundComponent.Cast(owner.FindComponent(SoundComponent));
202 if (signalsManagerComponent)
203 signalsManagerComponent.SetSignalValue(signalsManagerComponent.AddOrFindSignal(
"Trigger"), 0);
206 if (!componentData.GetLightData().IsEmpty())
214 ClearEventMask(
GetOwner(), EntityEvent.VISIBLE);
232 bool shouldUpdate =
true;
234 for (
int i = 0, count = Math.Min(componentData.GetLightData().Count(),
m_aLights.Count()); i < count; i++)
252 m_aLights[lightArrayIndex].SetColor(Color.FromVector(lightData.GetLightColor()),
m_fCurLV);
258 m_fCurEM += MATERIAL_EMISSIVITY_STEP;
265 super.RplSave(writer);
267 writer.WriteBool(
IsOn());
275 super.RplLoad(reader);
278 reader.ReadBool(isOn);
287 super.OnPostInit(owner);
312 super.OnDelete(owner);