예제 #1
0
        private void ILHotfixDllLoadDone(TextAsset asset)
        {
            _ILHotfixDll = asset;

            if (_ILHotfixDll != null)
            {
                _isStartUp = true;
                _appDomain = new AppDomain();
                MemoryStream dllStream = new MemoryStream(_ILHotfixDll.bytes);
                _appDomain.LoadAssembly(dllStream, null, new PdbReaderProvider());

                _ILHotFixTypes.Clear();
                foreach (var item in _appDomain.LoadedTypes.Values)
                {
                    _ILHotFixTypes.Add(item.ReflectionType);
                }

                ILHotfixInitialize();

                _ILHotfixEnvironment = _appDomain.Instantiate("ILHotfixEnvironment");

                if (_ILHotfixEnvironment == null)
                {
                    _isStartUp = false;
                    Log.Error("热更新初始化失败:热更新库中不存在热更新环境 ILHotfixEnvironment!");
                }

                dllStream.Dispose();
            }
            else
            {
                _isStartUp = false;
                Log.Error("热更新初始化失败:未正确加载热更新库文件!");
            }
        }
예제 #2
0
        private void ILHotfixDllLoadDone(TextAsset asset)
        {
            _ILHotfixDll = asset;

            if (_ILHotfixDll != null)
            {
                _isStartUp = true;
                _appDomain = new AppDomain();
                MemoryStream dllStream = new MemoryStream(_ILHotfixDll.bytes);
                _appDomain.LoadAssembly(dllStream, null, new PdbReaderProvider());

                ILHotfixInitialize();

                _ILHotfixEnvironment = _appDomain.Instantiate("ILHotfixEnvironment");

                if (_ILHotfixEnvironment == null)
                {
                    _isStartUp = false;
                    GlobalTools.LogError("热更新初始化失败:热更新库中不存在热更新环境 ILHotfixEnvironment!");
                }

                dllStream.Dispose();
            }
            else
            {
                _isStartUp = false;
                GlobalTools.LogError("热更新初始化失败:未正确加载热更新库文件!");
            }
        }
예제 #3
0
        public static object CreateInstance(Type type)
        {
            string typeName = type.FullName;

            if (FindType(typeName) != null)
            {
                return(appdomain.Instantiate(typeName));
            }
            return(Activator.CreateInstance(type));
        }
예제 #4
0
 public ILInstanceMethod(ILRuntime.Runtime.Enviorment.AppDomain appDomain, string typeName, string methodName, ref object _instance, int paramsCount = 0)
 {
     this.appDomain = appDomain;
     method         = appDomain.LoadedTypes[typeName].GetMethod(methodName, paramsCount);
     if (_instance == null)
     {
         _instance = appDomain.Instantiate(typeName);
     }
     instance = _instance;
 }
예제 #5
0
        public override HotfixObject Instantiate(string rTypeName, params object[] rArgs)
        {
            if (mApp == null)
            {
                return(null);
            }
            var rObject = new HotfixObject(this, rTypeName);

            rObject.Object = mApp.Instantiate(rTypeName, rArgs);
            return(rObject);
        }
예제 #6
0
        public static void SetPackageItemExtension(string url, System.Type type)
        {

#if USE_HOT

            UIObjectFactory.SetPackageItemExtension(url, () => {
                return appDomain.Instantiate<GComponent>(type.FullName);
            });
#else
            UIObjectFactory.SetPackageItemExtension(url, type);
#endif

        }
예제 #7
0
        private void OnILRuntimeInitialized()
        {
#if UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE
            //appdomain.UnityMainThreadID = Thread.CurrentThread.ManagedThreadId;
#endif
            appdomain.RegisterCrossBindingAdaptor(new MonoBehaviourAdapter());

            CLRRedirection();

            string KEY = "委托调用";

            switch (KEY)
            {
            case "静态调用":
            {
                appdomain.Invoke("ILRuntime.Program", "Initialize", null);
            }
            break;

            case "实例调用":
            {
                object script = appdomain.Instantiate("ILRuntime.Main");

                appdomain.Invoke("ILRuntime.Main", "Test", script);
            }
            break;

            case "反射调用":
            {
                var script = appdomain.LoadedTypes["ILRuntime.Main"];

                var type = script.ReflectionType;

                var ctor = type.GetConstructor(new System.Type[0]);

                var obj = ctor.Invoke(null);

                var field = type.GetField("index", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

                field.SetValue(obj, 123456);

                var value = field.GetValue(obj);

                Debug.Log("ID = " + value);
            }
            break;

            default:
                break;
            }
        }
예제 #8
0
        public static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            RegisterFunctionCreateInstance(typeName => appdomain.Instantiate(typeName));
            RegisterFunctionGetRealType(o =>
            {
                var type = o.GetType();
                if (type.FullName == "ILRuntime.Runtime.Intepreter.ILTypeInstance")
                {
                    var ilo = o as ILRuntime.Runtime.Intepreter.ILTypeInstance;
                    type    = ProtoBuf.PType.FindType(ilo.Type.FullName);
                }

                return(type);
            });
        }
        public ILClassInstance CreateInstance(string typeFullName, params object[] args)
        {
            ILClassInstance ilInstance = null;
            object          instance   = appdomain.Instantiate(typeFullName, args);

            if (instance != null)
            {
                ilInstance = ReferencePool.Acquire <ILClassInstance>();

                ilInstance.classInstance = instance;
                ilInstance.type          = appdomain.LoadedTypes[typeFullName];
            }

            return(ilInstance);
        }
예제 #10
0
        public object CreateInstance(string klass)
        {
            var obj = mDomain.Instantiate(klass);

            if (obj != null)
            {
                return(obj);
            }
            var type = Rtti.RttiHelper.GetTypeFromTypeFullName(klass);

            if (type == null)
            {
                return(null);
            }
            return(System.Activator.CreateInstance(type));
        }
예제 #11
0
파일: PType.cs 프로젝트: 404Lcc/Lcc
 public static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appDomain)
 {
     foreach (ILRuntime.CLR.TypeSystem.IType item in appDomain.LoadedTypes.Values)
     {
         RegisterType(item.FullName, item.ReflectionType);
     }
     RegisterFunctionCreateInstance(typeName => appDomain.Instantiate(typeName));
     RegisterFunctionGetRealType((obj) =>
     {
         Type type = obj.GetType();
         if (type.FullName == "ILRuntime.Runtime.Intepreter.ILTypeInstance")
         {
             ILRuntime.Runtime.Intepreter.ILTypeInstance instance = (ILRuntime.Runtime.Intepreter.ILTypeInstance)obj;
             type = FindType(instance.Type.FullName);
         }
         return(type);
     });
 }
예제 #12
0
        public static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain)
        {
            RegisterFunctionCreateInstance(typeName => appdomain.Instantiate(typeName));
            RegisterFunctionGetRealType(o =>
            {
                Type type;
                if (o is ILTypeInstance ins)
                {
                    type = ins.Type.ReflectionType;
                    RegisterType(type.FullName, type);                     //自动注册一下
                }
                else
                {
                    type = o.GetType();
                }

                return(type);
            });
        }
예제 #13
0
        unsafe static StackObject *SetPackageItemExtension_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.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));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.String @url = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            FairyGUI.UIObjectFactory.SetPackageItemExtension(@url, () =>
            {
                return(__domain.Instantiate <GComponent>(@type.FullName));
            });
            // FairyGUI.UIObjectFactory.SetPackageItemExtension (@url, @type);

            return(__ret);
        }
예제 #14
0
        private static object ReadValue(Type type, string[] args, ILRuntime.Runtime.Enviorment.AppDomain domain = null, bool isEditor = false)
        {
            ObjectMetadata info;

            if (!object_metadata.TryGetValue(type, out info))
            {
                info = new ObjectMetadata(type);
                object_metadata.Add(type, info);
            }
            object instance;

            if (domain != null)
            {
                instance = domain.Instantiate(type.FullName);
            }
            else
            {
                instance = Activator.CreateInstance(type);
            }


            ObjectFieldMetadata field;
            object value;

            for (int i = 0; i < info.FieldInfo.Length; i++)
            {
                value = null;
                field = info.FieldInfo[i];
                if (field.IsListListArray)
                {
                    value = GetListListArray(args[i]);
                }
                else if (field.IsListArray)
                {
                    value = GetListArray(args[i]);
                }
                else if (field.IsLang)
                {
                    if (domain != null)
                    {
                        value = domain.Instantiate(field.TypeName, new object[] { args[i] });
                    }
                    else
                    {
                        if (isEditor)
                        {
                            //value = Activator.CreateInstance(typeof(MapEditor.Lang), new object[] { args[i] });
                        }
                        else
                        {
#if REFLECT
                            value = Activator.CreateInstance(Mgr.ILR.GetAssemblyType(field.TypeName), new object[] { args[i] });
#endif
                        }
                    }
                }
                else if (field.IsArray)
                {
                    switch (field.TypeName)
                    {
                    case "Int32[]": value = GetArray_int(args[i]); break;

                    case "Byte[]": value = GetArray_byte(args[i]); break;

                    case "Int16[]": value = GetArray_short(args[i]); break;

                    case "Int64[]": value = GetArray_long(args[i]); break;

                    case "Single[]": value = GetArray_float(args[i]); break;

                    case "Double[]": value = GetArray_double(args[i]); break;

                    case "Boolean[]": value = GetArray_bool(args[i]); break;

                    case "String[]": value = GetArray_string(args[i]); break;
                    }
                }
                else
                {
                    switch (field.TypeName)
                    {
                    case "Int32": value = Int32.Parse(args[i]); break;

                    case "Single": value = Single.Parse(args[i]); break;

                    case "String": value = args[i]; break;

                    case "Boolean": value = Boolean.Parse(args[i]); break;

                    case "Double": value = Double.Parse(args[i]); break;

                    case "Byte": value = Byte.Parse(args[i]); break;

                    case "Int16": value = Int16.Parse(args[i]); break;

                    case "Int64": value = Int64.Parse(args[i]); break;

                    case "DateTime": value = DateTime.Parse(args[i]); break;
                    }
                }
                field.FieldInfo.SetValue(instance, value);
            }
            return(instance);
        }