コード例 #1
0
        private CodeLoader()
        {
            Dictionary <string, UnityEngine.Object> dictionary = AssetsBundleHelper.LoadBundle("code.unity3d");

            byte[] assBytes = ((TextAsset)dictionary["Code.dll"]).bytes;
            byte[] pdbBytes = ((TextAsset)dictionary["Code.pdb"]).bytes;

#if ILRuntime
            ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
            using (System.IO.MemoryStream assStream = new System.IO.MemoryStream(assBytes))
                using (System.IO.MemoryStream pdbStream = new System.IO.MemoryStream(pdbBytes))
                {
                    appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
                }
            ILHelper.InitILRuntime(appDomain);

            this.hotfixTypes = Type.EmptyTypes;
            this.hotfixTypes = appDomain.LoadedTypes.Values.Select(x => x.ReflectionType).ToArray();
            this.start       = new ILStaticMethod(appDomain, "ET.Entry", "Start", 0);
#else
            System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(assBytes, pdbBytes);
            hotfixTypes = assembly.GetTypes();
            this.start  = new MonoStaticMethod(assembly, "ET.Entry", "Start");
#endif
        }
コード例 #2
0
ファイル: CodeLoader.cs プロジェクト: wikieden/ET
        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;
            }
            }
        }
コード例 #3
0
ファイル: CodeLoader.cs プロジェクト: dajiadousr/ET
        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;
            }
            }
        }
コード例 #4
0
        public void Start()
        {
            if (Define.EnableCodes)
            {
                this.GlobalConfig.LoadMode = LoadMode.Codes;
            }

            switch (this.GlobalConfig.LoadMode)
            {
            case LoadMode.Mono:
            {
                if (Define.EnableCodes)
                {
                    throw new Exception("LoadMode.Mono must remove ENABLE_CODE define, please use ET/ChangeDefine/Remove ENABLE_CODE to Remove define");
                }

                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);


                Dictionary <string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof(Game).Assembly, this.assembly);
                Game.EventSystem.Add(types);

                IStaticMethod start = new StaticMethod(assembly, "ET.Client.Entry", "Start");
                start.Run();
                break;
            }

            case LoadMode.Reload:
            {
                if (Define.EnableCodes)
                {
                    throw new Exception("LoadMode.Reload must remove ENABLE_CODE define, please use ET/ChangeDefine/Remove ENABLE_CODE to Remove define");
                }

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

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

            case LoadMode.Codes:
            {
                if (!Define.EnableCodes)
                {
                    throw new Exception("LoadMode.Codes must add ENABLE_CODE define, please use ET/ChangeDefine/Add ENABLE_CODE to add define");
                }

                Assembly[] assemblies           = AppDomain.CurrentDomain.GetAssemblies();
                Dictionary <string, Type> types = AssemblyHelper.GetAssemblyTypes(assemblies);
                Game.EventSystem.Add(types);
                foreach (Assembly ass in assemblies)
                {
                    string name = ass.GetName().Name;
                    if (name == "Unity.Codes")
                    {
                        this.assembly = ass;
                    }
                }
                IStaticMethod start = new StaticMethod(assembly, "ET.Client.Entry", "Start");
                start.Run();
                break;
            }
            }
        }