Пример #1
0
        private async ETVoid StartAsync()
        {
            try
            {
                SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

                DontDestroyOnLoad(gameObject);
                ClientConfigHelper.SetConfigHelper();
                Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly);
                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);

                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();

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

                ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d");
                Game.Scene.AddComponent <ConfigComponent>();
                ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");

                UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001);
                Log.Debug($"config {JsonHelper.ToJson(unitConfig)}");


                //添加指定与网络组件
                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();

                ////添加UI组件
                Game.Scene.AddComponent <UIComponent>();

                Game.Scene.AddComponent <GamerComponent>();

                //加上消息分发组件MessageDispatcherComponent
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                //执行斗地主初始事件,也就是创建LandLogin界面
                Game.EventSystem.Run(UIEventType.LandInitSceneStart);



                ////练习3
                //TestRoom room = ComponentFactory.Create<TestRoom>();
                //room.AddComponent<TimeTestComponent>();
                //room.GetComponent<TimeTestComponent>().Run(Typebehavior.Waiting, 5000);

                //测试发送给服务端一条文本消息
                Session         session        = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
                G2C_TestMessage g2CTestMessage = (G2C_TestMessage)await session.Call(new C2G_TestMessage()
                {
                    Info = "==>>服务端的朋友,你好!收到请回答"
                });
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Пример #2
0
        private async ETVoid StartAsync()
        {
            try
            {
                SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);

                DontDestroyOnLoad(gameObject);
                ClientConfigHelper.SetConfigHelper();
                Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly);
                Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
                //Log.Info(typeof(Core).Assembly.ToString());

                Game.Scene.AddComponent <TimerComponent>();
                Game.Scene.AddComponent <GlobalConfigComponent>();
                Game.Scene.AddComponent <NetOuterComponent>();
                Game.Scene.AddComponent <ResourcesComponent>();
                Game.Scene.AddComponent <PlayerComponent>();
                Game.Scene.AddComponent <UnitComponent>();
                Game.Scene.AddComponent <UIComponent>();

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

                //Game.Hotfix.LoadHotfixAssembly();

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

                Game.Scene.AddComponent <OpcodeTypeComponent>();
                Game.Scene.AddComponent <MessageDispatcherComponent>();

                UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001);
                Log.Debug($"config {JsonHelper.ToJson(unitConfig)}");

                // 网络同步方式组件
                Game.Scene.AddComponent <NetSyncComponent, SyncType>(SyncType.State);

                //Game.Hotfix.GotoHotfix();

                Game.EventSystem.Run(EventIdType.InitSceneStart);

                //Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }