using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization; using UnityEngine; /// /// Quaternions are used to represent rotations. /// [Serializable] public struct QuaternionSerializable : ISerializable { #region Parameters /// /// The x component. /// public float x; /// /// The y component. /// public float y; /// /// The z component. /// public float z; /// /// The w component. /// public float w; #endregion #region Constructors /// /// Initializes a new instance of the struct. /// /// Quaternion. public QuaternionSerializable ( Quaternion quaternion ) : this ( quaternion.x, quaternion.y, quaternion.z, quaternion.w ) { } /// /// Initializes a new instance of the struct. /// /// The x coordinate. /// The y coordinate. /// The z coordinate. /// The width. 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 }