Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ParticleContactComponent.c
Go to the documentation of this file.
1 class SCR_ParticleContactComponentClass : ScriptComponentClass
2 {
3  [Attribute(category: "Sound")]
4  ref SCR_AudioSourceConfiguration m_AudioSourceConfiguration;
5 
6  [Attribute("true", desc: "Set surface signal", category: "Sound")]
7  bool m_bSurfaceSignal;
8 
9  [Attribute("false", desc: "If to play particle effect", category: "VFX")]
10  bool m_bPlayParticle;
11 
12  [Attribute("", UIWidgets.ResourcePickerThumbnail, desc: "Particle effect", params: "ptc", category: "VFX")]
13  ResourceName m_Particle;
14 
15  [Attribute("0", uiwidget: UIWidgets.ComboBox, "Desired type of Game Material effect", "", ParamEnumArray.FromEnum(EParticleEffectInfoType), category: "VFX")]
16  int m_iGameMaterialEffect;
17 
18  [Attribute("0", desc: "Index of Material Effect type", category: "VFX")]
19  int m_iEffectIndex;
20 
21  [Attribute("true", desc: "Disable OnContact after the first contact")]
22  bool m_bFirstContactOnly;
23 
24  [Attribute("false", desc: "Particle oriented to surface", category: "VFX")]
25  bool m_bParticleOriented;
26 }
27 
28 enum EParticleEffectInfoType
29 {
30  NONE = 0,
31  VEHICLE = 1,
32  BLAST = 2,
33 }
34 
35 class SCR_ParticleContactComponent : ScriptComponent
36 {
37  //------------------------------------------------------------------------------------------------
38  private void PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
39  {
40  SCR_SoundManagerEntity soundManagerEntity = GetGame().GetSoundManagerEntity();
41  if (!soundManagerEntity)
42  return;
43 
44  if (!prefabData.m_AudioSourceConfiguration || !prefabData.m_AudioSourceConfiguration.IsValid())
45  return;
46 
47  // Create audio source
48  SCR_AudioSource audioSource = soundManagerEntity.CreateAudioSource(owner, prefabData.m_AudioSourceConfiguration);
49  if (!audioSource)
50  return;
51 
52  // Set surface signal
53  if (prefabData.m_bSurfaceSignal)
54  {
55  GameMaterial material = contact.Material2;
56  if (material)
57  audioSource.SetSignalValue(SCR_AudioSource.SURFACE_SIGNAL_NAME, material.GetSoundInfo().GetSignalValue());
58  }
59 
60  // Play sound
61  if (SCR_Enum.HasFlag(prefabData.m_AudioSourceConfiguration.m_eFlags, EAudioSourceConfigurationFlag.Static))
62  {
63  vector mat[4];
64  Math3D.MatrixIdentity4(mat);
65  mat[3] = contact.Position;
66 
67  soundManagerEntity.PlayAudioSource(audioSource, mat);
68  }
69  else
70  soundManagerEntity.PlayAudioSource(audioSource);
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  override void OnPostInit(IEntity owner)
75  {
76  SCR_ParticleContactComponentClass prefabData = SCR_ParticleContactComponentClass.Cast(GetComponentData(owner));
77  if (!prefabData)
78  return;
79 
80  SetEventMask(owner, EntityEvent.CONTACT);
81 
82 #ifdef ENABLE_DIAG
83  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_PARTICLES_CONTACT_COMPONENT, "", "Show Particle Contacts", "Particles");
84 #endif
85 
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void EOnContact(IEntity owner, IEntity other, Contact contact)
90  {
91  // Get prefab data
92  SCR_ParticleContactComponentClass prefabData = SCR_ParticleContactComponentClass.Cast(GetComponentData(owner));
93  if (!prefabData)
94  {
95  ClearEventMask(owner, EntityEvent.CONTACT);
96  return;
97  }
98 
99  // Play sound
100  PlaySound(owner, prefabData, contact);
101 
102  //Play VFX
103  if (prefabData.m_bPlayParticle)
104  {
105 
106  //Play game material effect
107  if (prefabData.m_iGameMaterialEffect == 1)
108  {
109  GameMaterial material = contact.Material2;
110  ParticleEffectInfo effectInfo = material.GetParticleEffectInfo();
111 
112  if (effectInfo)
113  {
114  prefabData.m_Particle = effectInfo.GetVehicleDustResource(prefabData.m_iEffectIndex);
115  }
116  }
117  else if (prefabData.m_iGameMaterialEffect == 2)
118  {
119  GameMaterial material = contact.Material2;
120  ParticleEffectInfo effectInfo = material.GetParticleEffectInfo();
121 
122  if (effectInfo)
123  {
124  prefabData.m_Particle = effectInfo.GetBlastResource(prefabData.m_iEffectIndex);
125  }
126  }
127 
128  if (prefabData.m_Particle != string.Empty)
129  {
130  ParticleEffectEntitySpawnParams spawnParams();
131  spawnParams.UseFrameEvent = true;
132 
133  if (prefabData.m_bParticleOriented)
134  Math3D.AnglesToMatrix(contact.Normal, spawnParams.Transform);
135 
136  spawnParams.Transform[3] = contact.Position;
137  ParticleEffectEntity.SpawnParticleEffect(prefabData.m_Particle, spawnParams);
138 
139 #ifdef ENABLE_DIAG
140  if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_PARTICLES_CONTACT_COMPONENT))
141  return;
142 
143  DebugTextWorldSpace.Create(GetOwner().GetWorld(), contact.Material2.GetName(), DebugTextFlags.CENTER, contact.Position[0], contact.Position[1], contact.Position[2]);
144 #endif
145  }
146  }
147 
148  // Disable OnContact after the first contact
149  if (prefabData.m_bFirstContactOnly)
150  ClearEventMask(owner, EntityEvent.CONTACT);
151  }
152 }
SCR_AudioSource
Definition: SCR_AudioSource.c:1
SCR_Enum
Definition: SCR_Enum.c:1
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
NONE
SCR_ParticleContactComponentClass NONE
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EAudioSourceConfigurationFlag
EAudioSourceConfigurationFlag
Definition: SCR_AudioSourceConfiguration.c:1
EOnContact
override void EOnContact(IEntity owner, IEntity other, Contact contact)
Definition: SCR_ParticleContactComponent.c:89
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_SoundManagerEntity
Definition: SCR_SoundManagerEntity.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_ParticleContactComponent.c:74
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
VEHICLE
SCR_ParticleContactComponentClass VEHICLE
BLAST
SCR_ParticleContactComponentClass BLAST
ParticleEffectInfo
Definition: ParticleEffectInfo.c:12
SCR_ParticleContactComponentClass
Definition: SCR_ParticleContactComponent.c:1
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
GameMaterial
Definition: GameMaterial.c:12
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180