init
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary> Converts from float array to Color during deserialization, and back </summary>
|
||||
[Preserve] public class ColorRGBConverter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Color c = (Color) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(c.r);
|
||||
writer.WriteValue(c.g);
|
||||
writer.WriteValue(c.b);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] a = serializer.Deserialize<float[]>(reader);
|
||||
return new Color(a[0], a[1], a[2]);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Color);
|
||||
}
|
||||
}
|
||||
|
||||
[Preserve] public class ColorRGBAConverter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Color c = (Color) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(c.r);
|
||||
writer.WriteValue(c.g);
|
||||
writer.WriteValue(c.b);
|
||||
writer.WriteValue(c.a);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] a = serializer.Deserialize<float[]>(reader);
|
||||
return new Color(a[0], a[1], a[2], a[3]);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6532df4837460e147922cbb51088800d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary> Converts from string to enum during deserialization, and back </summary>
|
||||
[Preserve] public class EnumConverter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
string value = serializer.Deserialize<string>(reader);
|
||||
if (Enum.IsDefined(objectType, value)) return Enum.Parse(objectType, value);
|
||||
else return existingValue;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return typeof(Enum).IsAssignableFrom(objectType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2d1df10b03ea5f43acd4f34d6150bf9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary> Converts from float array to Matrix4x4 during deserialization, and back </summary>
|
||||
[Preserve] public class Matrix4x4Converter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Matrix4x4 m = (Matrix4x4) value;
|
||||
writer.WriteStartArray();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
writer.WriteValue(m[i]);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] floatArray = serializer.Deserialize<float[]>(reader);
|
||||
return new Matrix4x4(
|
||||
new Vector4(floatArray[0], floatArray[1], floatArray[2], floatArray[3]),
|
||||
new Vector4(floatArray[4], floatArray[5], floatArray[6], floatArray[7]),
|
||||
new Vector4(floatArray[8], floatArray[9], floatArray[10], floatArray[11]),
|
||||
new Vector4(floatArray[12], floatArray[13], floatArray[14], floatArray[15])
|
||||
);;
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Matrix4x4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 948a6430ddecdb3409e998ba6e9a3704
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary>
|
||||
/// Converts from float array to Quaternion during deserialization, and back.
|
||||
/// Compensates for differing coordinate systems as well.
|
||||
/// </summary>
|
||||
[Preserve] public class QuaternionConverter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Quaternion q = (Quaternion) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(q.x);
|
||||
writer.WriteValue(-q.y);
|
||||
writer.WriteValue(-q.z);
|
||||
writer.WriteValue(q.w);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] floatArray = serializer.Deserialize<float[]>(reader);
|
||||
return new Quaternion(floatArray[0], -floatArray[1], -floatArray[2], floatArray[3]);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Quaternion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cbe765fb9857a44696eb441e0e0bb25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary>
|
||||
/// Converts from float array to Vector3 during deserialization, and back.
|
||||
/// Compensates for differing coordinate systems as well.
|
||||
/// </summary>
|
||||
[Preserve] public class TranslationConverter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Vector3 pos = (Vector3) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(-pos.x);
|
||||
writer.WriteValue(pos.y);
|
||||
writer.WriteValue(pos.z);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] floatArray = serializer.Deserialize<float[]>(reader);
|
||||
return new Vector3(-floatArray[0], floatArray[1], floatArray[2]);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Vector3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c0b75c128b76e2488f9284096ada72d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary> Converts from float array to Vector2 during deserialization, and back </summary>
|
||||
[Preserve] public class Vector2Converter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Vector2 pos = (Vector2) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(pos.x);
|
||||
writer.WriteValue(pos.y);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] floatArray = null;
|
||||
try {
|
||||
floatArray = serializer.Deserialize<float[]>(reader);
|
||||
} catch (System.Exception) {
|
||||
floatArray = new float[] { serializer.Deserialize<float>(reader) };
|
||||
}
|
||||
|
||||
switch (floatArray.Length) {
|
||||
case 1:
|
||||
return new Vector2(floatArray[0], floatArray[0]); // just copy float
|
||||
case 2:
|
||||
return new Vector2(floatArray[0], floatArray[1]);
|
||||
case 3:
|
||||
return new Vector2(floatArray[0], floatArray[1]); // we dont need third float
|
||||
default:
|
||||
return new Vector2(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Vector2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3270bccdd3fef254d9cb10fd0fc8bf51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Siccity.GLTFUtility.Converters {
|
||||
/// <summary> Converts from float array to Vector3 during deserialization, and back </summary>
|
||||
[Preserve] public class Vector3Converter : JsonConverter {
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
|
||||
Vector3 pos = (Vector3) value;
|
||||
writer.WriteStartArray();
|
||||
writer.WriteValue(pos.x);
|
||||
writer.WriteValue(pos.y);
|
||||
writer.WriteValue(pos.z);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
float[] floatArray = serializer.Deserialize<float[]>(reader);
|
||||
return new Vector3(floatArray[0], floatArray[1], floatArray[2]);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType) {
|
||||
return objectType == typeof(Vector3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27048007fcb96f94f9c0af0877a49845
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user