8 [
Attribute(
"", UIWidgets.ResourceAssignArray,
"Generated explosions will loop through the projectiles on this array",
"et")]
9 ref array<ResourceName> m_ProjectilesToTrigger;
12 [
Attribute(
"0", UIWidgets.EditBox,
"Number of explosions to create. 0 = until time ends")]
15 [
Attribute(
"0", UIWidgets.EditBox,
"Time until this entity creates a new explosion.")]
16 float m_TimeBetweenExplosions;
18 [
Attribute(
"0", UIWidgets.EditBox,
"Time (in seconds) until no more explosions are generated. This is not needed if Num Explosions is different to 0")]
19 float m_TotalDuration;
22 ref array<ref Resource> m_LoadedPrefabs =
new array<ref Resource>();
24 int m_RemainingExplosions = 0;
25 float m_TimeUntilNextExplosion = 0;
26 float m_RemainingDuration = 0;
30 int m_CurrentExplosionPrefab = 0;
36 SetEventMask(EntityEvent.FRAME);
38 for(
int i = 0; i < m_ProjectilesToTrigger.Count(); i++)
40 if(m_ProjectilesToTrigger[i])
41 m_LoadedPrefabs.Insert(Resource.Load(m_ProjectilesToTrigger[i]));
44 m_RemainingExplosions = m_NumExplosions;
45 m_TimeUntilNextExplosion = m_TimeBetweenExplosions;
46 m_RemainingDuration = m_TotalDuration;
50 override protected void EOnFrame(IEntity owner,
float timeSlice)
53 if (m_NumExplosions == 0 && m_RemainingDuration < 0 || m_NumExplosions != 0 && m_RemainingExplosions <= 0)
55 ClearEventMask(EntityEvent.FRAME);
59 m_TimeUntilNextExplosion -= timeSlice;
60 m_RemainingDuration -= timeSlice;
63 if (m_TimeUntilNextExplosion > 0)
67 m_TimeUntilNextExplosion += m_TimeBetweenExplosions;
69 CreateExplosion(owner);
72 protected void CreateExplosion(IEntity owner)
74 ref Resource prefab = m_LoadedPrefabs[m_CurrentExplosionPrefab];
76 AdvanceExplosionPrefab();
78 m_RemainingExplosions--;
83 ref EntitySpawnParams spawnParams =
new EntitySpawnParams();
85 spawnParams.TransformMode = ETransformMode.WORLD;
86 owner.GetTransform(spawnParams.Transform);
88 IEntity spawnedProjectile =
GetGame().SpawnEntityPrefab(prefab, owner.GetWorld(), spawnParams);
95 comp.OnUserTrigger(spawnedProjectile);
100 protected void AdvanceExplosionPrefab()
102 ++m_CurrentExplosionPrefab;
104 if (m_CurrentExplosionPrefab >= m_LoadedPrefabs.Count())
105 m_CurrentExplosionPrefab = 0;