Created
February 23, 2019 20:15
-
-
Save psuong/6e2e5e68354a2ed1537fa8d43bb29e27 to your computer and use it in GitHub Desktop.
Charging a Charge Shot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChargeFXIndicatorSystem : ComponentSystem { | |
private ComponentGroup particleGroup, playerGroup; | |
protected override void OnCreateManager() { | |
particleGroup = GetComponentGroup(ComponentType.ReadOnly<ParticleSystemPair>(), ComponentType.ReadOnly<ID>()); | |
playerGroup = GetComponentGroup(ComponentType.ReadOnly<ChargeShotTimer>(), ComponentType.ReadOnly<ID>()); | |
} | |
protected override void OnUpdate() { | |
var playerEntities = playerGroup.GetEntityArray(); | |
var times = new NativeArray<ChargeShotTimer>(playerEntities.Length, Allocator.Temp); | |
ForEach((ref ChargeShotTimer timer, ref ID id) => { | |
times[id.Value] = timer; | |
}, playerGroup); | |
ForEach((ParticleSystemPair pair, ref ID id) => { | |
var time = times[id.Value]; | |
if (time.Current <= float.Epsilon) { | |
pair.Parent.Clear(true); | |
pair.Parent.Stop(true); | |
pair.Parent.time = pair.Child.time = 0f; | |
} | |
if (time.Current > 0f && !pair.Child.isPlaying) { | |
pair.Child.Play(false); | |
} | |
if (time.Current >= time.Wait) { | |
pair.Parent.Play(false); | |
} | |
}, particleGroup); | |
times.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment