| | |
| | | Assets/ThirdParty.meta |
| | | LuaDebuggee.dll |
| | | Assets/XLua/Gen.meta |
| | | Assets/ILRuntime/Generated/ |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: a2619b749b100f847a3fdbddc509bebc |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | #if UNITY_EDITOR |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using ILCrossBinding; |
| | | using Snxxz.UI; |
| | | using UnityEditor; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | |
| | | [System.Reflection.Obfuscation(Exclude = true)] |
| | | public class ILRuntimeCLRBinding |
| | | { |
| | | const string genPath = "Assets/Scripts/ILRuntime/Generated"; |
| | | |
| | | //需要生成绑定代码的类, litjson 和 c# system 下的代码不要在这生成,会有问题 |
| | | //此处配置的类,生成代码会覆盖自动生成的。 |
| | | static List<Type> types = new List<Type> |
| | | { |
| | | //Unity相关 |
| | | typeof(Transform), |
| | | typeof(RectTransform), |
| | | typeof(GameObject), |
| | | typeof(Component), |
| | | typeof(UnityEngine.Object), |
| | | typeof(MonoBehaviour), |
| | | typeof(Behaviour), |
| | | typeof(Text), |
| | | typeof(Button), |
| | | typeof(Image), |
| | | //主工程相关 |
| | | typeof(Int2), |
| | | typeof(Int3), |
| | | typeof(UILoader), |
| | | typeof(ComponentExtersion), |
| | | typeof(TransformExtension), |
| | | typeof(LocalSave), |
| | | typeof(ILBehaviourProxy), |
| | | typeof(WidgetBehavior), |
| | | typeof(ILWindowProxy), |
| | | typeof(ILOneLevelWindowProxy), |
| | | typeof(ModelCenter), |
| | | typeof(Singleton<ModelCenter>), |
| | | typeof(WindowCenter), |
| | | typeof(SingletonMonobehaviour<WindowCenter>), |
| | | typeof(WindowJumpMgr), |
| | | typeof(Singleton<WindowJumpMgr>), |
| | | typeof(DebugEx), |
| | | typeof(TextEx), |
| | | typeof(ButtonEx), |
| | | typeof(ImageEx), |
| | | typeof(TimeUtility), |
| | | typeof(HttpRequest), |
| | | typeof(SingletonMonobehaviour<HttpRequest>), |
| | | typeof(SysNotifyMgr), |
| | | typeof(SingletonMonobehaviour<SysNotifyMgr>), |
| | | typeof(PackageRegedit), |
| | | typeof(GameNetSystem), |
| | | typeof(Singleton<GameNetSystem>), |
| | | typeof(GameNetPackBasic), |
| | | typeof(OperationTimeHepler), |
| | | typeof(Singleton<OperationTimeHepler>), |
| | | typeof(DtcBasic), |
| | | typeof(PlayerDatas), |
| | | typeof(Singleton<PlayerDatas>), |
| | | typeof(PlayerBaseData), |
| | | typeof(Language), |
| | | typeof(TimeMgr), |
| | | typeof(SingletonMonobehaviour<TimeMgr>), |
| | | typeof(CommonItemBaisc), |
| | | typeof(ItemCell), |
| | | typeof(ItemTipUtility), |
| | | typeof(SkillModel), |
| | | typeof(VipModel), |
| | | typeof(ItemCellModel), |
| | | typeof(ItemModel), |
| | | typeof(PackModel), |
| | | typeof(EquipModel), |
| | | //表 |
| | | typeof(ItemConfig), |
| | | typeof(FuncConfigConfig), |
| | | typeof(SysInfoConfig) |
| | | }; |
| | | |
| | | //需要排除的方法 |
| | | static List<object[]> excludeMethods = new List<object[]>() |
| | | { |
| | | new object[]{typeof(Text),"OnRebuildRequested"}, |
| | | new object[]{typeof(MonoBehaviour),"get_runInEditMode"}, |
| | | new object[]{typeof(MonoBehaviour),"set_runInEditMode"}, |
| | | }; |
| | | |
| | | static HashSet<MethodBase> GetExcludeMethod() |
| | | { |
| | | var set = new HashSet<MethodBase>(); |
| | | foreach (var objs in excludeMethods) |
| | | { |
| | | var type = (Type)objs[0]; |
| | | var m = type.GetMethod((string)objs[1]); |
| | | set.Add(m); |
| | | } |
| | | return set; |
| | | } |
| | | |
| | | [MenuItem("ILRuntime/清除CLR绑定")] |
| | | static void ClearCLRBinding() |
| | | { |
| | | if (Directory.Exists(genPath)) |
| | | { |
| | | Directory.Delete(genPath, true); |
| | | } |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | |
| | | [MenuItem("ILRuntime/生成CLR绑定")] |
| | | public static void GenerateCLRBinding() |
| | | { |
| | | ClearCLRBinding(); |
| | | GenerateCLRBindingByAnalysis(); |
| | | GenerateCLRBindingByTypes(); |
| | | MergeGenerated(); |
| | | AssetDatabase.Refresh(); |
| | | DebugEx.Log("ILRuntime CLR绑定代码生成成功!"); |
| | | } |
| | | |
| | | // [MenuItem("ILRuntime/自动分析Dll生成CLR绑定")] |
| | | public static void GenerateCLRBindingByAnalysis() |
| | | { |
| | | var path = genPath + "/Analysis"; |
| | | //用热更dll调用引用来生成绑定代码 |
| | | ILRuntime.Runtime.Enviorment.AppDomain domain = new ILRuntime.Runtime.Enviorment.AppDomain(); |
| | | using (System.IO.FileStream fs = new System.IO.FileStream("Assets/ResourcesOut/logic/Logic.dll.bytes", System.IO.FileMode.Open, System.IO.FileAccess.Read)) |
| | | { |
| | | domain.LoadAssembly(fs); |
| | | //Crossbind Adapter is needed to generate the correct binding code |
| | | InitILRuntime(domain); |
| | | ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(domain, path); |
| | | } |
| | | } |
| | | |
| | | // [MenuItem("ILRuntime/根据配置列表生成CLR绑定")] |
| | | public static void GenerateCLRBindingByTypes() |
| | | { |
| | | var path = genPath + "/Types"; |
| | | //用自定义的列表来生成绑定代码 |
| | | ILRuntime.Runtime.CLRBinding.BindingCodeGenerator.GenerateBindingCode(types, path, GetExcludeMethod()); |
| | | } |
| | | |
| | | //合并生成的代码 |
| | | public static void MergeGenerated() |
| | | { |
| | | var exist = new HashSet<string>(); |
| | | var added = new List<string>(); |
| | | var path1 = System.Environment.CurrentDirectory + "/" + genPath + "/Types"; |
| | | var dic1 = new DirectoryInfo(path1); |
| | | //获取types生成的列表 |
| | | foreach (var file in dic1.GetFiles()) |
| | | { |
| | | exist.Add(file.Name); |
| | | } |
| | | var path2 = System.Environment.CurrentDirectory + "/" + genPath + "/Analysis"; |
| | | var dic2 = new DirectoryInfo(path2); |
| | | //dll存在和types一样的代码,就删除,其余的视为新增 |
| | | foreach (var file in dic2.GetFiles()) |
| | | { |
| | | if (exist.Contains(file.Name)) |
| | | file.Delete(); |
| | | else |
| | | added.Add(Path.GetFileNameWithoutExtension(file.Name)); |
| | | } |
| | | //将dll新增代码写入到CLRBindings中注册 |
| | | var lines = File.ReadAllLines(path1 + "/CLRBindings.cs").ToList(); |
| | | int index = 0; |
| | | for (int i = 0; i < lines.Count; i++) |
| | | { |
| | | if (lines[i].Contains("public static void Initialize")) |
| | | { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | var space = " "; |
| | | lines.Insert(index + 2, space + "//配置列表的CLR绑定类"); |
| | | foreach (var name in added) |
| | | { |
| | | lines.Insert(index + 2, space + name + ".Register(app);"); |
| | | } |
| | | lines.Insert(index + 2, space + "//自动分析dll新增的CLR绑定类"); |
| | | File.WriteAllLines(path1 + "/CLRBindings.cs", lines); |
| | | } |
| | | |
| | | //这里需要注册所有热更DLL中用到的跨域继承Adapter,否则无法正确抓取引用 |
| | | static void InitILRuntime(ILRuntime.Runtime.Enviorment.AppDomain domain) |
| | | { |
| | | domain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); |
| | | domain.RegisterCrossBindingAdaptor(new DtcBasicAdapter()); |
| | | domain.RegisterCrossBindingAdaptor(new GameNetPackBasicAdapter()); |
| | | } |
| | | |
| | | } |
| | | #endif |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: b25613ceb76187a4f928518b9ac1dd22 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | #if UNITY_EDITOR |
| | | using UnityEditor; |
| | | using UnityEngine; |
| | | using System; |
| | | [System.Reflection.Obfuscation(Exclude = true)] |
| | | public class ILRuntimeCrossBinding : EditorWindow |
| | | { |
| | | [MenuItem("ILRuntime/生成跨域继承适配器")] |
| | | public static void ShowWindow() |
| | | { |
| | | EditorWindow.GetWindow<ILRuntimeCrossBinding>("生成跨域继承适配器").Show(); |
| | | } |
| | | |
| | | Type type = typeof(DtcBasic); |
| | | |
| | | private void OnGUI() |
| | | { |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | GUILayout.Label(string.Format("类名:{0}", type.Name)); |
| | | EditorGUILayout.Space(); |
| | | |
| | | if (GUILayout.Button("生成")) |
| | | { |
| | | GenerateCrossbindAdapter(); |
| | | } |
| | | } |
| | | |
| | | void GenerateCrossbindAdapter() |
| | | { |
| | | var path = "Assets/Scripts/ILRuntime/Src/Inheritance/{0}Adapter.cs"; |
| | | using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Format(path, type.Name))) |
| | | { |
| | | sw.WriteLine(ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(type, "ILCrossBinding")); |
| | | } |
| | | AssetDatabase.Refresh(); |
| | | DebugEx.Log("跨域继承适配生成成功"); |
| | | } |
| | | } |
| | | #endif |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 077d29cbd51762b43bf8163a1b0df776 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 085891858c30b314cadd10f32049c31c |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 160d44d5c8f210a4a8f72a7d2167b131 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 63c35164a7435f845b547dd77d13d13a |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using ILRuntime.Other; |
| | | using System; |
| | | using System.Reflection; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.CLR.TypeSystem; |
| | | using ILRuntime.Runtime.Stack; |
| | | |
| | | public unsafe class QuaternionBinder : ValueTypeBinder<Quaternion> |
| | | { |
| | | Vector3Binder vector3Binder; |
| | | bool vector3BinderGot; |
| | | |
| | | Vector3Binder Vector3Binder |
| | | { |
| | | get |
| | | { |
| | | if (!vector3BinderGot) |
| | | { |
| | | vector3BinderGot = true; |
| | | var vector3Type = CLRType.AppDomain.GetType(typeof(Vector3)) as CLRType; |
| | | vector3Binder = vector3Type.ValueTypeBinder as Vector3Binder; |
| | | } |
| | | |
| | | return vector3Binder; |
| | | } |
| | | } |
| | | |
| | | public override unsafe void AssignFromStack(ref Quaternion ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | ins.x = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | ins.y = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 3); |
| | | ins.z = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 4); |
| | | ins.w = *(float*)&v->Value; |
| | | } |
| | | |
| | | public override unsafe void CopyValueTypeToStack(ref Quaternion ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | *(float*)&v->Value = ins.x; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | *(float*)&v->Value = ins.y; |
| | | v = ILIntepreter.Minus(ptr, 3); |
| | | *(float*)&v->Value = ins.z; |
| | | v = ILIntepreter.Minus(ptr, 4); |
| | | *(float*)&v->Value = ins.w; |
| | | } |
| | | public override void RegisterCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain) |
| | | { |
| | | BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; |
| | | MethodBase method; |
| | | Type[] args; |
| | | Type type = typeof(Quaternion); |
| | | args = new Type[] { typeof(float), typeof(float), typeof(float), typeof(float) }; |
| | | method = type.GetConstructor(flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, NewQuaternion); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Quaternion) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Multiply); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Multiply2); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Quaternion) }; |
| | | method = type.GetMethod("op_Equality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Equality); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Quaternion) }; |
| | | method = type.GetMethod("op_Inequality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Inequality); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Quaternion) }; |
| | | method = type.GetMethod("Dot", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Dot); |
| | | |
| | | args = new Type[] { typeof(Quaternion), typeof(Quaternion) }; |
| | | method = type.GetMethod("Angle", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Angle); |
| | | |
| | | args = new Type[] { typeof(Vector3) }; |
| | | method = type.GetMethod("Euler", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Euler); |
| | | |
| | | args = new Type[] { typeof(float), typeof(float), typeof(float) }; |
| | | method = type.GetMethod("Euler", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Quaternion_Euler2); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_eulerAngles", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_EulerAngle); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_identity", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Identity); |
| | | } |
| | | |
| | | StackObject* Quaternion_Multiply(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | Quaternion left, right; |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseQuaternion(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | var res = left * right; |
| | | PushQuaternion(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Multiply2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | Vector3 vec; |
| | | Quaternion left; |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3Binder.ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | vec = left * vec; |
| | | PushVector3(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Equality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Quaternion left, right; |
| | | ParseQuaternion(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | var res = left == right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Inequality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Quaternion left, right; |
| | | ParseQuaternion(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | var res = left != right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Dot(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Quaternion left, right; |
| | | ParseQuaternion(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | var res = Quaternion.Dot(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Angle(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Quaternion left, right; |
| | | ParseQuaternion(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseQuaternion(out left, intp, ptr, mStack); |
| | | |
| | | var res = Quaternion.Angle(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Euler(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 vec; |
| | | Vector3Binder.ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | var res = Quaternion.Euler(vec); |
| | | |
| | | PushQuaternion(ref res, intp, ptr, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Quaternion_Euler2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 3); |
| | | float x, y, z; |
| | | |
| | | var ptr = ILIntepreter.GetObjectAndResolveReference(ILIntepreter.Minus(esp, 1)); |
| | | z = *(float*)&ptr->Value; |
| | | |
| | | ptr = ILIntepreter.GetObjectAndResolveReference(ILIntepreter.Minus(esp, 2)); |
| | | y = *(float*)&ptr->Value; |
| | | |
| | | ptr = ILIntepreter.GetObjectAndResolveReference(ILIntepreter.Minus(esp, 3)); |
| | | x = *(float*)&ptr->Value; |
| | | |
| | | var res = Quaternion.Euler(x, y, z); |
| | | |
| | | PushQuaternion(ref res, intp, ptr, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* NewQuaternion(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | StackObject* ret; |
| | | if (isNewObj) |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 3); |
| | | Quaternion vec; |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | vec.w = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | vec.z = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 3); |
| | | vec.y = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 4); |
| | | vec.x = *(float*)&ptr->Value; |
| | | |
| | | PushQuaternion(ref vec, intp, ptr, mStack); |
| | | } |
| | | else |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 5); |
| | | var instance = ILIntepreter.GetObjectAndResolveReference(ret); |
| | | var dst = *(StackObject**)&instance->Value; |
| | | var f = ILIntepreter.Minus(dst, 1); |
| | | var v = ILIntepreter.Minus(esp, 4); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 2); |
| | | v = ILIntepreter.Minus(esp, 3); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 3); |
| | | v = ILIntepreter.Minus(esp, 2); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 4); |
| | | v = ILIntepreter.Minus(esp, 1); |
| | | *f = *v; |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | StackObject* Get_EulerAngle(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Quaternion vec; |
| | | ParseQuaternion(out vec, intp, ptr, mStack); |
| | | |
| | | var res = vec.eulerAngles; |
| | | |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_Identity(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = esp; |
| | | |
| | | var res = Quaternion.identity; |
| | | PushQuaternion(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | static void ParseQuaternion(out Quaternion vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var a = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | if (a->ObjectType == ObjectTypes.ValueTypeObjectReference) |
| | | { |
| | | var src = *(StackObject**)&a->Value; |
| | | vec.x = *(float*)&ILIntepreter.Minus(src, 1)->Value; |
| | | vec.y = *(float*)&ILIntepreter.Minus(src, 2)->Value; |
| | | vec.z = *(float*)&ILIntepreter.Minus(src, 3)->Value; |
| | | vec.w = *(float*)&ILIntepreter.Minus(src, 4)->Value; |
| | | intp.FreeStackValueType(ptr); |
| | | } |
| | | else |
| | | { |
| | | vec = (Quaternion)StackObject.ToObject(a, intp.AppDomain, mStack); |
| | | intp.Free(ptr); |
| | | } |
| | | } |
| | | |
| | | void PushQuaternion(ref Quaternion vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | intp.AllocValueType(ptr, CLRType); |
| | | var dst = *((StackObject**)&ptr->Value); |
| | | CopyValueTypeToStack(ref vec, dst, mStack); |
| | | } |
| | | |
| | | void PushVector3(ref Vector3 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var binder = Vector3Binder; |
| | | if (binder != null) |
| | | binder.PushVector3(ref vec, intp, ptr, mStack); |
| | | else |
| | | ILIntepreter.PushObject(ptr, mStack, vec, true); |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: e5e2a12f16432dd41b19583a42ca0e9d |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using ILRuntime.Other; |
| | | using System; |
| | | using System.Reflection; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.CLR.TypeSystem; |
| | | using ILRuntime.Runtime.Stack; |
| | | |
| | | public unsafe class Vector2Binder : ValueTypeBinder<Vector2> |
| | | { |
| | | Vector3Binder vector3Binder; |
| | | bool vector3BinderGot; |
| | | |
| | | Vector3Binder Vector3Binder |
| | | { |
| | | get |
| | | { |
| | | if (!vector3BinderGot) |
| | | { |
| | | vector3BinderGot = true; |
| | | var vector3Type = CLRType.AppDomain.GetType(typeof(Vector3)) as CLRType; |
| | | vector3Binder = vector3Type.ValueTypeBinder as Vector3Binder; |
| | | } |
| | | |
| | | return vector3Binder; |
| | | } |
| | | } |
| | | |
| | | public override unsafe void AssignFromStack(ref Vector2 ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | ins.x = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | ins.y = *(float*)&v->Value; |
| | | } |
| | | |
| | | public override unsafe void CopyValueTypeToStack(ref Vector2 ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | *(float*)&v->Value = ins.x; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | *(float*)&v->Value = ins.y; |
| | | } |
| | | public override void RegisterCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain) |
| | | { |
| | | BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; |
| | | MethodBase method; |
| | | Type[] args; |
| | | Type type = typeof(Vector2); |
| | | args = new Type[] { typeof(float), typeof(float) }; |
| | | method = type.GetConstructor(flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, NewVector2); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("op_Addition", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Add); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("op_Subtraction", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Subtraction); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(float) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Multiply); |
| | | |
| | | args = new Type[] { typeof(float), typeof(Vector2) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Multiply2); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(float) }; |
| | | method = type.GetMethod("op_Division", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Division); |
| | | |
| | | args = new Type[] { typeof(Vector2) }; |
| | | method = type.GetMethod("op_UnaryNegation", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Negate); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("op_Equality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Equality); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("op_Inequality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Inequality); |
| | | |
| | | args = new Type[] { typeof(Vector2) }; |
| | | method = type.GetMethod("op_Implicit", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Implicit); |
| | | |
| | | args = new Type[] { typeof(Vector3) }; |
| | | method = type.GetMethod("op_Implicit", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Implicit2); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("Dot", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Dot); |
| | | |
| | | args = new Type[] { typeof(Vector2), typeof(Vector2) }; |
| | | method = type.GetMethod("Distance", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector2_Distance); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_magnitude", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Magnitude); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_sqrMagnitude", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_SqrMagnitude); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_normalized", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Normalized); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_one", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_One); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_zero", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Zero); |
| | | } |
| | | |
| | | StackObject* Vector2_Add(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = left + right; |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Subtraction(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = left - right; |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Multiply(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | Vector2 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | vec = vec * val; |
| | | PushVector2(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Multiply2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | Vector2 vec; |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | vec = val * vec; |
| | | PushVector2(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Division(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | Vector2 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | vec = vec / val; |
| | | PushVector2(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Negate(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | vec = -vec; |
| | | PushVector2(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Implicit(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | Vector3 res = vec; |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Implicit2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3Binder.ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | Vector2 res = vec; |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Equality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = left == right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Inequality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = left != right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Dot(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = Vector3.Dot(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector2_Distance(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector2 left, right; |
| | | ParseVector2(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector2(out left, intp, ptr, mStack); |
| | | |
| | | var res = Vector3.Distance(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* NewVector2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | StackObject* ret; |
| | | if (isNewObj) |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | vec.y = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | vec.x = *(float*)&ptr->Value; |
| | | |
| | | PushVector2(ref vec, intp, ptr, mStack); |
| | | } |
| | | else |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 3); |
| | | var instance = ILIntepreter.GetObjectAndResolveReference(ret); |
| | | var dst = *(StackObject**)&instance->Value; |
| | | var f = ILIntepreter.Minus(dst, 1); |
| | | var v = ILIntepreter.Minus(esp, 2); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 2); |
| | | v = ILIntepreter.Minus(esp, 1); |
| | | *f = *v; |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | StackObject* Get_Magnitude(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | float res = vec.magnitude; |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_SqrMagnitude(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | float res = vec.sqrMagnitude; |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_Normalized(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector2 vec; |
| | | ParseVector2(out vec, intp, ptr, mStack); |
| | | |
| | | var res = vec.normalized; |
| | | |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_One(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = esp; |
| | | var res = Vector2.one; |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_Zero(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = esp; |
| | | var res = Vector2.zero; |
| | | PushVector2(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | public static void ParseVector2(out Vector2 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var a = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | if (a->ObjectType == ObjectTypes.ValueTypeObjectReference) |
| | | { |
| | | var src = *(StackObject**)&a->Value; |
| | | vec.x = *(float*)&ILIntepreter.Minus(src, 1)->Value; |
| | | vec.y = *(float*)&ILIntepreter.Minus(src, 2)->Value; |
| | | intp.FreeStackValueType(ptr); |
| | | } |
| | | else |
| | | { |
| | | vec = (Vector2)StackObject.ToObject(a, intp.AppDomain, mStack); |
| | | intp.Free(ptr); |
| | | } |
| | | } |
| | | |
| | | public void PushVector2(ref Vector2 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | intp.AllocValueType(ptr, CLRType); |
| | | var dst = *((StackObject**)&ptr->Value); |
| | | CopyValueTypeToStack(ref vec, dst, mStack); |
| | | } |
| | | |
| | | void PushVector3(ref Vector3 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var binder = Vector3Binder; |
| | | if (binder != null) |
| | | binder.PushVector3(ref vec, intp, ptr, mStack); |
| | | else |
| | | ILIntepreter.PushObject(ptr, mStack, vec, true); |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: c67e166fc0959864c95cb8a252f5c0d8 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using ILRuntime.Other; |
| | | using System; |
| | | using System.Reflection; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Stack; |
| | | |
| | | public unsafe class Vector3Binder : ValueTypeBinder<Vector3> |
| | | { |
| | | public override unsafe void AssignFromStack(ref Vector3 ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | ins.x = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | ins.y = *(float*)&v->Value; |
| | | v = ILIntepreter.Minus(ptr, 3); |
| | | ins.z = *(float*)&v->Value; |
| | | } |
| | | |
| | | public override unsafe void CopyValueTypeToStack(ref Vector3 ins, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var v = ILIntepreter.Minus(ptr, 1); |
| | | *(float*)&v->Value = ins.x; |
| | | v = ILIntepreter.Minus(ptr, 2); |
| | | *(float*)&v->Value = ins.y; |
| | | v = ILIntepreter.Minus(ptr, 3); |
| | | *(float*)&v->Value = ins.z; |
| | | } |
| | | public override void RegisterCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain) |
| | | { |
| | | BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; |
| | | MethodBase method; |
| | | Type[] args; |
| | | Type type = typeof(Vector3); |
| | | args = new Type[] { typeof(float), typeof(float), typeof(float) }; |
| | | method = type.GetConstructor(flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, NewVector3); |
| | | |
| | | args = new Type[] { typeof(float), typeof(float) }; |
| | | method = type.GetConstructor(flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, NewVector3_2); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Addition", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Add); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Subtraction", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Subtraction); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(float) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Multiply); |
| | | |
| | | args = new Type[] { typeof(float), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Multiply", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Multiply2); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(float) }; |
| | | method = type.GetMethod("op_Division", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Division); |
| | | |
| | | args = new Type[] { typeof(Vector3) }; |
| | | method = type.GetMethod("op_UnaryNegation", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Negate); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Equality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Equality); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("op_Inequality", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Inequality); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("Dot", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Dot); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("Cross", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Cross); |
| | | |
| | | args = new Type[] { typeof(Vector3), typeof(Vector3) }; |
| | | method = type.GetMethod("Distance", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Vector3_Distance); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_magnitude", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Magnitude); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_sqrMagnitude", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_SqrMagnitude); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_normalized", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Normalized); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_one", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_One); |
| | | |
| | | args = new Type[] { }; |
| | | method = type.GetMethod("get_zero", flag, null, args, null); |
| | | appdomain.RegisterCLRMethodRedirection(method, Get_Zero); |
| | | } |
| | | |
| | | StackObject* Vector3_Add(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = left + right; |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Subtraction(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = left - right; |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Multiply(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | Vector3 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | vec = vec * val; |
| | | PushVector3(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Multiply2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | Vector3 vec; |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | vec = val * vec; |
| | | PushVector3(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Division(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | var b = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | |
| | | float val = *(float*)&b->Value; |
| | | |
| | | Vector3 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | vec = vec / val; |
| | | PushVector3(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Negate(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 1); |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | vec = -vec; |
| | | PushVector3(ref vec, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Equality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = left == right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Inequality(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = left != right; |
| | | |
| | | ret->ObjectType = ObjectTypes.Integer; |
| | | ret->Value = res ? 1 : 0; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Dot(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = Vector3.Dot(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Distance(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = Vector3.Distance(left, right); |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Vector3_Cross(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 2); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | |
| | | Vector3 left, right; |
| | | ParseVector3(out right, intp, ptr, mStack); |
| | | |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | ParseVector3(out left, intp, ptr, mStack); |
| | | |
| | | var res = Vector3.Cross(left, right); |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* NewVector3(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | StackObject* ret; |
| | | if (isNewObj) |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 2); |
| | | Vector3 vec; |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | vec.z = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | vec.y = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 3); |
| | | vec.x = *(float*)&ptr->Value; |
| | | |
| | | PushVector3(ref vec, intp, ptr, mStack); |
| | | } |
| | | else |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 4); |
| | | var instance = ILIntepreter.GetObjectAndResolveReference(ret); |
| | | var dst = *(StackObject**)&instance->Value; |
| | | var f = ILIntepreter.Minus(dst, 1); |
| | | var v = ILIntepreter.Minus(esp, 3); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 2); |
| | | v = ILIntepreter.Minus(esp, 2); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 3); |
| | | v = ILIntepreter.Minus(esp, 1); |
| | | *f = *v; |
| | | } |
| | | return ret; |
| | | } |
| | | StackObject* NewVector3_2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | StackObject* ret; |
| | | if (isNewObj) |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | vec.y = *(float*)&ptr->Value; |
| | | ptr = ILIntepreter.Minus(esp, 2); |
| | | vec.x = *(float*)&ptr->Value; |
| | | vec.z = 0; |
| | | |
| | | PushVector3(ref vec, intp, ptr, mStack); |
| | | } |
| | | else |
| | | { |
| | | ret = ILIntepreter.Minus(esp, 3); |
| | | var instance = ILIntepreter.GetObjectAndResolveReference(ret); |
| | | var dst = *(StackObject**)&instance->Value; |
| | | var f = ILIntepreter.Minus(dst, 1); |
| | | var v = ILIntepreter.Minus(esp, 2); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 2); |
| | | v = ILIntepreter.Minus(esp, 1); |
| | | *f = *v; |
| | | |
| | | f = ILIntepreter.Minus(dst, 3); |
| | | *(float*)&f->Value = 0f; |
| | | } |
| | | return ret; |
| | | } |
| | | |
| | | StackObject* Get_Magnitude(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | float res = vec.magnitude; |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_SqrMagnitude(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | float res = vec.sqrMagnitude; |
| | | |
| | | ret->ObjectType = ObjectTypes.Float; |
| | | *(float*)&ret->Value = res; |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_Normalized(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = ILIntepreter.Minus(esp, 1); |
| | | var ptr = ILIntepreter.Minus(esp, 1); |
| | | Vector3 vec; |
| | | ParseVector3(out vec, intp, ptr, mStack); |
| | | |
| | | var res = vec.normalized; |
| | | |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_One(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = esp; |
| | | var res = Vector3.one; |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | StackObject* Get_Zero(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | var ret = esp; |
| | | var res = Vector3.zero; |
| | | PushVector3(ref res, intp, ret, mStack); |
| | | return ret + 1; |
| | | } |
| | | |
| | | public static void ParseVector3(out Vector3 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | var a = ILIntepreter.GetObjectAndResolveReference(ptr); |
| | | if (a->ObjectType == ObjectTypes.ValueTypeObjectReference) |
| | | { |
| | | var src = *(StackObject**)&a->Value; |
| | | vec.x = *(float*)&ILIntepreter.Minus(src, 1)->Value; |
| | | vec.y = *(float*)&ILIntepreter.Minus(src, 2)->Value; |
| | | vec.z = *(float*)&ILIntepreter.Minus(src, 3)->Value; |
| | | intp.FreeStackValueType(ptr); |
| | | } |
| | | else |
| | | { |
| | | vec = (Vector3)StackObject.ToObject(a, intp.AppDomain, mStack); |
| | | intp.Free(ptr); |
| | | } |
| | | } |
| | | |
| | | public void PushVector3(ref Vector3 vec, ILIntepreter intp, StackObject* ptr, IList<object> mStack) |
| | | { |
| | | intp.AllocValueType(ptr, CLRType); |
| | | var dst = *((StackObject**)&ptr->Value); |
| | | CopyValueTypeToStack(ref vec, dst, mStack); |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 5d1e5f2c3e980eb4ca3a46ab89ee9ff2 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System.Collections.Generic; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using UnityEngine; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 热更工程使用monovehavior的基础代理类 |
| | | /// </summary> |
| | | public class ILBehaviourProxy : WidgetBehavior |
| | | { |
| | | [SerializeField] |
| | | [Tooltip("Logic工程的代码,例:命名空间.类名")] |
| | | List<string> classNames; |
| | | Dictionary<string, ILBehaviourHolder> ilBehaviourHolders = new Dictionary<string, ILBehaviourHolder>(); |
| | | AppDomain appDomain |
| | | { |
| | | get { return ILRuntimeLoader.Instance.appDomain; } |
| | | } |
| | | |
| | | private void Init() |
| | | { |
| | | InitWidgts(); |
| | | ilBehaviourHolders.Clear(); |
| | | var baseType = appDomain.LoadedTypes["BaseILBehaviour"]; |
| | | foreach (var name in classNames) |
| | | { |
| | | if (ilBehaviourHolders.ContainsKey(name)) |
| | | { |
| | | DebugEx.LogErrorFormat("ILBehaviour 脚本代码有重复项:{0}", name); |
| | | continue; |
| | | } |
| | | var obj = appDomain.Instantiate(name); |
| | | if (obj == null) |
| | | { |
| | | DebugEx.LogErrorFormat("ILBehaviour 脚本代码不存在:{0}", name); |
| | | continue; |
| | | } |
| | | var setProxy = baseType.GetMethod("SetProxy", 1); |
| | | appDomain.Invoke(setProxy, obj, this);//将当前代理对象传过去 |
| | | |
| | | var holder = new ILBehaviourHolder(obj); |
| | | |
| | | //此处用type获取的方法,子类不定义是不会执行Logic工程父类的方法 |
| | | var type = obj.Type; |
| | | |
| | | holder.awake = type.GetMethod("Awake"); |
| | | holder.start = type.GetMethod("Start"); |
| | | holder.onEnable = type.GetMethod("OnEnable"); |
| | | holder.onDisable = type.GetMethod("OnDisable"); |
| | | holder.update = type.GetMethod("Update"); |
| | | holder.fixedUpdate = type.GetMethod("FixedUpdate"); |
| | | holder.lateUpdate = type.GetMethod("LateUpdate"); |
| | | holder.onDestroy = type.GetMethod("OnDestroy", 0); |
| | | |
| | | //baseType 获取的方法,才会执行父类Logic工程的父类方法,但同时也不会调用子类重写的方法 |
| | | holder.dipose = baseType.GetMethod("Dipose", 0); |
| | | |
| | | ilBehaviourHolders.Add(name, holder); |
| | | } |
| | | } |
| | | |
| | | //获取IL热更工程的脚本实例,供热更工程调用,不要在主工程使用 |
| | | public object GetILBehaviour(string name) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | return holder.instance; |
| | | else |
| | | return null; |
| | | } |
| | | |
| | | private void Awake() |
| | | { |
| | | Init(); |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.awake != null) |
| | | appDomain.Invoke(holder.awake, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void Start() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.start != null) |
| | | appDomain.Invoke(holder.start, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void OnEnable() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.onEnable != null) |
| | | appDomain.Invoke(holder.onEnable, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void OnDisable() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.onDisable != null) |
| | | appDomain.Invoke(holder.onDisable, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void Update() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.update != null) |
| | | appDomain.Invoke(holder.update, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void FixedUpdate() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.fixedUpdate != null) |
| | | appDomain.Invoke(holder.fixedUpdate, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (holder.lateUpdate != null) |
| | | appDomain.Invoke(holder.lateUpdate, holder.instance); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | |
| | | foreach (var name in classNames) |
| | | { |
| | | ILBehaviourHolder holder; |
| | | if (ilBehaviourHolders.TryGetValue(name, out holder)) |
| | | { |
| | | if (appDomain != null && holder.onDestroy != null) |
| | | appDomain?.Invoke(holder.onDestroy, holder.instance); |
| | | if (appDomain != null && holder.dipose != null) |
| | | appDomain?.Invoke(holder.dipose, holder.instance); |
| | | } |
| | | } |
| | | ilBehaviourHolders.Clear(); |
| | | } |
| | | |
| | | private class ILBehaviourHolder |
| | | { |
| | | public object instance; |
| | | public IMethod awake, start, onEnable, onDisable, update, fixedUpdate, lateUpdate, onDestroy; |
| | | public IMethod dipose; |
| | | |
| | | public ILBehaviourHolder(object instance) |
| | | { |
| | | this.instance = instance; |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 0972c9814fd923f459dfe2411b6ccb50 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using Snxxz.UI; |
| | | using UnityEngine; |
| | | |
| | | /// <summary> |
| | | /// 热更工程使用一级窗口的基础代理类 |
| | | /// </summary> |
| | | public class ILOneLevelWindowProxy : OneLevelWin |
| | | { |
| | | |
| | | ILTypeInstance obj; |
| | | |
| | | IMethod bindController, addListeners, onPreOpen, onAfterOpen, onPreClose, onAfterClose, onDestroy, lateUpdate, onActived; |
| | | IMethod dipose; |
| | | AppDomain appDomain |
| | | { |
| | | get { return ILRuntimeLoader.Instance.appDomain; } |
| | | } |
| | | private void Init() |
| | | { |
| | | InitWidgts(); |
| | | //使用与预制同名的代码文件 |
| | | var windowName = gameObject.name; |
| | | var baseType = appDomain.LoadedTypes["BaseILWindow"]; |
| | | obj = appDomain.Instantiate(windowName); |
| | | if (obj == null) |
| | | { |
| | | DebugEx.LogErrorFormat("ILWindow 热更代码不存在:{0}", windowName); |
| | | return; |
| | | } |
| | | var setProxy = baseType.GetMethod("SetProxy", 1); |
| | | appDomain.Invoke(setProxy, obj, this);//将当前代理对象传过去 |
| | | |
| | | //此处用type获取的方法,子类不定义是不会执行Logic工程父类的方法 |
| | | var type = obj.Type; |
| | | |
| | | bindController = type.GetMethod("BindController"); |
| | | addListeners = type.GetMethod("AddListeners"); |
| | | onPreOpen = type.GetMethod("OnPreOpen"); |
| | | onAfterOpen = type.GetMethod("OnAfterOpen"); |
| | | onPreClose = type.GetMethod("OnPreClose"); |
| | | onAfterClose = type.GetMethod("OnAfterClose"); |
| | | onDestroy = type.GetMethod("OnDestroy"); |
| | | |
| | | lateUpdate = type.GetMethod("LateUpdate"); |
| | | onActived = type.GetMethod("OnActived"); |
| | | |
| | | //baseType 获取的方法,才会执行父类Logic工程的父类方法,但同时也不会调用子类重写的方法 |
| | | dipose = baseType.GetMethod("Dipose", 0); |
| | | } |
| | | |
| | | public void CloseAllChildWindow() |
| | | { |
| | | CloseSubWindows(); |
| | | } |
| | | |
| | | protected override void OnActived() |
| | | { |
| | | if (onActived != null) |
| | | appDomain.Invoke(onActived, obj); |
| | | } |
| | | |
| | | protected override void LateUpdate() |
| | | { |
| | | if (lateUpdate != null) |
| | | appDomain.Invoke(lateUpdate, obj); |
| | | } |
| | | |
| | | protected override void BindController() |
| | | { |
| | | Init(); |
| | | if (bindController != null) |
| | | appDomain.Invoke(bindController, obj); |
| | | } |
| | | protected override void AddListeners() |
| | | { |
| | | if (addListeners != null) |
| | | appDomain.Invoke(addListeners, obj); |
| | | } |
| | | protected override void OnPreOpen() |
| | | { |
| | | if (onPreOpen != null) |
| | | appDomain.Invoke(onPreOpen, obj); |
| | | } |
| | | protected override void OnAfterOpen() |
| | | { |
| | | if (onAfterOpen != null) |
| | | appDomain.Invoke(onAfterOpen, obj); |
| | | } |
| | | protected override void OnPreClose() |
| | | { |
| | | if (onPreClose != null) |
| | | appDomain.Invoke(onPreClose, obj); |
| | | } |
| | | protected override void OnAfterClose() |
| | | { |
| | | if (onAfterClose != null) |
| | | appDomain.Invoke(onAfterClose, obj); |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | if (onDestroy != null) |
| | | appDomain?.Invoke(onDestroy, obj); |
| | | if (dipose != null) |
| | | appDomain?.Invoke(dipose, obj); |
| | | bindController = null; |
| | | addListeners = null; |
| | | onPreOpen = null; |
| | | onAfterOpen = null; |
| | | onPreClose = null; |
| | | onAfterClose = null; |
| | | onDestroy = null; |
| | | lateUpdate = null; |
| | | onActived = null; |
| | | obj = null; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: a35321404ae3e28439ce53bec5fd2d55 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using ILCrossBinding; |
| | | using ILRuntime.Mono.Cecil.Pdb; |
| | | using Snxxz.UI; |
| | | using UnityEngine; |
| | | |
| | | public class ILRuntimeLoader : SingletonMonobehaviour<ILRuntimeLoader> |
| | | { |
| | | FileStream dllFS, pdbFS; |
| | | |
| | | private ILRuntime.Runtime.Enviorment.AppDomain _appdomain; |
| | | |
| | | public ILRuntime.Runtime.Enviorment.AppDomain appDomain |
| | | { |
| | | get |
| | | { |
| | | if (_appdomain == null) |
| | | DebugEx.Log("AppDomain 调用时为空!"); |
| | | return _appdomain; |
| | | } |
| | | } |
| | | |
| | | public void Init() |
| | | { |
| | | LoadILRuntime(); |
| | | //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler |
| | | #if UNITY_EDITOR |
| | | _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; |
| | | #endif |
| | | //对LitJson进行注册 |
| | | LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(_appdomain); |
| | | RegisterCrossBindingAdaptor(); |
| | | RegisterValueTypeBinder(); |
| | | RegisterDelegate(); |
| | | #if UNITY_EDITOR |
| | | // CLRBindings 是动态生成出来的,editor下可能不存在,所以使用反射方式调用 |
| | | var type = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings"); |
| | | if (type != null) |
| | | { |
| | | var m = type.GetMethod("Initialize"); |
| | | m.Invoke(null, new object[] { appDomain }); |
| | | } |
| | | #else |
| | | ILRuntime.Runtime.Generated.CLRBindings.Initialize(_appdomain); |
| | | #endif |
| | | } |
| | | |
| | | void LoadILRuntime() |
| | | { |
| | | _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); |
| | | var dllPath = string.Empty; |
| | | var pdbPath = string.Empty; |
| | | if (AssetSource.logicFromEditor) |
| | | { |
| | | dllPath = ResourcesPath.ResourcesOutAssetPath + "logic/Logic.dll.bytes"; |
| | | pdbPath = ResourcesPath.ResourcesOutAssetPath + "logic/Logic.pdb"; |
| | | } |
| | | else |
| | | { |
| | | dllPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.dll.bytes"); |
| | | pdbPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.pdb"); |
| | | } |
| | | if (!File.Exists(dllPath)) |
| | | { |
| | | DebugEx.LogErrorFormat("找不到热更代码:{0}", dllPath); |
| | | return; |
| | | } |
| | | |
| | | dllFS = new FileStream(dllPath, FileMode.Open); |
| | | if (VersionConfig.Get().debugVersion && File.Exists(pdbPath)) |
| | | pdbFS = new FileStream(pdbPath, FileMode.Open); |
| | | _appdomain.LoadAssembly(dllFS, pdbFS, new PdbReaderProvider()); |
| | | } |
| | | |
| | | //注册跨域继承适配器 |
| | | private void RegisterCrossBindingAdaptor() |
| | | { |
| | | appDomain.RegisterCrossBindingAdaptor(new CoroutineAdapter()); |
| | | appDomain.RegisterCrossBindingAdaptor(new DtcBasicAdapter()); |
| | | appDomain.RegisterCrossBindingAdaptor(new GameNetPackBasicAdapter()); |
| | | } |
| | | |
| | | //注册值类型绑定 |
| | | private void RegisterValueTypeBinder() |
| | | { |
| | | appDomain.RegisterValueTypeBinder(typeof(Vector3), new Vector3Binder()); |
| | | appDomain.RegisterValueTypeBinder(typeof(Quaternion), new QuaternionBinder()); |
| | | appDomain.RegisterValueTypeBinder(typeof(Vector2), new Vector2Binder()); |
| | | } |
| | | |
| | | //注册委托 |
| | | private void RegisterDelegate() |
| | | { |
| | | //无返回值 |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<long>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<string>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<float>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<double>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<byte[]>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<bool, bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<bool, string>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, string>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, float>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<string, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, bool, string>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<bool, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<ulong>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<uint>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.Operation>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<float, Vector2>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<int, Transform>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Vector2>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Vector3>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Transform>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<GameObject>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Component>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<E_AttackMode>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<PlayerDataType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<PlayerDataType, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<List<Vector3>>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<ChatData>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<VoiceHttpRequest.VoiceDecodec>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.ComposeMatCell, NeedMatType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<ItemCompoundConfig, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.ComposeMatCell, int, SelectItemType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<GroupType, bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<PackType, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<PackType, string>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<PackType, int, int>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<SystemSwitch, bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<ChatBoolType, bool>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<E_NpcType, int, uint>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<TeamInviteType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Snxxz.UI.PlayerDetails.DetailType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<FunctionUnlockType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<TreasureCategory>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<Window>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<TimeMgr.SyntonyType>(); |
| | | appDomain.DelegateManager.RegisterMethodDelegate<DateTime>(); |
| | | |
| | | appDomain.DelegateManager.RegisterDelegateConvertor<UnityEngine.Events.UnityAction>((action) => |
| | | { |
| | | return new UnityEngine.Events.UnityAction(() => |
| | | { |
| | | ((System.Action)action)(); |
| | | }); |
| | | }); |
| | | |
| | | //有返回值 |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<int>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<bool>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<long>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<string>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<float>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<double>(); |
| | | appDomain.DelegateManager.RegisterFunctionDelegate<int, bool>(); |
| | | } |
| | | |
| | | public void LaunchStart() |
| | | { |
| | | _appdomain.Invoke("GameLogicMgr", "Init", null, null); |
| | | } |
| | | |
| | | protected override void OnDestroy() |
| | | { |
| | | base.OnDestroy(); |
| | | #if UNITY_EDITOR |
| | | var type = Type.GetType("ILRuntime.Runtime.Generated.CLRBindings"); |
| | | if (type != null) |
| | | { |
| | | var m = type.GetMethod("Shutdown"); |
| | | m.Invoke(null, new object[] { appDomain }); |
| | | } |
| | | #else |
| | | ILRuntime.Runtime.Generated.CLRBindings.Shutdown(appDomain); |
| | | #endif |
| | | dllFS?.Close(); |
| | | pdbFS?.Close(); |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 3bd1d701cd6c1cb45913ed0999ced256 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using Snxxz.UI; |
| | | using UnityEngine; |
| | | |
| | | /// <summary> |
| | | /// 热更工程使用window的基础代理类 |
| | | /// </summary> |
| | | public class ILWindowProxy : Window |
| | | { |
| | | ILTypeInstance obj; |
| | | |
| | | IMethod bindController, addListeners, onPreOpen, onAfterOpen, onPreClose, onAfterClose, onDestroy, lateUpdate, onActived; |
| | | IMethod dipose; |
| | | AppDomain appDomain |
| | | { |
| | | get { return ILRuntimeLoader.Instance.appDomain; } |
| | | } |
| | | private void Init() |
| | | { |
| | | InitWidgts(); |
| | | //使用与预制同名的代码文件 |
| | | var windowName =gameObject.name; |
| | | var baseType = appDomain.LoadedTypes["BaseILWindow"]; |
| | | obj = appDomain.Instantiate(windowName); |
| | | if (obj == null) |
| | | { |
| | | DebugEx.LogErrorFormat("ILWindow 热更代码不存在:{0}", windowName); |
| | | return; |
| | | } |
| | | var setProxy = baseType.GetMethod("SetProxy", 1); |
| | | appDomain.Invoke(setProxy, obj, this);//将当前代理对象传过去 |
| | | |
| | | //此处用type获取的方法,子类不定义是不会执行Logic工程父类的方法 |
| | | var type = obj.Type; |
| | | |
| | | bindController = type.GetMethod("BindController"); |
| | | addListeners = type.GetMethod("AddListeners"); |
| | | onPreOpen = type.GetMethod("OnPreOpen"); |
| | | onAfterOpen = type.GetMethod("OnAfterOpen"); |
| | | onPreClose = type.GetMethod("OnPreClose"); |
| | | onAfterClose = type.GetMethod("OnAfterClose"); |
| | | onDestroy = type.GetMethod("OnDestroy"); |
| | | |
| | | lateUpdate = type.GetMethod("LateUpdate"); |
| | | onActived = type.GetMethod("OnActived"); |
| | | |
| | | //baseType 获取的方法,才会执行父类Logic工程的父类方法,但同时也不会调用子类重写的方法 |
| | | dipose = baseType.GetMethod("Dipose", 0); |
| | | } |
| | | |
| | | protected override void OnActived() |
| | | { |
| | | if (onActived != null) |
| | | appDomain.Invoke(onActived, obj); |
| | | } |
| | | |
| | | protected override void LateUpdate() |
| | | { |
| | | if (lateUpdate != null) |
| | | appDomain.Invoke(lateUpdate, obj); |
| | | } |
| | | |
| | | protected override void BindController() |
| | | { |
| | | Init(); |
| | | if (bindController != null) |
| | | appDomain.Invoke(bindController, obj); |
| | | } |
| | | protected override void AddListeners() |
| | | { |
| | | if (addListeners != null) |
| | | appDomain.Invoke(addListeners, obj); |
| | | } |
| | | protected override void OnPreOpen() |
| | | { |
| | | if (onPreOpen != null) |
| | | appDomain.Invoke(onPreOpen, obj); |
| | | } |
| | | protected override void OnAfterOpen() |
| | | { |
| | | if (onAfterOpen != null) |
| | | appDomain.Invoke(onAfterOpen, obj); |
| | | } |
| | | protected override void OnPreClose() |
| | | { |
| | | if (onPreClose != null) |
| | | appDomain.Invoke(onPreClose, obj); |
| | | } |
| | | protected override void OnAfterClose() |
| | | { |
| | | if (onAfterClose != null) |
| | | appDomain.Invoke(onAfterClose, obj); |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | if (onDestroy != null) |
| | | appDomain?.Invoke(onDestroy, obj); |
| | | if (dipose != null) |
| | | appDomain?.Invoke(dipose, obj); |
| | | bindController = null; |
| | | addListeners = null; |
| | | onPreOpen = null; |
| | | onAfterOpen = null; |
| | | onPreClose = null; |
| | | onAfterClose = null; |
| | | onDestroy = null; |
| | | lateUpdate = null; |
| | | onActived = null; |
| | | obj = null; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: dfecc37f6c13b544d83e80e8a1dda3f7 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: a36d462b97cf6824cb7d430aaeb583f7 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using UnityEngine; |
| | | using System.Collections.Generic; |
| | | using ILRuntime.Other; |
| | | using System; |
| | | using System.Collections; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.CLR.Method; |
| | | |
| | | namespace ILCrossBinding |
| | | { |
| | | public class CoroutineAdapter : CrossBindingAdaptor |
| | | { |
| | | public override Type BaseCLRType |
| | | { |
| | | get |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public override Type[] BaseCLRTypes |
| | | { |
| | | get |
| | | { |
| | | //跨域继承只能有1个Adapter,因此应该尽量避免一个类同时实现多个外部接口,对于coroutine来说是IEnumerator<object>,IEnumerator和IDisposable, |
| | | //ILRuntime虽然支持,但是一定要小心这种用法,使用不当很容易造成不可预期的问题 |
| | | //日常开发如果需要实现多个DLL外部接口,请在Unity这边先做一个基类实现那些个接口,然后继承那个基类 |
| | | return new Type[] { typeof(IEnumerator<object>), typeof(IEnumerator), typeof(IDisposable) }; |
| | | } |
| | | } |
| | | |
| | | public override Type AdaptorType |
| | | { |
| | | get |
| | | { |
| | | return typeof(Adaptor); |
| | | } |
| | | } |
| | | |
| | | public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | return new Adaptor(appdomain, instance); |
| | | } |
| | | //Coroutine生成的类实现了IEnumerator<System.Object>, IEnumerator, IDisposable,所以都要实现,这个可以通过reflector之类的IL反编译软件得知 |
| | | internal class Adaptor : IEnumerator<System.Object>, IEnumerator, IDisposable, CrossBindingAdaptorType |
| | | { |
| | | ILTypeInstance instance; |
| | | ILRuntime.Runtime.Enviorment.AppDomain appdomain; |
| | | |
| | | public Adaptor() |
| | | { |
| | | |
| | | } |
| | | |
| | | public Adaptor(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | this.appdomain = appdomain; |
| | | this.instance = instance; |
| | | } |
| | | |
| | | public ILTypeInstance ILInstance { get { return instance; } } |
| | | |
| | | IMethod mCurrentMethod; |
| | | bool mCurrentMethodGot; |
| | | public object Current |
| | | { |
| | | get |
| | | { |
| | | if (!mCurrentMethodGot) |
| | | { |
| | | mCurrentMethod = instance.Type.GetMethod("get_Current", 0); |
| | | if (mCurrentMethod == null) |
| | | { |
| | | //这里写System.Collections.IEnumerator.get_Current而不是直接get_Current是因为coroutine生成的类是显式实现这个接口的,通过Reflector等反编译软件可得知 |
| | | //为了兼容其他只实现了单一Current属性的,所以上面先直接取了get_Current |
| | | mCurrentMethod = instance.Type.GetMethod("System.Collections.IEnumerator.get_Current", 0); |
| | | } |
| | | mCurrentMethodGot = true; |
| | | } |
| | | |
| | | if (mCurrentMethod != null) |
| | | { |
| | | var res = appdomain.Invoke(mCurrentMethod, instance, null); |
| | | return res; |
| | | } |
| | | else |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | IMethod mDisposeMethod; |
| | | bool mDisposeMethodGot; |
| | | public void Dispose() |
| | | { |
| | | if (!mDisposeMethodGot) |
| | | { |
| | | mDisposeMethod = instance.Type.GetMethod("Dispose", 0); |
| | | if (mDisposeMethod == null) |
| | | { |
| | | mDisposeMethod = instance.Type.GetMethod("System.IDisposable.Dispose", 0); |
| | | } |
| | | mDisposeMethodGot = true; |
| | | } |
| | | |
| | | if (mDisposeMethod != null) |
| | | { |
| | | appdomain.Invoke(mDisposeMethod, instance, null); |
| | | } |
| | | } |
| | | |
| | | IMethod mMoveNextMethod; |
| | | bool mMoveNextMethodGot; |
| | | public bool MoveNext() |
| | | { |
| | | if (!mMoveNextMethodGot) |
| | | { |
| | | mMoveNextMethod = instance.Type.GetMethod("MoveNext", 0); |
| | | mMoveNextMethodGot = true; |
| | | } |
| | | |
| | | if (mMoveNextMethod != null) |
| | | { |
| | | return (bool)appdomain.Invoke(mMoveNextMethod, instance, null); |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | IMethod mResetMethod; |
| | | bool mResetMethodGot; |
| | | public void Reset() |
| | | { |
| | | if (!mResetMethodGot) |
| | | { |
| | | mResetMethod = instance.Type.GetMethod("Reset", 0); |
| | | mResetMethodGot = true; |
| | | } |
| | | |
| | | if (mResetMethod != null) |
| | | { |
| | | appdomain.Invoke(mResetMethod, instance, null); |
| | | } |
| | | } |
| | | |
| | | public override string ToString() |
| | | { |
| | | IMethod m = appdomain.ObjectType.GetMethod("ToString", 0); |
| | | m = instance.Type.GetVirtualMethod(m); |
| | | if (m == null || m is ILMethod) |
| | | { |
| | | return instance.ToString(); |
| | | } |
| | | else |
| | | return instance.Type.FullName; |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 2f8dde6199bfcaa46b09411a7a942d47 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | namespace ILCrossBinding |
| | | { |
| | | public class DtcBasicAdapter : CrossBindingAdaptor |
| | | { |
| | | static CrossBindingMethodInfo<global::GameNetPackBasic> mDone_0 = new CrossBindingMethodInfo<global::GameNetPackBasic>("Done"); |
| | | public override Type BaseCLRType |
| | | { |
| | | get |
| | | { |
| | | return typeof(global::DtcBasic); |
| | | } |
| | | } |
| | | |
| | | public override Type AdaptorType |
| | | { |
| | | get |
| | | { |
| | | return typeof(Adapter); |
| | | } |
| | | } |
| | | |
| | | public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | return new Adapter(appdomain, instance); |
| | | } |
| | | |
| | | public class Adapter : global::DtcBasic, CrossBindingAdaptorType |
| | | { |
| | | ILTypeInstance instance; |
| | | ILRuntime.Runtime.Enviorment.AppDomain appdomain; |
| | | |
| | | public Adapter() |
| | | { |
| | | |
| | | } |
| | | |
| | | public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | this.appdomain = appdomain; |
| | | this.instance = instance; |
| | | } |
| | | |
| | | public ILTypeInstance ILInstance { get { return instance; } } |
| | | |
| | | public override void Done(global::GameNetPackBasic vNetPack) |
| | | { |
| | | if (mDone_0.CheckShouldInvokeBase(this.instance)) |
| | | base.Done(vNetPack); |
| | | else |
| | | mDone_0.Invoke(this.instance, vNetPack); |
| | | } |
| | | |
| | | public override string ToString() |
| | | { |
| | | IMethod m = appdomain.ObjectType.GetMethod("ToString", 0); |
| | | m = instance.Type.GetVirtualMethod(m); |
| | | if (m == null || m is ILMethod) |
| | | { |
| | | return instance.ToString(); |
| | | } |
| | | else |
| | | return instance.Type.FullName; |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: b3ca5a52e14ab7a4682553c1fb67893d |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | |
| | | namespace ILCrossBinding |
| | | { |
| | | public class GameNetPackBasicAdapter : CrossBindingAdaptor |
| | | { |
| | | static CrossBindingMethodInfo<System.Byte[]> mReadFromBytes_0 = new CrossBindingMethodInfo<System.Byte[]>("ReadFromBytes"); |
| | | static CrossBindingMethodInfo mWriteToBytes_1 = new CrossBindingMethodInfo("WriteToBytes"); |
| | | public override Type BaseCLRType |
| | | { |
| | | get |
| | | { |
| | | return typeof(global::GameNetPackBasic); |
| | | } |
| | | } |
| | | |
| | | public override Type AdaptorType |
| | | { |
| | | get |
| | | { |
| | | return typeof(Adapter); |
| | | } |
| | | } |
| | | |
| | | public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | return new Adapter(appdomain, instance); |
| | | } |
| | | |
| | | public class Adapter : global::GameNetPackBasic, CrossBindingAdaptorType |
| | | { |
| | | ILTypeInstance instance; |
| | | ILRuntime.Runtime.Enviorment.AppDomain appdomain; |
| | | |
| | | public Adapter() |
| | | { |
| | | |
| | | } |
| | | |
| | | public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | this.appdomain = appdomain; |
| | | this.instance = instance; |
| | | } |
| | | |
| | | public ILTypeInstance ILInstance { get { return instance; } } |
| | | |
| | | public override void ReadFromBytes(System.Byte[] vBytes) |
| | | { |
| | | if (mReadFromBytes_0.CheckShouldInvokeBase(this.instance)) |
| | | base.ReadFromBytes(vBytes); |
| | | else |
| | | mReadFromBytes_0.Invoke(this.instance, vBytes); |
| | | } |
| | | |
| | | public override void WriteToBytes() |
| | | { |
| | | if (mWriteToBytes_1.CheckShouldInvokeBase(this.instance)) |
| | | base.WriteToBytes(); |
| | | else |
| | | mWriteToBytes_1.Invoke(this.instance); |
| | | } |
| | | |
| | | public override string ToString() |
| | | { |
| | | IMethod m = appdomain.ObjectType.GetMethod("ToString", 0); |
| | | m = instance.Type.GetVirtualMethod(m); |
| | | if (m == null || m is ILMethod) |
| | | { |
| | | return instance.ToString(); |
| | | } |
| | | else |
| | | return instance.Type.FullName; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: a94c13742be64f647bd0be7f74f5f2a5 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |