123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using UnityEngine;
- namespace wf
- {
- public static class Parse
- {
- public static Vector2 Vector2(string text)
- {
- Vector2 zero = UnityEngine.Vector2.zero;
- if (string.IsNullOrEmpty(text))
- {
- return zero;
- }
- text = text.Trim();
- string[] array = text.Substring(1, text.Length - 2).Split(new char[]
- {
- ','
- });
- if (array.Length == 2)
- {
- zero.x = float.Parse(array[0]);
- zero.y = float.Parse(array[1]);
- }
- return zero;
- }
- public static Vector3 Vector3(string text)
- {
- Vector3 zero = UnityEngine.Vector3.zero;
- if (string.IsNullOrEmpty(text))
- {
- return zero;
- }
- text = text.Trim();
- string[] array = text.Substring(1, text.Length - 2).Split(new char[]
- {
- ','
- });
- if (array.Length == 3)
- {
- zero.x = float.Parse(array[0]);
- zero.y = float.Parse(array[1]);
- zero.z = float.Parse(array[2]);
- }
- return zero;
- }
- public static Vector4 Vector4(string text)
- {
- Vector4 zero = UnityEngine.Vector4.zero;
- if (string.IsNullOrEmpty(text))
- {
- return zero;
- }
- text = text.Trim();
- string[] array = text.Substring(1, text.Length - 2).Split(new char[]
- {
- ','
- });
- if (array.Length == 4)
- {
- zero.x = float.Parse(array[0]);
- zero.y = float.Parse(array[1]);
- zero.z = float.Parse(array[2]);
- zero.w = float.Parse(array[3]);
- }
- return zero;
- }
- public static Quaternion Quaternion(string text)
- {
- Quaternion identity = UnityEngine.Quaternion.identity;
- if (string.IsNullOrEmpty(text))
- {
- return identity;
- }
- text = text.Trim();
- string[] array = text.Substring(1, text.Length - 2).Split(new char[]
- {
- ','
- });
- if (array.Length == 4)
- {
- identity = new Quaternion(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
- }
- return identity;
- }
- public static Color Color(string text)
- {
- Color result = default(Color);
- if (string.IsNullOrEmpty(text))
- {
- return result;
- }
- text = text.Trim().Replace("RGBA", string.Empty);
- string[] array = text.Substring(1, text.Length - 2).Split(new char[]
- {
- ','
- });
- if (array.Length == 4)
- {
- result = new Color(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
- }
- return result;
- }
- }
- }
|