Beispiel #1
0
        public void LoadHotfixAssembly()
        {
            Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
#if ILRuntime
            this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
            GameObject code     = Game.Scene.GetComponent <ResourcesComponent>().GetAsset <GameObject>("code.unity3d", "Code");
            byte[]     assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[]     mdbBytes = code.Get <TextAsset>("Hotfix.pdb").bytes;

            using (MemoryStream fs = new MemoryStream(assBytes))
                using (MemoryStream p = new MemoryStream(mdbBytes))
                {
                    this.appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
                }

            this.start = new ILStaticMethod(this.appDomain, "Hotfix.Init", "Start", 0);
#else
            GameObject code     = Game.Scene.GetComponent <ResourcesComponent>().GetAsset <GameObject>("code.unity3d", "Code");
            byte[]     assBytes = code.Get <TextAsset>("Hotfix.dll").bytes;
            byte[]     mdbBytes = code.Get <TextAsset>("Hotfix.mdb").bytes;
            this.assembly = Assembly.Load(assBytes, mdbBytes);

            Type hotfixInit = this.assembly.GetType("Hotfix.Init");
            this.start = new MonoStaticMethod(hotfixInit, "Start");
#endif
            Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
        }
Beispiel #2
0
        private void Start()
        {
            try
            {
                //if (Application.unityVersion != "2017.1.0p5")
                //{
                //    Log.Error("请使用Unity2017.1.0p5版本");
                //}

                DontDestroyOnLoad(gameObject);
                Instance = this;


                ObjectEvents.Instance.Add("Model", typeof(Init).Assembly);

                string hotfixPath = $"{Application.dataPath}/../../PC/StreamingAssets/hotfixcode";
#if ILRuntime
                Log.Debug("run in ilruntime mode");

                this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain();

                DllHelper.LoadHotfixAssembly(hotfixPath);
                ILHelper.InitILRuntime();

                this.start             = new ILStaticMethod("Hotfix.Init", "Start", 0);
                this.update            = new ILStaticMethod("Hotfix.Init", "Update", 0);
                this.lateUpdate        = new ILStaticMethod("Hotfix.Init", "LateUpdate", 0);
                this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0);
#else
                Log.Debug("run in mono mode");
                ObjectEvents.Instance.HotfixAssembly = DllHelper.LoadHotfixAssembly(hotfixPath);
                Type hotfixInit = ObjectEvents.Instance.HotfixAssembly.GetType("Hotfix.Init");
                this.start             = new MonoStaticMethod(hotfixInit, "Start");
                this.update            = new MonoStaticMethod(hotfixInit, "Update");
                this.lateUpdate        = new MonoStaticMethod(hotfixInit, "LateUpdate");
                this.onApplicationQuit = new MonoStaticMethod(hotfixInit, "OnApplicationQuit");
#endif

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatherComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <BehaviorTreeComponent>();
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.AddComponent <PlayerComponent>();
                Game.Scene.AddComponent <UnitComponent>();
                Game.Scene.AddComponent <ClientFrameComponent>();
                Game.Scene.AddComponent <ClientComponent>();

                // 进入热更新层
                this.start.Run();
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Beispiel #3
0
 public void Add(EntityEventType type, IStaticMethod methodInfo)
 {
     try
     {
         this.infos.Add(type, methodInfo);
     }
     catch (Exception e)
     {
         throw new Exception($"Add EntityEventType MethodInfo Error: {type}", e);
     }
 }
Beispiel #4
0
        private void Start()
        {
            try
            {
                if (Application.unityVersion != "2017.1.0p5")
                {
                    Log.Error("请使用Unity2017.1.0p5版本");
                    return;
                }

                DontDestroyOnLoad(gameObject);
                Instance = this;


                ObjectEvents.Instance.Add("Model", typeof(Init).Assembly);

#if ILRuntime
                Log.Debug("run in ilruntime mode");

                this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                DllHelper.LoadHotfixAssembly();
                ILHelper.InitILRuntime();

                this.start             = new ILStaticMethod("Hotfix.Init", "Start", 0);
                this.update            = new ILStaticMethod("Hotfix.Init", "Update", 0);
                this.lateUpdate        = new ILStaticMethod("Hotfix.Init", "LateUpdate", 0);
                this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0);
#else
                Log.Debug("run in mono mode");
                ObjectEvents.Instance.HotfixAssembly = DllHelper.LoadHotfixAssembly();
                Type hotfixInit = ObjectEvents.Instance.HotfixAssembly.GetType("Hotfix.Init");
                this.start             = new MonoStaticMethod(hotfixInit, "Start");
                this.update            = new MonoStaticMethod(hotfixInit, "Update");
                this.lateUpdate        = new MonoStaticMethod(hotfixInit, "LateUpdate");
                this.onApplicationQuit = new MonoStaticMethod(hotfixInit, "OnApplicationQuit");
#endif
                // 进入热更新层
                this.start.Run();
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Beispiel #5
0
        private async void Start()
        {
            try
            {
                if (Application.unityVersion != "2017.1.0p5")
                {
                    Log.Error("请使用Unity2017.1.0p5版本");
                }

                DontDestroyOnLoad(gameObject);
                Instance = this;


                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);

                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <BehaviorTreeComponent>();
                Game.Scene.AddComponent <PlayerComponent>();
                Game.Scene.AddComponent <UnitComponent>();
                Game.Scene.AddComponent <ClientFrameComponent>();
                Game.Scene.AddComponent <UIComponent>();


                // 下载ab包
                await BundleHelper.DownloadBundle();

                // 加载配置
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d");
                Game.Scene.AddComponent <ConfigComponent>();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");

                Game.Scene.AddComponent <MessageDispatherComponent>();
#if ILRuntime
                Log.Debug("run in ilruntime mode");

                this.AppDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
                Game.EventSystem.LoadHotfixDll();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
                ILHelper.InitILRuntime();

                this.start             = new ILStaticMethod("Hotfix.Init", "Start", 0);
                this.update            = new ILStaticMethod("Hotfix.Init", "Update", 0);
                this.lateUpdate        = new ILStaticMethod("Hotfix.Init", "LateUpdate", 0);
                this.onApplicationQuit = new ILStaticMethod("Hotfix.Init", "OnApplicationQuit", 0);
#else
                Log.Debug("run in mono mode");
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle($"code.unity3d");
                Game.EventSystem.LoadHotfixDll();
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle($"code.unity3d");
                Type hotfixInit = Game.EventSystem.HotfixAssembly.GetType("Hotfix.Init");
                this.start             = new MonoStaticMethod(hotfixInit, "Start");
                this.update            = new MonoStaticMethod(hotfixInit, "Update");
                this.lateUpdate        = new MonoStaticMethod(hotfixInit, "LateUpdate");
                this.onApplicationQuit = new MonoStaticMethod(hotfixInit, "OnApplicationQuit");
#endif

                // 进入热更新层
                this.start.Run();

                Game.EventSystem.Run(EventIdType.InitSceneStart);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }