예제 #1
0
파일: Init.cs 프로젝트: ww386362087/ETCore
        private async ETVoid StartAsync()
        {
            try
            {
                DontDestroyOnLoad(gameObject);
                Game.EventSystem.Add(typeof(Init).Assembly);
                ClientConfigHelper.SetConfigHelper();
                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(GlobalConfigComponent.Instance.GlobalProto.GetUrl());

                // 加载配置
                Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d");
                Game.Scene.AddComponent <ConfigComponent>();
                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 <MessageDispatcherComponent>();

                Game.EventSystem.Run(EventIdType.InitSceneStart);

                //测试发送给服务端一条文本消息
                //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);
            }
        }