summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Common
diff options
context:
space:
mode:
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Common')
-rw-r--r--WorldlineKeepers/Assets/Scripts/Common/Common.cs348
-rw-r--r--WorldlineKeepers/Assets/Scripts/Common/Common.cs.meta12
-rw-r--r--WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs317
-rw-r--r--WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs.meta12
4 files changed, 689 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Common/Common.cs b/WorldlineKeepers/Assets/Scripts/Common/Common.cs
new file mode 100644
index 0000000..13a9f58
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Common/Common.cs
@@ -0,0 +1,348 @@
+/////////////////////////////////////////////////////////////////////////////////
+//
+// author: hanjun
+// date: 2018/12/03 16:31:57
+// desc: 某类
+//
+//
+//
+//
+//
+/////////////////////////////////////////////////////////////////////////////////
+
+using UnityEngine;
+using System.Collections;
+
+namespace DNA
+{
+ [System.Serializable]
+ public struct IntVector2
+ {
+ public int x;
+ public int y;
+
+ public IntVector2(int x, int y)
+ {
+ this.x = x;
+ this.y = y;
+ }
+
+ static IntVector2 mZero = new IntVector2(0, 0);
+ static IntVector2 mOne = new IntVector2(1, 1);
+ public static IntVector2 Zero
+ {
+ get
+ {
+ return mZero;
+ }
+ }
+
+ public static IntVector2 One
+ {
+ get
+ {
+ return mOne;
+ }
+ }
+ public int ConstCount
+ {
+ get
+ {
+ return 2;
+ }
+ }
+ public int this[int index]
+ {
+ get
+ {
+ switch (index)
+ {
+ case 0:
+ return x;
+ case 1:
+ return y;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector2索引越界");
+ }
+ }
+ set
+ {
+ switch (index)
+ {
+ case 0:
+ x = value;
+ break;
+ case 1:
+ y = value;
+ break;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector2索引越界");
+ }
+ }
+ }
+ public static implicit operator Vector2(IntVector2 v)
+ {
+ return new Vector2(v.x, v.y);
+ }
+ public static IntVector2 operator *(int d, IntVector2 a)
+ {
+ a.x *= d;
+ a.y *= d;
+ return a;
+ }
+ public static bool operator ==(IntVector2 lhs, IntVector2 rhs)
+ {
+ return (lhs.x == rhs.x && lhs.y == rhs.y);
+ }
+
+ public static bool operator !=(IntVector2 lhs, IntVector2 rhs)
+ {
+ return (lhs.x != rhs.x || lhs.y != rhs.y);
+ }
+ public override string ToString()
+ {
+ return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString());
+ }
+ public override bool Equals(object obj)
+ {
+ if (obj is IntVector2)
+ {
+ IntVector2 other = (IntVector2)obj;
+ return other.x == x && other.y == y;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+ }
+
+ public struct IntVector3
+ {
+ public int x;
+ public int y;
+ public int z;
+
+ public IntVector3(int x, int y, int z)
+ {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ }
+
+ static IntVector3 mZero = new IntVector3(0, 0, 0);
+ public static IntVector3 Zero
+ {
+ get
+ {
+ return mZero;
+ }
+ }
+ public int ConstCount
+ {
+ get
+ {
+ return 3;
+ }
+ }
+ public int this[int index]
+ {
+ get
+ {
+ switch (index)
+ {
+ case 0:
+ return x;
+ case 1:
+ return y;
+ case 2:
+ return z;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector3索引越界");
+ }
+ }
+ set
+ {
+ switch (index)
+ {
+ case 0:
+ x = value;
+ break;
+ case 1:
+ y = value;
+ break;
+ case 2:
+ z = value;
+ break;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector3索引越界");
+ }
+ }
+ }
+ public static implicit operator Vector3(IntVector3 v)
+ {
+ return new Vector3(v.x, v.y, v.z);
+ }
+ public static IntVector3 operator *(int d, IntVector3 a)
+ {
+ a.x *= d;
+ a.y *= d;
+ a.z *= d;
+ return a;
+ }
+ public static bool operator ==(IntVector3 lhs, IntVector3 rhs)
+ {
+ return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
+ }
+ public static bool operator !=(IntVector3 lhs, IntVector3 rhs)
+ {
+ return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z);
+ }
+ public override string ToString()
+ {
+ return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString(), ",", z.ToTempString());
+ }
+ public override bool Equals(object obj)
+ {
+ if (obj is IntVector3)
+ {
+ IntVector3 other = (IntVector3)obj;
+ return other.x == x && other.y == y && other.z == z;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public bool Contains(int a)
+ {
+ if (x == a || y == a || z == a)
+ return true;
+ return false;
+ }
+ }
+
+ public struct IntVector4
+ {
+ public int x;
+ public int y;
+ public int z;
+ public int w;
+
+ public IntVector4(int x, int y, int z, int w)
+ {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.w = w;
+ }
+
+ static IntVector4 mZero = new IntVector4(0, 0, 0, 0);
+ public static IntVector4 Zero
+ {
+ get
+ {
+ return mZero;
+ }
+ }
+ public static int ConstCount
+ {
+ get
+ {
+ return 4;
+ }
+ }
+ public int this[int index]
+ {
+ get
+ {
+ switch (index)
+ {
+ case 0:
+ return x;
+ case 1:
+ return y;
+ case 2:
+ return z;
+ case 3:
+ return w;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector4索引越界");
+ }
+ }
+ set
+ {
+ switch (index)
+ {
+ case 0:
+ x = value;
+ break;
+ case 1:
+ y = value;
+ break;
+ case 2:
+ z = value;
+ break;
+ case 3:
+ w = value;
+ break;
+ default:
+ throw new System.ArgumentOutOfRangeException("IntVector4索引越界");
+ }
+ }
+ }
+ public static implicit operator Vector4(IntVector4 v)
+ {
+ return new Vector4(v.x, v.y, v.z, v.w);
+ }
+ public static IntVector4 operator *(int d, IntVector4 a)
+ {
+ a.x *= d;
+ a.y *= d;
+ a.z *= d;
+ a.w *= d;
+ return a;
+ }
+ public static bool operator ==(IntVector4 lhs, IntVector4 rhs)
+ {
+ return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w);
+ }
+ public static bool operator !=(IntVector4 lhs, IntVector4 rhs)
+ {
+ return (lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z || lhs.w != rhs.w);
+ }
+
+ public override string ToString()
+ {
+ return StringUtil.Concat(x.ToTempString(), ",", y.ToTempString(), ",", z.ToTempString(), ",", w.ToTempString());
+ }
+ public override bool Equals(object obj)
+ {
+ if (obj is IntVector4)
+ {
+ IntVector4 other = (IntVector4)obj;
+ return other.x == x && other.y == y && other.z == z && other.w == w;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+ }
+} \ No newline at end of file
diff --git a/WorldlineKeepers/Assets/Scripts/Common/Common.cs.meta b/WorldlineKeepers/Assets/Scripts/Common/Common.cs.meta
new file mode 100644
index 0000000..e738e0b
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Common/Common.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c2cff652623bdff42acbdbfe57c4b998
+timeCreated: 1543825917
+licenseType: Pro
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs b/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs
new file mode 100644
index 0000000..6d06eff
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs
@@ -0,0 +1,317 @@
+/////////////////////////////////////////////////////////////////////////////////
+//
+// author: hanjun
+// date: 2018/12/03 16:33:35
+// desc: 某类
+//
+//
+//
+//
+//
+/////////////////////////////////////////////////////////////////////////////////
+
+using UnityEngine;
+using System.Collections;
+using System;
+using LitJson;
+
+namespace DNA
+{
+ public class CommonParse
+ {
+ public static float ParseFloat(string str)
+ {
+ float target = 0f;
+ ParseFloat(ref target, str, 0f);
+ return target;
+ }
+ public static void ParseFloat(ref float target, string str)
+ {
+ ParseFloat(ref target, str, 0f);
+ }
+ public static void ParseFloat(ref float target, string str, float defaultValue)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ target = defaultValue;
+ return;
+ }
+ str = str.Replace("(", "");
+ str = str.Replace(")", "");
+ float result = defaultValue;//使用默认值
+ if (float.TryParse(str, out result))
+ {
+ target = result;
+ }
+ else
+ {
+ LogHelper.LogEditorError("ParseFloat Error at field : " + str);
+ target = defaultValue;
+ }
+ }
+ public static int ParseInt(string str)
+ {
+ int target = 0;
+ ParseInt(ref target, str, 0);
+ return target;
+ }
+ public static void ParseInt(ref int target, string str)
+ {
+ ParseInt(ref target, str, 0);
+ }
+ public static void ParseInt(ref int target, string str, int defaultValue)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ target = defaultValue;
+ return;
+ }
+
+ int result = defaultValue;//使用默认值
+ if (int.TryParse(str, out result))
+ {
+ target = result;
+ }
+ else
+ {
+ if (str.Contains("0x"))
+ {
+ target = Convert.ToInt32(str, 16);
+ }
+ else
+ {
+ LogHelper.LogEditorError("ParseInt Error at field : " + str);
+ target = defaultValue;
+ }
+ }
+ }
+ public static byte ParseByte(string str)
+ {
+ byte target = 0;
+ ParseByte(ref target, str, 0);
+ return target;
+ }
+ public static void ParseByte(ref byte target, string str)
+ {
+ ParseByte(ref target, str, 0);
+ }
+ public static void ParseByte(ref byte target, string str, byte defaultValue)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ target = defaultValue;
+ return;
+ }
+
+ byte result = defaultValue;//使用默认值
+ if (byte.TryParse(str, out result))
+ {
+ target = result;
+ }
+ else
+ {
+ if (str.Contains("0x"))
+ {
+ target = Convert.ToByte(str, 16);
+ }
+ else
+ {
+ LogHelper.LogEditorError("ParseByte Error at field : " + str);
+ target = defaultValue;
+ }
+ }
+ }
+
+ public static void ParseVector2(ref Vector2 v2, string str)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ v2 = Vector2.zero;
+ return;
+ }
+
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseFloat(ref v2.x, array[0]);
+ if (array.Length >= 2)
+ ParseFloat(ref v2.y, array[1]);
+
+ //if (array.Length == 2)
+ //{
+ // ParseFloat(ref v2.x, array[0]);
+ // ParseFloat(ref v2.y, array[1]);
+ //}
+ //else
+ //{
+ // LogHelper.LogError("解析ParseVector2失败," + str);
+ //}
+ }
+ public static void ParseVector3(ref Vector3 v3, string str)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ v3 = Vector3.zero;
+ return;
+ }
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseFloat(ref v3.x, array[0]);
+ if (array.Length >= 2)
+ ParseFloat(ref v3.y, array[1]);
+ if (array.Length >= 3)
+ ParseFloat(ref v3.z, array[2]);
+
+ //if (array.Length == 3)
+ //{
+ // ParseFloat(ref v3.x, array[0]);
+ // ParseFloat(ref v3.y, array[1]);
+ // ParseFloat(ref v3.z, array[2]);
+ //}
+ //else
+ //{
+ // LogHelper.LogError("解析ParseVector3失败," + str);
+ //}
+ }
+ public static void ParseVector4(ref Vector4 v4, string str)
+ {
+ if (string.IsNullOrEmpty(str))
+ {
+ v4 = Vector4.zero;
+ return;
+ }
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseFloat(ref v4.x, array[0]);
+ if (array.Length >= 2)
+ ParseFloat(ref v4.y, array[1]);
+ if (array.Length >= 3)
+ ParseFloat(ref v4.z, array[2]);
+ if (array.Length >= 4)
+ ParseFloat(ref v4.w, array[3]);
+
+ //if (array.Length == 4)
+ //{
+ // ParseFloat(ref v4.x, array[0]);
+ // ParseFloat(ref v4.y, array[1]);
+ // ParseFloat(ref v4.z, array[2]);
+ // ParseFloat(ref v4.w, array[3]);
+ //}
+ //else
+ //{
+ // LogHelper.LogError("解析ParseVector4失败," + str);
+ //}
+ }
+
+ #region Json序列化
+ public static Vector3 ParseVector4(string str)
+ {
+ Vector4 v = Vector4.zero;
+ ParseVector4(ref v, str);
+ return v;
+ }
+
+ public static Vector3 ParseVector3(string str)
+ {
+ Vector3 v = Vector3.zero;
+ ParseVector3(ref v, str);
+ return v;
+ }
+
+ public static Vector2 ParseVector2(string str)
+ {
+ Vector2 v = Vector2.zero;
+ ParseVector2(ref v, str);
+ return v;
+ }
+
+ public static IntVector2 ParseIntVector2(string str)
+ {
+ IntVector2 iv2 = IntVector2.Zero;
+ if (string.IsNullOrEmpty(str))
+ {
+ return iv2;
+ }
+
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseInt(ref iv2.x, array[0]);
+ if (array.Length >= 2)
+ ParseInt(ref iv2.y, array[1]);
+
+ return iv2;
+ }
+
+ public static IntVector3 ParseIntVector3(string str)
+ {
+ IntVector3 iv3 = IntVector3.Zero;
+ if (string.IsNullOrEmpty(str))
+ {
+ return iv3;
+ }
+
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseInt(ref iv3.x, array[0]);
+ if (array.Length >= 2)
+ ParseInt(ref iv3.y, array[1]);
+ if (array.Length >= 3)
+ ParseInt(ref iv3.z, array[2]);
+
+ return iv3;
+ }
+
+ public static IntVector4 ParseIntVector4(string str)
+ {
+ IntVector4 iv4 = IntVector4.Zero;
+ if (string.IsNullOrEmpty(str))
+ {
+ return iv4;
+ }
+
+ string[] array = str.Split(',', ';', '=');
+ if (array.Length >= 1)
+ ParseInt(ref iv4.x, array[0]);
+ if (array.Length >= 2)
+ ParseInt(ref iv4.y, array[1]);
+ if (array.Length >= 3)
+ ParseInt(ref iv4.z, array[2]);
+ if (array.Length >= 4)
+ ParseInt(ref iv4.w, array[3]);
+ return iv4;
+ }
+
+ public static Color ParseColor(string str)
+ {
+ Color col = Color.white;
+ string[] array = str.Split(',', ';', '=');
+ int i = array.Length;
+ if (i > 0) col.r = ParseFloat(array[0]);
+ if (i > 1) col.g = ParseFloat(array[1]);
+ if (i > 2) col.b = ParseFloat(array[2]);
+ if (i > 3) col.a = ParseFloat(array[3]);
+ return col;
+ }
+
+ public static Color32 ParseColor32(string str)
+ {
+ Color32 col = new Color32(255,255,255,255);
+ string[] array = str.Split(',', ';', '=');
+ int i = array.Length;
+ if (i > 0) col.r = ParseByte(array[0]);
+ if (i > 1) col.g = ParseByte(array[1]);
+ if (i > 2) col.b = ParseByte(array[2]);
+ if (i > 3) col.a = ParseByte(array[3]);
+ return col;
+ }
+ #endregion
+
+ public static string ToJsonByFormat(System.Object obj)
+ {
+ System.Text.StringBuilder sb = new System.Text.StringBuilder();
+ JsonWriter jw = new JsonWriter(sb);
+ jw.PrettyPrint = true;
+ JsonMapper.ToJson(obj, jw);
+ return sb.ToString();
+ }
+ }
+} \ No newline at end of file
diff --git a/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs.meta b/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs.meta
new file mode 100644
index 0000000..0573243
--- /dev/null
+++ b/WorldlineKeepers/Assets/Scripts/Common/CommonParse.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d52e289ce1c1b5d4c836a2f671dca346
+timeCreated: 1543826015
+licenseType: Pro
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: