forked from UnityCommunity/UnityLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector4Serializable.cs
193 lines (157 loc) · 5.66 KB
/
Vector4Serializable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
/// <summary>
/// Representation of four-dimensional vectors.
/// </summary>
namespace UnityLibrary
{
[Serializable]
public struct Vector4Serializable : ISerializable
{
#region Parametres
/// <summary>
/// X component of the vector.
/// </summary>
public float x;
/// <summary>
/// Y component of the vector.
/// </summary>
public float y;
/// <summary>
/// Z component of the vector.
/// </summary>
public float z;
/// <summary>
/// W component of the vector.
/// </summary>
public float w;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="vector">Vector.</param>
public Vector4Serializable(Vector2 vector) : this(vector.x, vector.y)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="vector">Vector.</param>
public Vector4Serializable(Vector3 vector) : this(vector.x, vector.y, vector.z)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="vector">Vector.</param>
public Vector4Serializable(Vector4 vector) : this(vector.x, vector.y, vector.z, vector.w)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
public Vector4Serializable(float x, float y) : this(x, y, 0f)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
public Vector4Serializable(float x, float y, float z) : this(x, y, z, 0f)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Vector4Serializable"/> struct.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
/// <param name="w">The width.</param>
public Vector4Serializable(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
#endregion
#region Methods
public override bool Equals(object obj)
{
if (obj is Vector4Serializable || obj is Vector4)
{
Vector4Serializable vector = (Vector4Serializable)obj;
return this.x == vector.x && this.y == vector.y && this.z == vector.z && this.w == vector.w;
}
return false;
}
public override int GetHashCode()
{
return this.x.GetHashCode() ^ this.y.GetHashCode() << 2 ^ this.z.GetHashCode() >> 2 ^ this.w.GetHashCode() >> 1;
}
public override string ToString()
{
return string.Format("({0}, {1}, {2}, {3})", this.x, this.y, this.z, this.w);
}
#endregion
#region Operators Overload
public static implicit operator Vector4Serializable(Vector2 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector2(Vector4Serializable vector)
{
return new Vector2(vector.x, vector.y);
}
public static implicit operator Vector4Serializable(Vector3 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector3(Vector4Serializable vector)
{
return new Vector3(vector.x, vector.y, vector.z);
}
public static implicit operator Vector4Serializable(Vector4 vector)
{
return new Vector4Serializable(vector);
}
public static implicit operator Vector4(Vector4Serializable vector)
{
return new Vector4(vector.x, vector.y, vector.z, vector.w);
}
public static implicit operator Vector4Serializable(Vector2Serializable vector)
{
return new Vector4Serializable((Vector4)vector);
}
public static implicit operator Vector2Serializable(Vector4Serializable vector)
{
return new Vector2Serializable((Vector4)vector);
}
public static implicit operator Vector4Serializable(Vector3Serializable vector)
{
return new Vector4Serializable((Vector4)vector);
}
public static implicit operator Vector3Serializable(Vector4Serializable vector)
{
return new Vector3Serializable((Vector4)vector);
}
#endregion
#region ISerializable implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("x", this.x, typeof(float));
info.AddValue("y", this.y, typeof(float));
info.AddValue("z", this.w, typeof(float));
info.AddValue("w", this.w, typeof(float));
}
#endregion
}
}