forked from UnityCommunity/UnityLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuaternionSerializable.cs
91 lines (72 loc) · 2.01 KB
/
QuaternionSerializable.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
/// <summary>
/// Quaternions are used to represent rotations.
/// </summary>
[Serializable]
public struct QuaternionSerializable : ISerializable
{
#region Parameters
/// <summary>
/// The x component.
/// </summary>
public float x;
/// <summary>
/// The y component.
/// </summary>
public float y;
/// <summary>
/// The z component.
/// </summary>
public float z;
/// <summary>
/// The w component.
/// </summary>
public float w;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="QuaternionSerializable"/> struct.
/// </summary>
/// <param name="quaternion">Quaternion.</param>
public QuaternionSerializable ( Quaternion quaternion ) : this ( quaternion.x, quaternion.y, quaternion.z, quaternion.w )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="QuaternionSerializable"/> 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 QuaternionSerializable ( float x, float y, float z, float w )
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
#endregion
#region Operators Overload
public static implicit operator QuaternionSerializable ( Quaternion quaternion )
{
return new QuaternionSerializable ( quaternion );
}
public static implicit operator Quaternion ( QuaternionSerializable quaternion )
{
return new Quaternion ( quaternion.x, quaternion.y, quaternion.z, quaternion.w );
}
#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.z, typeof ( float ) );
info.AddValue ( "w", this.w, typeof ( float ) );
}
#endregion
}