Created
May 3, 2017 01:13
-
-
Save GeorgiyRyaposov/7100cb742df1b5b30cdf7e94bc555a3f to your computer and use it in GitHub Desktop.
SerializableQuaternion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System; | |
using System.Collections; | |
/// <summary> | |
/// Since unity doesn't flag the Quaternion as serializable, we | |
/// need to create our own version. This one will automatically convert | |
/// between Quaternion and SerializableQuaternion | |
/// </summary> | |
[System.Serializable] | |
public struct SerializableQuaternion | |
{ | |
/// <summary> | |
/// x component | |
/// </summary> | |
public float x; | |
/// <summary> | |
/// y component | |
/// </summary> | |
public float y; | |
/// <summary> | |
/// z component | |
/// </summary> | |
public float z; | |
/// <summary> | |
/// w component | |
/// </summary> | |
public float w; | |
/// <summary> | |
/// Constructor | |
/// </summary> | |
/// <param name="rX"></param> | |
/// <param name="rY"></param> | |
/// <param name="rZ"></param> | |
/// <param name="rW"></param> | |
public SerializableQuaternion(float rX, float rY, float rZ, float rW) | |
{ | |
x = rX; | |
y = rY; | |
z = rZ; | |
w = rW; | |
} | |
/// <summary> | |
/// Returns a string representation of the object | |
/// </summary> | |
/// <returns></returns> | |
public override string ToString() | |
{ | |
return String.Format("[{0}, {1}, {2}, {3}]", x, y, z, w); | |
} | |
/// <summary> | |
/// Automatic conversion from SerializableQuaternion to Quaternion | |
/// </summary> | |
/// <param name="rValue"></param> | |
/// <returns></returns> | |
public static implicit operator Quaternion(SerializableQuaternion rValue) | |
{ | |
return new Quaternion(rValue.x, rValue.y, rValue.z, rValue.w); | |
} | |
/// <summary> | |
/// Automatic conversion from Quaternion to SerializableQuaternion | |
/// </summary> | |
/// <param name="rValue"></param> | |
/// <returns></returns> | |
public static implicit operator SerializableQuaternion(Quaternion rValue) | |
{ | |
return new SerializableQuaternion(rValue.x, rValue.y, rValue.z, rValue.w); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment