Skip to content

Instantly share code, notes, and snippets.

@psuong
Created February 23, 2019 20:15
Show Gist options
  • Save psuong/6e2e5e68354a2ed1537fa8d43bb29e27 to your computer and use it in GitHub Desktop.
Save psuong/6e2e5e68354a2ed1537fa8d43bb29e27 to your computer and use it in GitHub Desktop.
Charging a Charge Shot
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