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;
8 private bool m_bGradualLightning;
14 private float m_fDistanceAttenuation;
25 float GetDistanceAttenuation()
27 return m_fDistanceAttenuation;
33 bool IsGradualLightningOn()
35 return m_bGradualLightning;
40 ref array<ref SCR_BaseLightData> GetLightData()
53class SCR_BaseInteractiveLightComponent : SCR_BaseLightComponent
62 private bool m_bUpdate;
64 protected const static float MATERIAL_EMISSIVITY_STEP = 0.1;
65 protected const static int MATERIAL_EMISSIVITY_ON = 30;
66 protected const static float LIGHT_EMISSIVITY_START = 0.1;
67 protected const static int MATERIAL_EMISSIVITY_START = 1;
68 protected const static int LIGHT_EMISSIVITY_OFF = 0;
69 protected const static int UPDATE_LIGHT_TIME = 100;
71 [
Attribute(defvalue:
"0", uiwidget:
UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(ELightState))]
72 private ELightState m_eInitialLightState;
76 bool GetInitialState()
78 switch (m_eInitialLightState)
83 case ELightState.LIT_ON_SPAWN:
108 void ToggleLight(
bool turnOn,
bool skipTransition =
false,
bool playSound =
true)
113 SCR_BaseInteractiveLightComponentClass componentData = SCR_BaseInteractiveLightComponentClass.Cast(
GetComponentData(
GetOwner()));
118 TurnOn(componentData, skipTransition, playSound);
120 TurnOff(componentData, playSound);
129 if (!
System.IsConsoleApp())
139 if (signalsManagerComponent)
140 signalsManagerComponent.SetSignalValue(signalsManagerComponent.AddOrFindSignal(
"Trigger"), 1);
155 vector lightDirection = lightData.GetLightConeDirection().Multiply3(mat).Normalized();
156 vector pos = lightData.GetLightOffset().Multiply4(mat);
158 LightEntity light =
CreateLight(lightData, pos, lightDirection, LIGHT_EMISSIVITY_START);
170 if (skipTransition || !componentData.IsGradualLightningOn())
175 for (
int i = 0, count =
m_aLights.Count(); i < count; i++)
177 m_aLights[i].SetColor(
Color.FromVector(componentData.GetLightData()[i].GetLightColor()), componentData.GetLightLV());
178 m_aLights[i].SetDistanceAtt(componentData.GetDistanceAttenuation());
185 m_fCurEM = MATERIAL_EMISSIVITY_START;
186 m_fLightEmisivityStep = componentData.GetLightLV() / ((MATERIAL_EMISSIVITY_ON - MATERIAL_EMISSIVITY_START) / MATERIAL_EMISSIVITY_STEP);
195 if (!
System.IsConsoleApp())
207 if (signalsManagerComponent)
208 signalsManagerComponent.SetSignalValue(signalsManagerComponent.AddOrFindSignal(
"Trigger"), 0);
211 if (!componentData.GetLightData().IsEmpty())
237 bool shouldUpdate =
true;
239 for (
int i = 0, count =
Math.Min(componentData.GetLightData().Count(),
m_aLights.Count()); i < count; i++)
242 UpdateLightEmissivity(componentData.GetLightData()[i], i);
245 UpdateMaterialEmissivity();
250 m_bUpdate = shouldUpdate;
254 private void UpdateLightEmissivity(notnull SCR_BaseLightData lightData,
int lightArrayIndex)
257 m_aLights[lightArrayIndex].SetColor(Color.FromVector(lightData.GetLightColor()),
m_fCurLV);
261 private void UpdateMaterialEmissivity()
263 m_fCurEM += MATERIAL_EMISSIVITY_STEP;
268 override bool RplSave(ScriptBitWriter writer)
270 super.RplSave(writer);
272 writer.WriteBool(IsOn());
278 override bool RplLoad(ScriptBitReader reader)
280 super.RplLoad(reader);
283 reader.ReadBool(isOn);
292 super.OnPostInit(owner);
317 super.OnDelete(owner);
ArmaReforgerScripted GetGame()
override bool RplLoad(ScriptBitReader reader)
SCR_BaseInteractiveLightComponentClass OFF
SCR_BaseInteractiveLightComponentClass LIT_ON_SPAWN
float m_fLightEmisivityStep
SCR_BaseInteractiveLightComponentClass m_aLights
ParametricMaterialInstanceComponent m_EmissiveMaterialComponent
SCR_BaseInteractiveLightComponentClass LIT
SCR_BaseLightComponentClass ScriptComponentClass CreateLight(SCR_BaseLightData lightData, vector position, vector direction, float emissivity)
override bool RplSave(ScriptBitWriter writer)
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
override void ToggleLight(bool turnOn, bool skipTransition=false, bool playSound=true)
override void EOnVisible(IEntity owner, int frameNumber)
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
EntityFlags
Various entity flags.
void TurnOff()
Remove every particle associed with this effect.