Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpawnCubeSystem : ComponentSystem
- {
- Settings settings;
- int totalCubeCount;
- bool isFirstTime;
- public void Init(Settings inSettings, EntityManager entityManager, MeshInstanceRenderer look)
- {
- isFirstTime = true;
- settings = inSettings;
- int totalCubeCount = settings.spectrumSize*2;
- for(int index = 0;
- index < totalCubeCount;
- ++index)
- {
- EntityArchetype archetype = entityManager.CreateArchetype(typeof(Cube),
- typeof(Origin),
- typeof(TransformMatrix),
- typeof(Position),
- typeof(LocalRotation),
- typeof(Scale));
- Entity cube = entityManager.CreateEntity(archetype);
- entityManager.AddSharedComponentData(cube, look);
- }
- }
- public struct CubesGroup
- {
- public int Length;
- public ComponentDataArray<Cube> cubes;
- public ComponentDataArray<Position> positions;
- public ComponentDataArray<Origin> origins;
- }
- [Inject]
- CubesGroup group;
- protected override void OnUpdate()
- {
- if(isFirstTime)
- {
- int spectrumSize = settings.spectrumSize;
- for(int index = 0;
- index < totalCubeCount;
- ++index)
- {
- int groupIndex = index;
- SpiralPos pos = Utils.GetSpiralPos(groupIndex);
- Position position = group.positions[groupIndex];
- position.Value = new float3(pos.x, 0, pos.z);
- group.positions[groupIndex] = position;
- Origin origin = group.origins[groupIndex];
- origin.Value = position.Value;
- group.origins[groupIndex] = origin;
- }
- }
- isFirstTime = false;
- }
- }
Add Comment
Please, Sign In to add comment