Last active
August 23, 2021 03:11
-
-
Save GeorgiyRyaposov/b4b16898e5b5caf035763da85e5b5fd3 to your computer and use it in GitHub Desktop.
This file contains 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 Vector3 as serializable, we | |
/// need to create our own version. This one will automatically convert | |
/// between Vector3 and SerializableVector3 | |
/// </summary> | |
[System.Serializable] | |
public struct SerializableVector3 | |
{ | |
/// <summary> | |
/// x component | |
/// </summary> | |
public float x; | |
/// <summary> | |
/// y component | |
/// </summary> | |
public float y; | |
/// <summary> | |
/// z component | |
/// </summary> | |
public float z; | |
/// <summary> | |
/// Constructor | |
/// </summary> | |
/// <param name="rX"></param> | |
/// <param name="rY"></param> | |
/// <param name="rZ"></param> | |
public SerializableVector3(float rX, float rY, float rZ) | |
{ | |
x = rX; | |
y = rY; | |
z = rZ; | |
} | |
/// <summary> | |
/// Returns a string representation of the object | |
/// </summary> | |
/// <returns></returns> | |
public override string ToString() | |
{ | |
return String.Format("[{0}, {1}, {2}]", x, y, z); | |
} | |
/// <summary> | |
/// Automatic conversion from SerializableVector3 to Vector3 | |
/// </summary> | |
/// <param name="rValue"></param> | |
/// <returns></returns> | |
public static implicit operator Vector3(SerializableVector3 rValue) | |
{ | |
return new Vector3(rValue.x, rValue.y, rValue.z); | |
} | |
/// <summary> | |
/// Automatic conversion from Vector3 to SerializableVector3 | |
/// </summary> | |
/// <param name="rValue"></param> | |
/// <returns></returns> | |
public static implicit operator SerializableVector3(Vector3 rValue) | |
{ | |
return new SerializableVector3(rValue.x, rValue.y, rValue.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment