Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. public int size;
  2. public float speed;
  3.  
  4. private byte[] volume;
  5. private byte[] shifted;
  6.  
  7. public bool widthShift, heightShift, depthShift;
  8.  
  9. private int widthOffset = 0;
  10. private int heightOffset = 0;
  11. private int depthOffset = 0;
  12.  
  13. private float time = 0;
  14. private int cube;
  15.  
  16. void Start()
  17. {
  18. volume = new byte[size * size * size];
  19. shifted = new byte[size * size * size];
  20.  
  21. cube = size * size * size;
  22.  
  23. for (int x = 0; x < size; x++)
  24. for (int y = 0; y < size; y++)
  25. for(int z = 0; z < size; z++)
  26. volume[x + y * size + z * size * size] = (x == 0 || y == 0 || z == 0) ? (byte)1 : (byte)0;
  27. }
  28.  
  29. void Update()
  30. {
  31. time += Time.fixedDeltaTime * speed;
  32.  
  33. if (time > 1)
  34. {
  35. time = 0;
  36.  
  37. widthOffset = (widthOffset >= size) ? 0 : widthOffset;
  38. heightOffset = (heightOffset >= size) ? 0 : heightOffset;
  39. depthOffset = (depthOffset >= size) ? 0 : depthOffset;
  40.  
  41. if (widthShift)
  42. widthOffset++;
  43. else
  44. widthOffset = 0;
  45.  
  46. if (heightShift)
  47. heightOffset++;
  48. else
  49. heightOffset = 0;
  50.  
  51. if (depthShift)
  52. depthOffset++;
  53. else
  54. depthOffset = 0;
  55.  
  56. Shift(widthOffset, heightOffset, depthOffset);
  57. }
  58. }
  59.  
  60. void Shift(int xOff, int yOff, int zOff)
  61. {
  62. for (int x = 0; x < size; x++)
  63. for (int y = 0; y < size; y++)
  64. for(int z = 0; z < size; z++)
  65. {
  66. int i = ((x + xOff) + (y + yOff) * size + (z + zOff) * size * size);
  67. i = (i >= cube) ? (i - cube) : i;
  68.  
  69. shifted[x + y * size + z * size * size] = volume[i];
  70. }
  71. }
  72.  
  73. void OnDrawGizmos()
  74. {
  75. if(Application.isPlaying)
  76. for(int x = 0; x < size; x++)
  77. for(int y = 0; y < size; y++)
  78. for(int z = 0; z < size; z++)
  79. {
  80. Gizmos.color = (shifted[x + y * size + z * size * size] == 1) ? new Color32(0, 255, 0, 255) : new Color32(255, 0, 0, 4);
  81. Gizmos.DrawWireCube(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f), new Vector3(0.95f, 0.95f, 0.95f));
  82. }
  83. }
  84.  
  85. void Shift(int xOff, int yOff, int zOff)
  86. {
  87. for (int x = 0; x < size; x++)
  88. for (int y = 0; y < size; y++)
  89. for(int z = 0; z < size; z++)
  90. {
  91. int nx = (x + xOff) % size;
  92. int ny = (y + yOff) % size;
  93. int nz = (z + zOff) % size;
  94. int i = (nx + ny * size + nz * size * size);
  95.  
  96. shifted[x + y * size + z * size * size] = volume[i];
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement