Parse.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using UnityEngine;
  3. namespace wf
  4. {
  5. public static class Parse
  6. {
  7. public static Vector2 Vector2(string text)
  8. {
  9. Vector2 zero = UnityEngine.Vector2.zero;
  10. if (string.IsNullOrEmpty(text))
  11. {
  12. return zero;
  13. }
  14. text = text.Trim();
  15. string[] array = text.Substring(1, text.Length - 2).Split(new char[]
  16. {
  17. ','
  18. });
  19. if (array.Length == 2)
  20. {
  21. zero.x = float.Parse(array[0]);
  22. zero.y = float.Parse(array[1]);
  23. }
  24. return zero;
  25. }
  26. public static Vector3 Vector3(string text)
  27. {
  28. Vector3 zero = UnityEngine.Vector3.zero;
  29. if (string.IsNullOrEmpty(text))
  30. {
  31. return zero;
  32. }
  33. text = text.Trim();
  34. string[] array = text.Substring(1, text.Length - 2).Split(new char[]
  35. {
  36. ','
  37. });
  38. if (array.Length == 3)
  39. {
  40. zero.x = float.Parse(array[0]);
  41. zero.y = float.Parse(array[1]);
  42. zero.z = float.Parse(array[2]);
  43. }
  44. return zero;
  45. }
  46. public static Vector4 Vector4(string text)
  47. {
  48. Vector4 zero = UnityEngine.Vector4.zero;
  49. if (string.IsNullOrEmpty(text))
  50. {
  51. return zero;
  52. }
  53. text = text.Trim();
  54. string[] array = text.Substring(1, text.Length - 2).Split(new char[]
  55. {
  56. ','
  57. });
  58. if (array.Length == 4)
  59. {
  60. zero.x = float.Parse(array[0]);
  61. zero.y = float.Parse(array[1]);
  62. zero.z = float.Parse(array[2]);
  63. zero.w = float.Parse(array[3]);
  64. }
  65. return zero;
  66. }
  67. public static Quaternion Quaternion(string text)
  68. {
  69. Quaternion identity = UnityEngine.Quaternion.identity;
  70. if (string.IsNullOrEmpty(text))
  71. {
  72. return identity;
  73. }
  74. text = text.Trim();
  75. string[] array = text.Substring(1, text.Length - 2).Split(new char[]
  76. {
  77. ','
  78. });
  79. if (array.Length == 4)
  80. {
  81. identity = new Quaternion(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
  82. }
  83. return identity;
  84. }
  85. public static Color Color(string text)
  86. {
  87. Color result = default(Color);
  88. if (string.IsNullOrEmpty(text))
  89. {
  90. return result;
  91. }
  92. text = text.Trim().Replace("RGBA", string.Empty);
  93. string[] array = text.Substring(1, text.Length - 2).Split(new char[]
  94. {
  95. ','
  96. });
  97. if (array.Length == 4)
  98. {
  99. result = new Color(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
  100. }
  101. return result;
  102. }
  103. }
  104. }