Пример #1
0
        public void Start()
        {
            switch (this.CodeMode)
            {
            case CodeMode.Mono:
            {
                Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                assembly      = Assembly.Load(assBytes, pdbBytes);
                this.allTypes = assembly.GetTypes();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }

            case CodeMode.ILRuntime:
            {
                Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                //byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll"));
                //byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb"));

                appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
                this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
                MemoryStream assStream = new MemoryStream(assBytes);
                MemoryStream pdbStream = new MemoryStream(pdbBytes);
                appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                ILHelper.InitILRuntime(appDomain);

                this.allTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
                IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
                start.Run();
                break;
            }

            case CodeMode.Reload:
            {
                byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll"));
                byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb"));

                assembly = Assembly.Load(assBytes, pdbBytes);
                this.LoadLogic();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }
            }
        }
Пример #2
0
        public void Start()
        {
            switch (Init.Instance.CodeMode)
            {
            case CodeMode.Mono:
            {
                Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                assembly      = Assembly.Load(assBytes, pdbBytes);
                this.allTypes = assembly.GetTypes();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }

            case CodeMode.ILRuntime:
            {
                Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");
                byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
                byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

                //byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll"));
                //byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb"));

                ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                MemoryStream assStream = new MemoryStream(assBytes);
                MemoryStream pdbStream = new MemoryStream(pdbBytes);
                appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                ILHelper.InitILRuntime(appDomain);

                this.allTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
                IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
                start.Run();
                break;
            }

            case CodeMode.Reload:
            {
                byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll"));
                byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb"));

                assembly = Assembly.Load(assBytes, pdbBytes);
                LoadHotfix();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }
            }
        }
Пример #3
0
        public void Start()
        {
            switch (this.CodeMode)
            {
            case CodeMode.Mono:
            {
#if !UNITY_EDITOR
                var    ab       = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle");
                byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes;
                byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes;
#else
                byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes;
                byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes;
#endif

                assembly = Assembly.Load(assBytes, pdbBytes);
                foreach (Type type in this.assembly.GetTypes())
                {
                    this.monoTypes[type.FullName]   = type;
                    this.hotfixTypes[type.FullName] = type;
                }
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
#if !UNITY_EDITOR
                ab.Unload(true);
#endif
                break;
            }

            case CodeMode.ILRuntimeJIT:
            case CodeMode.ILRuntime:
            {
#if !UNITY_EDITOR
                var    ab       = AddressablesManager.Instance.SyncLoadAssetBundle("code_assets_all.bundle");
                byte[] assBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset))).bytes;
                byte[] pdbBytes = ((TextAsset)ab.LoadAsset($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset))).bytes;
#else
                byte[] assBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.dll.bytes", typeof(TextAsset)) as TextAsset).bytes;
                byte[] pdbBytes = (AssetDatabase.LoadAssetAtPath($"Assets/AssetsPackage/Code/Code{AssetBundleConfig.Instance.ResVer}.pdb.bytes", typeof(TextAsset)) as TextAsset).bytes;
#endif
                if (this.CodeMode == CodeMode.ILRuntimeJIT)
                {
                    appDomain = new ILRuntime.Runtime.Enviorment.AppDomain(ILRuntime.Runtime.ILRuntimeJITFlags.JITOnDemand);
                }
                else
                {
                    appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                }

#if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE)
                this.appDomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId;
#endif
                if (assStream != null)
                {
                    assStream.Dispose();
                }
                if (pdbStream != null)
                {
                    pdbStream.Dispose();
                }
                assStream = new MemoryStream(assBytes);
                pdbStream = new MemoryStream(pdbBytes);
                appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

                Type[] types = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
                foreach (Type type in types)
                {
                    this.hotfixTypes[type.FullName] = type;
                }

                ILHelper.InitILRuntime(appDomain);

                IStaticMethod start = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
#if !UNITY_EDITOR
                ab.Unload(true);
#endif
                start.Run();
                break;
            }

            case CodeMode.Reload:
            {
                byte[] assBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.dll"));
                byte[] pdbBytes = File.ReadAllBytes(Path.Combine(Define.BuildOutputDir, "Data.pdb"));

                assembly = Assembly.Load(assBytes, pdbBytes);
                this.LoadLogic();
                IStaticMethod start = new MonoStaticMethod(assembly, "ET.Entry", "Start");
                start.Run();
                break;
            }
            }
        }