Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HighLevelLoadManager.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class HighLevelLoadManager : MonoBehaviour
  5. {
  6. [Tooltip("How many islands in percent(%) to enable spinning at the start of the test")]
  7. [Range(0, 100)]
  8. public float startingLoadAmount = 100;
  9. [Tooltip("Rows and cols for the grid")]
  10. public Vector3 islandGrid;
  11. private float spawnAmount = 0;
  12. public GameObject prefab;
  13. public Transform floatingRocksParent;
  14. public void SetLoad(float loadAmount)
  15. {
  16. startingLoadAmount = loadAmount;
  17. int childCount = floatingRocksParent.childCount;
  18. for (int i = 0; i < childCount; i++)
  19. {
  20. Destroy(floatingRocksParent.GetChild(i).gameObject);
  21. }
  22. spawnAmount = islandGrid.x * islandGrid.y * islandGrid.z;
  23. spawnAmount = spawnAmount / 100.0f * loadAmount;
  24. var meshRenderer = prefab.GetComponentsInChildren<MeshRenderer>()[0];
  25. var bounds = meshRenderer.bounds.size + Vector3.one;
  26. var minX = bounds.x / 2 * islandGrid.x;
  27. var minZ = bounds.z / 2 * islandGrid.z;
  28. for (var layer = 1; layer <= islandGrid.z; layer++)
  29. {
  30. for (var row = 1; row <= islandGrid.y; row++)
  31. {
  32. for (var col = 1; col <= islandGrid.x; col++)
  33. {
  34. var objectPos = new Vector3((col - 1) * bounds.x, (layer - 1) * bounds.y, (row - 1) * bounds.z);
  35. objectPos.x -= minX;
  36. objectPos.z -= minZ;
  37. if (spawnAmount > 0)
  38. {
  39. Instantiate(prefab, objectPos, Quaternion.identity, floatingRocksParent);
  40. spawnAmount--;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }