using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using UnityFusion.CLR.TypeSystem; using UnityFusion.CLR.Method; using UnityFusion.Runtime.Enviorment; using UnityFusion.Runtime.Intepreter; using UnityFusion.Runtime.Stack; using UnityFusion.Reflection; using UnityFusion.CLR.Utils; using UnityEngine; #if DEBUG && !DISABLE_UNITYFUSION_DEBUG using AutoList = System.Collections.Generic.List; #else using AutoList = UnityFusion.Other.UncheckedList; #endif namespace UnityFusion.Runtime.Generated { unsafe class UnityEngine_Component_Binding { public static void Register(UnityFusion.Runtime.Enviorment.AppDomain app) { BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; MethodBase method; Type[] args; Type type = typeof(UnityEngine.Component); args = new Type[] { }; method = type.GetMethod("get_transform", flag, null, args, null); app.RegisterCLRMethodRedirection(method, get_transform_0); Dictionary> genericMethods = new Dictionary>(); List lst = null; foreach (var m in type.GetMethods()) { if (m.IsGenericMethodDefinition) { if (!genericMethods.TryGetValue(m.Name, out lst)) { lst = new List(); genericMethods[m.Name] = lst; } lst.Add(m); } } args = new Type[] {typeof(UnityEngine.Rigidbody)}; if (genericMethods.TryGetValue("GetComponent", out lst)) { foreach (var m in lst) { if (m.MatchGenericParameters(args, typeof(UnityEngine.Rigidbody))) { method = m.MakeGenericMethod(args); app.RegisterCLRMethodRedirection(method, GetComponent_1); break; } } } args = new Type[] { }; method = type.GetMethod("get_gameObject", flag, null, args, null); app.RegisterCLRMethodRedirection(method, get_gameObject_2); // args = new Type[] { }; // method = type.GetMethod("GetComponentInChildren", flag, null, args, null); // app.RegisterCLRMethodRedirection(method, GetComponentInChildren_4); // args = new Type[] {typeof(System.Type)}; // method = type.GetMethod("GetComponentInChildren", flag, null, args, null); // app.RegisterCLRMethodRedirection(method, GetComponentInChildren_2); // args = new Type[] {typeof(System.Type), typeof(System.Boolean)}; // method = type.GetMethod("GetComponentInChildren", flag, null, args, null); // app.RegisterCLRMethodRedirection(method, GetComponentInChildren_3); args = new Type[] {typeof(System.Type), typeof(System.Boolean)}; method = type.GetMethod("GetComponentInParent", flag, null, args, null); app.RegisterCLRMethodRedirection(method, GetComponentInParent_5); args = new Type[] {typeof(System.Type)}; method = type.GetMethod("GetComponentInParent", flag, null, args, null); app.RegisterCLRMethodRedirection(method, GetComponentInParent_6); } static StackObject* get_transform_0(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.Component instance_of_this_method = (UnityEngine.Component) typeof(UnityEngine.Component).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.transform; object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType) obj_result_of_this_method).ILInstance); } return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } static StackObject* GetComponent_1(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.Component instance_of_this_method = (UnityEngine.Component) typeof(UnityEngine.Component).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.GetComponent(); return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } static StackObject* get_gameObject_2(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.Component instance_of_this_method = (UnityEngine.Component) typeof(UnityEngine.Component).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.gameObject; return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } static StackObject* GetComponentInChildren_3(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 3); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Boolean @includeInactive = ptr_of_this_method->Value == 1; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Type @type = (System.Type) typeof(System.Type).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject) typeof(UnityEngine.GameObject).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.GetComponentInChildren(@type, @includeInactive); object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType) obj_result_of_this_method).ILInstance); } return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } static StackObject* GetComponentInChildren_2(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); var tmp_ComponentType = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); var instance = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); GameObject tmp_GameObject = null; switch (instance) { case GameObject tmp_Instance: tmp_GameObject = tmp_Instance; break; case Component tmp_Component: tmp_GameObject = tmp_Component.gameObject; break; case ILTypeInstance tmp_ILTypeInstance: tmp_GameObject = Utility.FindGameFromILTypeInstance(tmp_ILTypeInstance); break; } object res = null; if (tmp_ComponentType is CLRType tmp_ClrType) { res = tmp_GameObject.GetComponentInChildren(tmp_ClrType.TypeForCLR); if (res is CrossBindingAdaptorType crossBindingAdaptorType) { res = crossBindingAdaptorType.ILInstance; } } else if (tmp_ComponentType is UnityFusionType tmp_UnityFusionType) { var tmp_ClrInstances = tmp_GameObject.GetComponentsInChildren(typeof(CrossBindingAdaptorType)) .Cast() .ToArray(); foreach (var tmp_ClrInstance in tmp_ClrInstances) { if (tmp_ClrInstance.ILInstance == null) continue; if (!tmp_ClrInstance.ILInstance.Type.CanAssignTo(tmp_UnityFusionType.ILType)) continue; res = tmp_ClrInstance.ILInstance; break; } } return ILIntepreter.PushObject(__ret, __mStack, res); } static StackObject* GetComponentInChildren_4(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 1); var instance = StackObject.ToObject(__ret, __domain, __mStack); Debug.Log(instance.GetType()); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); UnityEngine.Component instance_of_this_method = (UnityEngine.Component) typeof(UnityEngine.Component).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); Component tmp_Component = null; if (__method.GenericArguments.Length == 1) { tmp_Component = instance_of_this_method.GetComponentInChildren( __method.GenericArguments[0].TypeForCLR is CrossBindingAdaptorType ? __method.GenericArguments[0].ReflectionType : __method.GenericArguments[0].TypeForCLR); } Debug.Log($"{instance_of_this_method.name}/{__method.GenericArguments[0].ReflectionType}"); object obj_result_of_this_method = tmp_Component; if (obj_result_of_this_method is CrossBindingAdaptorType) { return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType) obj_result_of_this_method).ILInstance); } return ILIntepreter.PushObject(__ret, __mStack, tmp_Component); } static StackObject* GetComponentInParent_5(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 3); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Boolean @includeInactive = ptr_of_this_method->Value == 1; ptr_of_this_method = ILIntepreter.Minus(__esp, 2); System.Type @type = (System.Type) typeof(System.Type).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject) typeof(UnityEngine.GameObject).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.GetComponentInParent(@type, @includeInactive); object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType) obj_result_of_this_method).ILInstance); } return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } static StackObject* GetComponentInParent_6(ILIntepreter __intp, StackObject* __esp, AutoList __mStack, CLRMethod __method, bool isNewObj) { UnityFusion.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject* ptr_of_this_method; StackObject* __ret = ILIntepreter.Minus(__esp, 2); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Type @type = (System.Type) typeof(System.Type).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject) typeof(UnityEngine.GameObject).CheckCLRTypes( StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); __intp.Free(ptr_of_this_method); var result_of_this_method = instance_of_this_method.GetComponentInParent(@type); object obj_result_of_this_method = result_of_this_method; if (obj_result_of_this_method is CrossBindingAdaptorType) { return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType) obj_result_of_this_method).ILInstance); } return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); } } }