mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-23 19:36:18 -05:00
fix AOT
This commit is contained in:
parent
18d0913af9
commit
8c5558d9a6
|
|
@ -1,4 +1,4 @@
|
|||
#pragma warning disable 0649
|
||||
#pragma warning disable 0649
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
|
@ -150,6 +150,11 @@ namespace UniJSON
|
|||
{
|
||||
public Dictionary<string, object> Dict = new Dictionary<string, object>();
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var rhs = obj as DictionaryValue;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,15 @@ namespace UniJSON
|
|||
f.Value(new ArraySegment<Byte>(bytes));
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, UnityEngine.Vector2 v)
|
||||
{
|
||||
//CommaCheck();
|
||||
f.BeginMap(2);
|
||||
f.Key("x"); f.Value(v.x);
|
||||
f.Key("y"); f.Value(v.y);
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, UnityEngine.Vector3 v)
|
||||
{
|
||||
//CommaCheck();
|
||||
|
|
@ -39,6 +48,17 @@ namespace UniJSON
|
|||
f.EndMap();
|
||||
}
|
||||
|
||||
public static void Value(this IFormatter f, UnityEngine.Vector4 v)
|
||||
{
|
||||
//CommaCheck();
|
||||
f.BeginMap(4);
|
||||
f.Key("x"); f.Value(v.x);
|
||||
f.Key("y"); f.Value(v.y);
|
||||
f.Key("z"); f.Value(v.z);
|
||||
f.Key("w"); f.Value(v.w);
|
||||
f.EndMap();
|
||||
}
|
||||
|
||||
static MethodInfo GetMethod<T>(Expression<Func<T>> expression)
|
||||
{
|
||||
var method = typeof(FormatterExtensions).GetMethod("Serialize");
|
||||
|
|
|
|||
|
|
@ -78,8 +78,10 @@ namespace UniJSON
|
|||
{
|
||||
delegate void Serializer(IFormatter f, T t);
|
||||
|
||||
static Action<IFormatter, T> GetSerializer(Type t)
|
||||
static Action<IFormatter, T> GetSerializer()
|
||||
{
|
||||
var t = typeof(T);
|
||||
|
||||
// object
|
||||
if (typeof(T) == typeof(object) && t.GetType() != typeof(object))
|
||||
{
|
||||
|
|
@ -166,7 +168,7 @@ namespace UniJSON
|
|||
{
|
||||
if (s_serializer == null)
|
||||
{
|
||||
s_serializer = new Serializer(GetSerializer(typeof(T)));
|
||||
s_serializer = new Serializer(GetSerializer());
|
||||
}
|
||||
s_serializer(f, t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
|
@ -9,7 +9,7 @@ namespace UniJSON
|
|||
public static class GenericDeserializer<T, U>
|
||||
where T : IListTreeItem, IValue<T>
|
||||
{
|
||||
static V[] GenericArrayDeserializer<V>(ListTreeNode<T> s)
|
||||
public static V[] GenericArrayDeserializer<V>(ListTreeNode<T> s)
|
||||
{
|
||||
if (!s.IsArray())
|
||||
{
|
||||
|
|
@ -24,7 +24,7 @@ namespace UniJSON
|
|||
return u;
|
||||
}
|
||||
|
||||
static List<V> GenericListDeserializer<V>(ListTreeNode<T> s)
|
||||
public static List<V> GenericListDeserializer<V>(ListTreeNode<T> s)
|
||||
{
|
||||
if (!s.IsArray())
|
||||
{
|
||||
|
|
@ -40,7 +40,7 @@ namespace UniJSON
|
|||
return u;
|
||||
}
|
||||
|
||||
static object DefaultDictionaryDeserializer(ListTreeNode<T> s)
|
||||
public static object DefaultDictionaryDeserializer(ListTreeNode<T> s)
|
||||
{
|
||||
switch (s.Value.ValueType)
|
||||
{
|
||||
|
|
@ -82,7 +82,7 @@ namespace UniJSON
|
|||
/// <typeparam name="V"></typeparam>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
static Dictionary<string, V> DictionaryDeserializer<V>(ListTreeNode<T> s)
|
||||
public static Dictionary<string, V> DictionaryDeserializer<V>(ListTreeNode<T> s)
|
||||
{
|
||||
var d = new Dictionary<string, V>();
|
||||
foreach (var kv in s.ObjectItems())
|
||||
|
|
@ -146,7 +146,7 @@ namespace UniJSON
|
|||
if (target.IsArray)
|
||||
{
|
||||
var mi = typeof(GenericDeserializer<T, U>).GetMethod("GenericArrayDeserializer",
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
BindingFlags.Static | BindingFlags.Public);
|
||||
var g = mi.MakeGenericMethod(target.GetElementType());
|
||||
return GenericInvokeCallFactory.StaticFunc<ListTreeNode<T>, U>(g);
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ namespace UniJSON
|
|||
if (target.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
var mi = typeof(GenericDeserializer<T, U>).GetMethod("GenericListDeserializer",
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
BindingFlags.Static | BindingFlags.Public);
|
||||
var g = mi.MakeGenericMethod(target.GetGenericArguments());
|
||||
return GenericInvokeCallFactory.StaticFunc<ListTreeNode<T>, U>(g);
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ namespace UniJSON
|
|||
{
|
||||
|
||||
var mi = typeof(GenericDeserializer<T, U>).GetMethod("DefaultDictionaryDeserializer",
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
BindingFlags.Static | BindingFlags.Public);
|
||||
return GenericInvokeCallFactory.StaticFunc<ListTreeNode<T>, U>(mi);
|
||||
}
|
||||
else
|
||||
|
|
@ -173,7 +173,7 @@ namespace UniJSON
|
|||
target.GetGenericArguments()[0] == typeof(string))
|
||||
{
|
||||
var mi = typeof(GenericDeserializer<T, U>).GetMethod("DictionaryDeserializer",
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
BindingFlags.Static | BindingFlags.Public);
|
||||
var g = mi.MakeGenericMethod(target.GetGenericArguments()[1]);
|
||||
return GenericInvokeCallFactory.StaticFunc<ListTreeNode<T>, U>(g);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,5 +286,22 @@ namespace UniJSON
|
|||
{
|
||||
return new JsonDictionaryValidator<T>();
|
||||
}
|
||||
|
||||
#region AOT
|
||||
public static JsonDictionaryValidator<Single> CreateSingle()
|
||||
{
|
||||
return Create<Single>();
|
||||
}
|
||||
|
||||
public static JsonDictionaryValidator<Int32> CreateInt32()
|
||||
{
|
||||
return Create<Int32>();
|
||||
}
|
||||
|
||||
public static JsonDictionaryValidator<Boolean> CreateBoolean()
|
||||
{
|
||||
return Create<Boolean>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
|
@ -592,7 +592,7 @@ namespace UniJSON
|
|||
GenericSerializer<T>.Serialize(this, f, c, value);
|
||||
}
|
||||
|
||||
static class GenericDeserializer<S, T>
|
||||
public static class GenericDeserializer<S, T>
|
||||
where S : IListTreeItem, IValue<S>
|
||||
{
|
||||
delegate T Deserializer(ListTreeNode<S> src);
|
||||
|
|
@ -610,7 +610,7 @@ namespace UniJSON
|
|||
};
|
||||
}
|
||||
|
||||
static U DeserializeField<U>(JsonSchema prop, ListTreeNode<S> s)
|
||||
public static U DeserializeField<U>(JsonSchema prop, ListTreeNode<S> s)
|
||||
{
|
||||
var u = default(U);
|
||||
prop.Validator.Deserialize(s, ref u);
|
||||
|
|
@ -639,7 +639,7 @@ namespace UniJSON
|
|||
}
|
||||
|
||||
var mi = typeof(GenericDeserializer<S, T>).GetMethod("DeserializeField",
|
||||
BindingFlags.Static | BindingFlags.NonPublic);
|
||||
BindingFlags.Static | BindingFlags.Public);
|
||||
var g = mi.MakeGenericMethod(x.FieldType);
|
||||
|
||||
return (FieldSetter)((s, o) =>
|
||||
|
|
|
|||
311
Assets/VRM/UniVRM/Editor/Format/VRMAOTMenu.cs
Normal file
311
Assets/VRM/UniVRM/Editor/Format/VRMAOTMenu.cs
Normal file
|
|
@ -0,0 +1,311 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UniGLTF;
|
||||
using UniJSON;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public static class VRMAOTMenu
|
||||
{
|
||||
/// <summary>
|
||||
/// AOT向けにダミーのGenerics呼び出しを作成する
|
||||
/// </summary>
|
||||
#if VRM_DEVELOP
|
||||
[MenuItem(VRMVersion.MENU + "/GenerateAOTCall")]
|
||||
#endif
|
||||
static void GenerateAOTCall()
|
||||
{
|
||||
var path = UnityPath.FromUnityPath("Assets/VRM/UniVRM/Scripts/AOTCall.g.cs");
|
||||
var encoding = new UTF8Encoding(false);
|
||||
using (var s = new MemoryStream())
|
||||
{
|
||||
using (var w = new StreamWriter(s, encoding))
|
||||
{
|
||||
w.WriteLine(@"
|
||||
using System;
|
||||
using UniJSON;
|
||||
using UniGLTF;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace VRM {
|
||||
public static partial class VRMAOTCall {
|
||||
static void glTF()
|
||||
{
|
||||
{
|
||||
var f = new JsonFormatter();
|
||||
");
|
||||
|
||||
{
|
||||
var excludes = new List<Type>
|
||||
{
|
||||
typeof(object),
|
||||
};
|
||||
|
||||
foreach (var t in new Type[]
|
||||
{
|
||||
typeof(string),
|
||||
typeof(bool),
|
||||
|
||||
typeof(byte),
|
||||
typeof(ushort),
|
||||
typeof(uint),
|
||||
typeof(ulong),
|
||||
|
||||
typeof(sbyte),
|
||||
typeof(short),
|
||||
typeof(int),
|
||||
typeof(long),
|
||||
|
||||
typeof(float),
|
||||
typeof(double),
|
||||
typeof(Vector2),
|
||||
typeof(Vector3),
|
||||
typeof(Vector4),
|
||||
typeof(Quaternion),
|
||||
typeof(glTF),
|
||||
})
|
||||
{
|
||||
TraverseType("JsonValue", w, t, excludes);
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteLine(@"}
|
||||
|
||||
{
|
||||
var f = new MsgPackFormatter();
|
||||
");
|
||||
|
||||
{
|
||||
var excludes = new List<Type>
|
||||
{
|
||||
typeof(object),
|
||||
};
|
||||
|
||||
foreach (var t in new Type[]
|
||||
{
|
||||
typeof(string),
|
||||
typeof(bool),
|
||||
|
||||
typeof(byte),
|
||||
typeof(ushort),
|
||||
typeof(uint),
|
||||
typeof(ulong),
|
||||
|
||||
typeof(sbyte),
|
||||
typeof(short),
|
||||
typeof(int),
|
||||
typeof(long),
|
||||
|
||||
typeof(float),
|
||||
typeof(double),
|
||||
typeof(Vector2),
|
||||
typeof(Vector3),
|
||||
typeof(Vector4),
|
||||
typeof(Quaternion),
|
||||
})
|
||||
{
|
||||
TraverseType("MsgPackValue", w, t, excludes);
|
||||
}
|
||||
}
|
||||
|
||||
w.WriteLine(@"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
");
|
||||
}
|
||||
|
||||
var text = encoding.GetString(s.ToArray());
|
||||
File.WriteAllText(path.FullPath, text.Replace("\r\n", "\n"), encoding);
|
||||
}
|
||||
|
||||
path.ImportAsset();
|
||||
}
|
||||
|
||||
static bool IsGenericList(Type t)
|
||||
{
|
||||
if (t.IsGenericType
|
||||
&& t.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsGenericDictionary(Type t)
|
||||
{
|
||||
if (t.IsGenericType
|
||||
&& t.GetGenericTypeDefinition() == typeof(Dictionary<,>)
|
||||
&& t.GetGenericArguments()[0] == typeof(string))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<Type> GetNestedTypes(Type t)
|
||||
{
|
||||
if (t.DeclaringType == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach(var x in GetNestedTypes(t.DeclaringType))
|
||||
{
|
||||
yield return x;
|
||||
}
|
||||
|
||||
yield return t.DeclaringType;
|
||||
}
|
||||
|
||||
static string GenericTypeName(Type t)
|
||||
{
|
||||
if (!t.IsGenericType)
|
||||
{
|
||||
return t.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return t.Name.Split('`')[0]
|
||||
+ "<"
|
||||
+ string.Join(",", t.GetGenericArguments().Select(x => GenericTypeName(x)).ToArray())
|
||||
+ ">"
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
static string GetTypeName(Type t)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(t.Name))
|
||||
{
|
||||
sb.Append(t.Namespace);
|
||||
sb.Append(".");
|
||||
}
|
||||
|
||||
foreach(var x in GetNestedTypes(t))
|
||||
{
|
||||
sb.Append(x.Name);
|
||||
sb.Append(".");
|
||||
}
|
||||
|
||||
sb.Append(GenericTypeName(t));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static void TraverseType(string value, TextWriter w, Type t, List<Type> excludes)
|
||||
{
|
||||
if (excludes.Contains(t))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
w.WriteLine();
|
||||
w.WriteLine("// $0".Replace("$0", t.Name));
|
||||
excludes.Add(t);
|
||||
|
||||
if (t.IsArray)
|
||||
{
|
||||
var valueType = t.GetElementType();
|
||||
w.WriteLine("f.Serialize(default($0[]));".Replace("$0", valueType.Name));
|
||||
w.WriteLine(@"{
|
||||
var value = default($0[]);
|
||||
default(ListTreeNode<$2>).Deserialize(ref value);
|
||||
GenericDeserializer<$2, $0[]>.GenericArrayDeserializer<$0>(default(ListTreeNode<$2>));
|
||||
}"
|
||||
.Replace("$0", valueType.Name)
|
||||
.Replace("$2", value)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
// list
|
||||
if (IsGenericList(t))
|
||||
{
|
||||
var name = GetTypeName(t.GetGenericArguments()[0]);
|
||||
w.WriteLine("f.Serialize(default(List<$0>));".Replace("$0", name));
|
||||
w.WriteLine(@"{
|
||||
var value = default(List<$0>);
|
||||
default(ListTreeNode<$2>).Deserialize(ref value);
|
||||
GenericDeserializer<$2, List<$0>>.GenericListDeserializer<$0>(default(ListTreeNode<$2>));
|
||||
}"
|
||||
.Replace("$0", name)
|
||||
.Replace("$2", value)
|
||||
);
|
||||
|
||||
TraverseType(value, w, t.GetGenericArguments()[0], excludes);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// dict
|
||||
if (IsGenericDictionary(t))
|
||||
{
|
||||
var name = GetTypeName(t.GetGenericArguments()[1]);
|
||||
w.WriteLine("f.Serialize(default(Dictionary<string, $0>));".Replace("$0", name));
|
||||
w.WriteLine(@"{
|
||||
var value = default(Dictionary<string, $0>);
|
||||
default(ListTreeNode<$2>).Deserialize(ref value);
|
||||
GenericDeserializer<$2, Dictionary<string, $0>>.DictionaryDeserializer<$0>(default(ListTreeNode<$2>));
|
||||
}"
|
||||
.Replace("$0", name)
|
||||
.Replace("$2", value)
|
||||
);
|
||||
|
||||
TraverseType(value, w, t.GetGenericArguments()[1], excludes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
var name = GetTypeName(t);
|
||||
w.WriteLine("f.Serialize(default($0));".Replace("$0", name));
|
||||
w.WriteLine(@"{
|
||||
var value = default($0);
|
||||
default(ListTreeNode<$2>).Deserialize(ref value);
|
||||
}"
|
||||
.Replace("$0", name)
|
||||
.Replace("$2", value)
|
||||
);
|
||||
}
|
||||
|
||||
// object
|
||||
//if (t.IsClass)
|
||||
{
|
||||
foreach (var fi in t.GetFields(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
var fieldTypeName = GetTypeName(fi.FieldType);
|
||||
w.WriteLine(@"{
|
||||
JsonObjectValidator.GenericDeserializer<$2,$0>.DeserializeField<$1>(default(JsonSchema), default(ListTreeNode<$2>));
|
||||
}"
|
||||
.Replace("$0", GetTypeName(t))
|
||||
.Replace("$1", GetTypeName(fi.FieldType))
|
||||
.Replace("$2", value)
|
||||
);
|
||||
|
||||
TraverseType(value, w, fi.FieldType, excludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/VRM/UniVRM/Editor/Format/VRMAOTMenu.cs.meta
Normal file
12
Assets/VRM/UniVRM/Editor/Format/VRMAOTMenu.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 400503f201487874f93b0efdc892cbf3
|
||||
timeCreated: 1550040672
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/VRM/UniVRM/Editor/Tests/VersionTests.cs.meta
Normal file
12
Assets/VRM/UniVRM/Editor/Tests/VersionTests.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 40fe68d2a0dd7fa40bb4c5d05da70a21
|
||||
timeCreated: 1551255796
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1953
Assets/VRM/UniVRM/Scripts/AOTCall.g.cs
Normal file
1953
Assets/VRM/UniVRM/Scripts/AOTCall.g.cs
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/VRM/UniVRM/Scripts/AOTCall.g.cs.meta
Normal file
12
Assets/VRM/UniVRM/Scripts/AOTCall.g.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7e3d4b1fe26c7984f93ae501382f2dd6
|
||||
timeCreated: 1550041070
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue
Block a user