Guest User

Untitled

a guest
Jul 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. public class SpawnCubeSystem : ComponentSystem
  2. {
  3. Settings settings;
  4. int totalCubeCount;
  5. bool isFirstTime;
  6.  
  7. public void Init(Settings inSettings, EntityManager entityManager, MeshInstanceRenderer look)
  8. {
  9. isFirstTime = true;
  10. settings = inSettings;
  11.  
  12. int totalCubeCount = settings.spectrumSize*2;
  13. for(int index = 0;
  14. index < totalCubeCount;
  15. ++index)
  16. {
  17. EntityArchetype archetype = entityManager.CreateArchetype(typeof(Cube),
  18. typeof(Origin),
  19. typeof(TransformMatrix),
  20. typeof(Position),
  21. typeof(LocalRotation),
  22. typeof(Scale));
  23.  
  24. Entity cube = entityManager.CreateEntity(archetype);
  25. entityManager.AddSharedComponentData(cube, look);
  26. }
  27. }
  28.  
  29. public struct CubesGroup
  30. {
  31. public int Length;
  32. public ComponentDataArray<Cube> cubes;
  33. public ComponentDataArray<Position> positions;
  34. public ComponentDataArray<Origin> origins;
  35. }
  36.  
  37. [Inject]
  38. CubesGroup group;
  39.  
  40. protected override void OnUpdate()
  41. {
  42. if(isFirstTime)
  43. {
  44. int spectrumSize = settings.spectrumSize;
  45. for(int index = 0;
  46. index < totalCubeCount;
  47. ++index)
  48. {
  49. int groupIndex = index;
  50. SpiralPos pos = Utils.GetSpiralPos(groupIndex);
  51. Position position = group.positions[groupIndex];
  52. position.Value = new float3(pos.x, 0, pos.z);
  53. group.positions[groupIndex] = position;
  54.  
  55. Origin origin = group.origins[groupIndex];
  56. origin.Value = position.Value;
  57. group.origins[groupIndex] = origin;
  58. }
  59. }
  60.  
  61. isFirstTime = false;
  62. }
  63. }
Add Comment
Please, Sign In to add comment