Skip to content

Instantly share code, notes, and snippets.

@MattDahEpic
Last active February 12, 2024 15:00
Show Gist options
  • Save MattDahEpic/d351a6f4a493a04aecc8a947ef3da405 to your computer and use it in GitHub Desktop.
Save MattDahEpic/d351a6f4a493a04aecc8a947ef3da405 to your computer and use it in GitHub Desktop.
Serializable Vector3 and Quaterions for Unity
using UnityEngine;
using System;
using System.Collections;
[System.Serializable]
public struct SerializableQuaternion {
public float x;
public float y;
public float z;
public float w;
public SerializableQuaternion(float rX, float rY, float rZ, float rW) {
x = rX;
y = rY;
z = rZ;
w = rW;
}
public override string ToString() {
return String.Format("[{0}, {1}, {2}, {3}]", x, y, z, w);
}
public static implicit operator Quaternion(SerializableQuaternion rValue) {
return new Quaternion(rValue.x, rValue.y, rValue.z, rValue.w);
}
public static implicit operator SerializableQuaternion(Quaternion rValue) {
return new SerializableQuaternion(rValue.x, rValue.y, rValue.z, rValue.w);
}
}
using UnityEngine;
using System;
using System.Collections;
[System.Serializable]
public struct SerializableVector3 {
public float x;
public float y;
public float z;
public SerializableVector3(float rX, float rY, float rZ) {
x = rX;
y = rY;
z = rZ;
}
public override string ToString() {
return String.Format("[{0}, {1}, {2}]", x, y, z);
}
public static implicit operator Vector3(SerializableVector3 rValue) {
return new Vector3(rValue.x, rValue.y, rValue.z);
}
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