ProceduralMeshResources.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. namespace O3DWB
  5. {
  6. public class ProceduralMeshResources
  7. {
  8. #region Private Variables
  9. private List<Mesh> _meshes = new List<Mesh>();
  10. #endregion
  11. #region Public Methods
  12. public Mesh CreateXYRectangleMesh(float width, float height, Color color)
  13. {
  14. Mesh mesh = ProceduralMeshGeneration.CreateXYRectangleMesh(width, height, color);
  15. if (mesh != null) _meshes.Add(mesh);
  16. return mesh;
  17. }
  18. public Mesh CreateXZRectangleMesh(float width, float depth, Color color)
  19. {
  20. Mesh mesh = ProceduralMeshGeneration.CreateXZRectangleMesh(width, depth, color);
  21. if (mesh != null) _meshes.Add(mesh);
  22. return mesh;
  23. }
  24. public Mesh CreateXYCircleMesh(float radius, int numberOfSlices, Color color)
  25. {
  26. Mesh mesh = ProceduralMeshGeneration.CreateXYCircleMesh(radius, numberOfSlices, color);
  27. if (mesh != null) _meshes.Add(mesh);
  28. return mesh;
  29. }
  30. public void DisposeMeshes()
  31. {
  32. foreach(Mesh mesh in _meshes)
  33. {
  34. if (mesh != null) Octave3DWorldBuilder.DestroyImmediate(mesh);
  35. }
  36. _meshes.Clear();
  37. }
  38. public void DisposeMesh(Mesh mesh)
  39. {
  40. int meshIndex = _meshes.FindIndex(item => item == mesh);
  41. if (meshIndex >= 0)
  42. {
  43. Octave3DWorldBuilder.DestroyImmediate(_meshes[meshIndex]);
  44. _meshes.RemoveAt(meshIndex);
  45. }
  46. }
  47. #endregion
  48. }
  49. }
  50. #endif