ArrayExtensionMethods.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright(c) Live2D Inc. All rights reserved.
  3. *
  4. * Use of this source code is governed by the Live2D Open Software license
  5. * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
  6. */
  7. using UnityEngine;
  8. namespace Live2D.Cubism.Rendering
  9. {
  10. /// <summary>
  11. /// Array extension methods.
  12. /// </summary>
  13. public static class ArrayExtensionMethods
  14. {
  15. /// <summary>
  16. /// Combines bounds of multiple <see cref="CubismRenderer"/>s.
  17. /// </summary>
  18. /// <param name="self">Renderers.</param>
  19. /// <returns>Combined bounds.</returns>
  20. public static Bounds GetMeshRendererBounds(this CubismRenderer[] self)
  21. {
  22. var min = self[0].MeshRenderer.bounds.min;
  23. var max = self[0].MeshRenderer.bounds.max;
  24. for (var i = 1; i < self.Length; ++i)
  25. {
  26. var boundsI = self[i].MeshRenderer.bounds;
  27. if (boundsI.min.x < min.x)
  28. {
  29. min.x = boundsI.min.x;
  30. }
  31. if (boundsI.max.x > max.x)
  32. {
  33. max.x = boundsI.max.x;
  34. }
  35. if (boundsI.min.y < min.y)
  36. {
  37. min.y = boundsI.min.y;
  38. }
  39. if (boundsI.max.y > max.y)
  40. {
  41. max.y = boundsI.max.y;
  42. }
  43. }
  44. return new Bounds
  45. {
  46. min = min,
  47. max = max
  48. };
  49. }
  50. }
  51. }