MegaCacheUtils.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System;
  4. [System.Serializable]
  5. public enum MegaCacheAxis
  6. {
  7. X,
  8. Y,
  9. Z,
  10. }
  11. public class MegaCacheUtils
  12. {
  13. static public Bounds GetBounds(Vector3[] vals)
  14. {
  15. Bounds b = new Bounds(Vector3.zero, Vector3.zero);
  16. if ( vals != null && vals.Length > 0 )
  17. {
  18. b.Encapsulate(vals[0]);
  19. for ( int i = 1; i < vals.Length; i++ )
  20. b.Encapsulate(vals[i]);
  21. }
  22. return b;
  23. }
  24. static public Bounds GetBounds(Vector2[] vals)
  25. {
  26. Bounds b = new Bounds(Vector3.zero, Vector3.zero);
  27. if ( vals != null && vals.Length > 0 )
  28. {
  29. Vector2 p = Vector2.zero;
  30. p = vals[0];
  31. b.Encapsulate(p);
  32. for ( int i = 1; i < vals.Length; i++ )
  33. {
  34. p = vals[i];
  35. b.Encapsulate(p);
  36. }
  37. }
  38. return b;
  39. }
  40. static public Bounds GetBounds(List<Vector3> vals)
  41. {
  42. Bounds b = new Bounds(Vector3.zero, Vector3.zero);
  43. if ( vals != null && vals.Count > 0 )
  44. {
  45. b.Encapsulate(vals[0]);
  46. for ( int i = 1; i < vals.Count; i++ )
  47. b.Encapsulate(vals[i]);
  48. }
  49. return b;
  50. }
  51. static public Bounds GetBounds(List<float> vals)
  52. {
  53. Bounds b = new Bounds(Vector3.zero, Vector3.zero);
  54. if ( vals != null && vals.Count > 0 )
  55. {
  56. Vector3 p = Vector3.zero;
  57. p.x = vals[0];
  58. b.Encapsulate(p);
  59. for ( int i = 1; i < vals.Count; i++ )
  60. {
  61. p.x = vals[i];
  62. b.Encapsulate(p);
  63. }
  64. }
  65. return b;
  66. }
  67. static public string MakeFileName(string file, ref int format)
  68. {
  69. //Debug.Log("filein " + file);
  70. string ret = "";
  71. format = 0;
  72. for ( int i = file.Length - 1; i >= 0; i-- )
  73. {
  74. char c = file[i];
  75. if ( Char.IsNumber(c) )
  76. {
  77. format++;
  78. }
  79. else
  80. {
  81. ret = file.Substring(0, i + 1);
  82. Debug.Log("ret " + ret + " format " + format);
  83. break;
  84. }
  85. }
  86. return ret;
  87. }
  88. }