summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Common/Common.cs
diff options
context:
space:
mode:
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Common/Common.cs')
-rw-r--r--WorldlineKeepers/Assets/Scripts/Common/Common.cs348
1 files changed, 348 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