mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-06-09 01:10:08 -05:00
Added GenericCallUtility
This commit is contained in:
parent
2665da1125
commit
9da1b3f321
43
Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs
Normal file
43
Assets/VRM/UniJSON/Editor/Tests/GenericCallUtilityTests.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public class GenericCallUtilityTests
|
||||
{
|
||||
class Sample
|
||||
{
|
||||
public int Value
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void Set(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void GenericCallUtilityTestsSimplePasses()
|
||||
{
|
||||
var s = new Sample();
|
||||
|
||||
var mi = s.GetType().GetMethod("Set");
|
||||
|
||||
var invoke = (Action<Sample, int>)GenericInvokeCallFactory.Create<Sample, int>(mi);
|
||||
invoke(s, 1);
|
||||
Assert.AreEqual(1, s.Value);
|
||||
|
||||
var exp = (Action<Sample, int>)GenericExpressionCallFactory.Create<Sample, int>(mi);
|
||||
exp(s, 2);
|
||||
Assert.AreEqual(2, s.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 961cb5c87e54b5d4685e7447783259e7
|
||||
timeCreated: 1548657517
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta
Normal file
9
Assets/VRM/UniJSON/Scripts/GenericCallUtility.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a508fceebf4ef64ca956059360b2467
|
||||
folderAsset: yes
|
||||
timeCreated: 1548656168
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericExpressionCallFactory
|
||||
{
|
||||
#if UNITY_EDITOR && VRM_DEVELOP
|
||||
const int ARGS = 6;
|
||||
const string GENERATE_PATH = "Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericExpressionCallFactory.g.cs";
|
||||
|
||||
static System.Collections.Generic.IEnumerable<string> GetArgs(string prefix, int n)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
yield return prefix + i;
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem(VRM.VRMVersion.MENU + "/Generate GenericExpressionCallFactory")]
|
||||
static void Generate()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
using (var w = new StringWriter(sb))
|
||||
{
|
||||
w.WriteLine(@"
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericExpressionCallFactory
|
||||
{
|
||||
");
|
||||
// Create
|
||||
for (int i = 1; i <= ARGS; ++i)
|
||||
{
|
||||
var g = String.Join(", ", GetArgs("A", i).ToArray());
|
||||
var a = String.Join(", ", GetArgs("a", i).ToArray());
|
||||
|
||||
var source = @"
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, $0>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, $0> Create<S, $0>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, $0>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
".Replace("$0", g).Replace("$1", a);
|
||||
|
||||
w.WriteLine(source);
|
||||
}
|
||||
|
||||
// CreateWithThis
|
||||
for (int i = 1; i <= ARGS; ++i)
|
||||
{
|
||||
var g = String.Join(", ", GetArgs("A", i).ToArray());
|
||||
|
||||
var source = @"
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, $0>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<$0> CreateWithThis<S, $0>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<$0>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
".Replace("$0", g);
|
||||
|
||||
w.WriteLine(source);
|
||||
}
|
||||
|
||||
w.WriteLine(@"
|
||||
}
|
||||
}
|
||||
");
|
||||
}
|
||||
|
||||
var path = UniGLTF.UnityPath.FromUnityPath(GENERATE_PATH);
|
||||
File.WriteAllText(path.FullPath, sb.ToString().Replace("\r\n", "\n"));
|
||||
path.ImportAsset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 93b8e65929169944e823bc9a95c8a1ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,370 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericExpressionCallFactory
|
||||
{
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0> Create<S, A0>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1> Create<S, A0, A1>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0, A1>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2> Create<S, A0, A1, A2>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0, A1, A2>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3> Create<S, A0, A1, A2, A3>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0, A1, A2, A3>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3, A4>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3, A4> Create<S, A0, A1, A2, A3, A4>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0, A1, A2, A3, A4>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3, A4, A5>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3, A4, A5> Create<S, A0, A1, A2, A3, A4, A5>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
var self = Expression.Parameter(m.DeclaringType, m.Name);
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
var call = Expression.Call(self, m, args);
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<S, A0, A1, A2, A3, A4, A5>)
|
||||
#endif
|
||||
Expression.Lambda(call, new[] { self }.Concat(args).ToArray()).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0> CreateWithThis<S, A0>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1> CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0, A1>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2> CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0, A1, A2>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3> CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0, A1, A2, A3>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3, A4>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3, A4> CreateWithThis<S, A0, A1, A2, A3, A4>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0, A1, A2, A3, A4>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3, A4, A5>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3, A4, A5> CreateWithThis<S, A0, A1, A2, A3, A4, A5>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
var self = Expression.Constant(instance, typeof(S)); // thisを定数化
|
||||
var args = m.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name)).ToArray();
|
||||
MethodCallExpression call;
|
||||
if (m.IsStatic)
|
||||
{
|
||||
call = Expression.Call(m, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
call = Expression.Call(self, m, args);
|
||||
}
|
||||
return
|
||||
#if UNITY_5
|
||||
#else
|
||||
(Action<A0, A1, A2, A3, A4, A5>)
|
||||
#endif
|
||||
Expression.Lambda(call, args).Compile();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cf88d89ec3acdbf4eb44842ed15aaff4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericInvokeCallFactory
|
||||
{
|
||||
#if UNITY_EDITOR && VRM_DEVELOP
|
||||
const int ARGS = 6;
|
||||
const string GENERATE_PATH = "Assets/VRM/UniJSON/Scripts/GenericCallUtility/GenericInvokeCallFactory.g.cs";
|
||||
|
||||
static System.Collections.Generic.IEnumerable<string> GetArgs(string prefix, int n)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
yield return prefix + i;
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem(VRM.VRMVersion.MENU + "/Generate GenericInvokeCallFactory")]
|
||||
static void Generate()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
using (var w = new StringWriter(sb))
|
||||
{
|
||||
w.WriteLine(@"
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericInvokeCallFactory
|
||||
{
|
||||
");
|
||||
|
||||
// CreateWithThis
|
||||
w.WriteLine("//////////// Create");
|
||||
|
||||
// Create
|
||||
for (int i = 1; i <= ARGS; ++i)
|
||||
{
|
||||
var g = String.Join(", ", GetArgs("A", i).ToArray());
|
||||
var a = String.Join(", ", GetArgs("a", i).ToArray());
|
||||
|
||||
if (i >= 4) w.WriteLine(@"
|
||||
#if UNITY_5
|
||||
#else
|
||||
");
|
||||
|
||||
|
||||
var source = @"
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, $0>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, $0> Create<S, $0>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, $0> callback=
|
||||
(s, $1) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { $1 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
".Replace("$0", g).Replace("$1", a);
|
||||
|
||||
w.WriteLine(source);
|
||||
|
||||
if (i >= 4) w.WriteLine(@"
|
||||
#endif
|
||||
");
|
||||
}
|
||||
|
||||
|
||||
// CreateWithThis
|
||||
w.WriteLine("//////////// CreateWithThis");
|
||||
for (int i = 1; i <= ARGS; ++i)
|
||||
{
|
||||
var g = String.Join(", ", GetArgs("A", i).ToArray());
|
||||
var a = String.Join(", ", GetArgs("a", i).ToArray());
|
||||
|
||||
if (i > 4) w.WriteLine(@"
|
||||
#if UNITY_5
|
||||
#else
|
||||
");
|
||||
|
||||
var source = @"
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, $0>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<$0> CreateWithThis<S, $0>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<$0> callback=
|
||||
($1) => {
|
||||
m.Invoke(instance, new object[]{ $1 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
".Replace("$0", g).Replace("$1", a);
|
||||
|
||||
w.WriteLine(source);
|
||||
|
||||
if (i > 4) w.WriteLine(@"
|
||||
#endif
|
||||
");
|
||||
}
|
||||
|
||||
|
||||
w.WriteLine(@"
|
||||
}
|
||||
}
|
||||
");
|
||||
}
|
||||
|
||||
var path = UniGLTF.UnityPath.FromUnityPath(GENERATE_PATH);
|
||||
File.WriteAllText(path.FullPath, sb.ToString().Replace("\r\n", "\n"));
|
||||
path.ImportAsset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#region no arguments
|
||||
public static Action<S> Create<S>(MethodInfo m)
|
||||
{
|
||||
return (s) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { });
|
||||
};
|
||||
}
|
||||
|
||||
public static Action CreateWithThis<S>(MethodInfo m, S instance)
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
m.Invoke(instance, new object[] { });
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4bdb47bf29e1214a9e3da9b4ae9f31e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,321 @@
|
|||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
namespace UniJSON
|
||||
{
|
||||
public static partial class GenericInvokeCallFactory
|
||||
{
|
||||
|
||||
//////////// Create
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0> Create<S, A0>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0> callback=
|
||||
(s, a0) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1> Create<S, A0, A1>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0, A1> callback=
|
||||
(s, a0, a1) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0, a1 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2> Create<S, A0, A1, A2>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0, A1, A2> callback=
|
||||
(s, a0, a1, a2) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0, a1, a2 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
#else
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3> Create<S, A0, A1, A2, A3>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0, A1, A2, A3> callback=
|
||||
(s, a0, a1, a2, a3) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0, a1, a2, a3 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
#else
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3, A4>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3, A4> Create<S, A0, A1, A2, A3, A4>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0, A1, A2, A3, A4> callback=
|
||||
(s, a0, a1, a2, a3, a4) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0, a1, a2, a3, a4 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
#else
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate Create<S, A0, A1, A2, A3, A4, A5>(MethodInfo m)
|
||||
#else
|
||||
public static Action<S, A0, A1, A2, A3, A4, A5> Create<S, A0, A1, A2, A3, A4, A5>(MethodInfo m)
|
||||
#endif
|
||||
{
|
||||
Action<S, A0, A1, A2, A3, A4, A5> callback=
|
||||
(s, a0, a1, a2, a3, a4, a5) =>
|
||||
{
|
||||
m.Invoke(s, new object[] { a0, a1, a2, a3, a4, a5 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
//////////// CreateWithThis
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0> CreateWithThis<S, A0>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0> callback=
|
||||
(a0) => {
|
||||
m.Invoke(instance, new object[]{ a0 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1> CreateWithThis<S, A0, A1>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0, A1> callback=
|
||||
(a0, a1) => {
|
||||
m.Invoke(instance, new object[]{ a0, a1 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2> CreateWithThis<S, A0, A1, A2>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0, A1, A2> callback=
|
||||
(a0, a1, a2) => {
|
||||
m.Invoke(instance, new object[]{ a0, a1, a2 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3> CreateWithThis<S, A0, A1, A2, A3>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0, A1, A2, A3> callback=
|
||||
(a0, a1, a2, a3) => {
|
||||
m.Invoke(instance, new object[]{ a0, a1, a2, a3 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
#else
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3, A4>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3, A4> CreateWithThis<S, A0, A1, A2, A3, A4>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0, A1, A2, A3, A4> callback=
|
||||
(a0, a1, a2, a3, a4) => {
|
||||
m.Invoke(instance, new object[]{ a0, a1, a2, a3, a4 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
#else
|
||||
|
||||
|
||||
#if UNITY_5
|
||||
public static Delegate CreateWithThis<S, A0, A1, A2, A3, A4, A5>(MethodInfo m, S instance)
|
||||
#else
|
||||
public static Action<A0, A1, A2, A3, A4, A5> CreateWithThis<S, A0, A1, A2, A3, A4, A5>(MethodInfo m, S instance)
|
||||
#endif
|
||||
{
|
||||
if (m.IsStatic)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo: CreateDelegate
|
||||
Action<A0, A1, A2, A3, A4, A5> callback=
|
||||
(a0, a1, a2, a3, a4, a5) => {
|
||||
m.Invoke(instance, new object[]{ a0, a1, a2, a3, a4, a5 });
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 56dfdc21f4d594143ab023e6bd171f91
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;DEBUG;UNITY_5</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
|
@ -43,4 +43,4 @@
|
|||
<Compile Include="UnityHelper.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user