-
-
Save martindevans/d39e0776eccfb2d601aec7a5d5b485d1 to your computer and use it in GitHub Desktop.
This file contains 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
[UpdateAfter(typeof(PowerSystem))] | |
public class LightBulbPostSystem | |
: JobComponentSystem | |
{ | |
private struct AfterPower | |
: IJobParallelFor | |
{ | |
[WriteOnly] private ComponentDataArray<LightBulb> _outputs; | |
[ReadOnly] private ComponentDataArray<PowerInput> _inputs; | |
public AfterPower(ComponentDataArray<LightBulb> outputs, ComponentDataArray<PowerInput> inputs) | |
{ | |
_outputs = outputs; | |
_inputs = inputs; | |
} | |
public void Execute(int index) | |
{ | |
var supply = _inputs[index].PowerSupplied; | |
var request = _inputs[index].PowerRequested; | |
var bulb = new LightBulb { | |
Brightness = supply / request | |
}; | |
_outputs[index] = bulb; | |
} | |
} | |
private struct Group | |
{ | |
[WriteOnly] public ComponentDataArray<LightBulb> Bulbs; | |
[ReadOnly] public ComponentDataArray<PowerInput> Inputs; | |
public readonly int Length; | |
} | |
[Inject] private Group _lights; | |
protected override JobHandle OnUpdate(JobHandle inputDeps) | |
{ | |
return new AfterPower(_lights.Bulbs, _lights.Inputs).Schedule(_lights.Length, 128, inputDeps); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment