Exemplo n.º 1
0
        public async void OnLogin()
        {
            try
            {
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(ServerIP);

                Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

                M2C_Reload M2C_Reload = (M2C_Reload)await session.Call(new C2M_Reload()
                {
                    Account = nickname.text, Password = password.text
                });

                //connetEndPoint = NetworkHelper.ToIPEndPoint(M2C_Reload.Message);
                //Session gateSession = Game.Scene.GetComponent<NetOuterComponent>().Create(connetEndPoint);
                //Game.Scene.AddComponent<SessionComponent>().Session = gateSession;
                Game.Scene.AddComponent <SessionComponent>().Session = session;

                G2C_EnterMap G2C_EnterMap = (G2C_EnterMap)await Game.Scene.GetComponent <SessionComponent>().Session.Call(new C2G_EnterMap());

                print("登陆gate成功!");

                // 创建Player
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(G2C_EnterMap.UnitId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                playerComponent.MyPlayer = player;

                uiLogin.SetActive(false);
                uiLobby.SetActive(true);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Exemplo n.º 2
0
        public static async ETVoid EnterMapAsync(string sceneName)
        {
            try
            {
                // 加载Unit资源
                ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
                await resourcesComponent.LoadBundleAsync($"unit.unity3d");

                // 加载场景资源
                await ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundleAsync("map.unity3d");

                // 切换到map场景
                using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>())
                {
                    await sceneChangeComponent.ChangeSceneAsync(sceneName);
                }

                G2C_EnterMap g2CEnterMap = await ETModel.SessionComponent.Instance.Session.Call(new C2G_EnterMap()) as G2C_EnterMap;

                PlayerComponent.Instance.MyPlayer.UnitId = g2CEnterMap.UnitId;

                Game.Scene.AddComponent <OperaComponent>();

                Game.EventSystem.Run(EventIdType.EnterMapFinish);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 3
0
        private async void EnterMap()
        {
            try
            {
                G2C_EnterMap g2CEnterMap = (G2C_EnterMap)await SessionComponent.Instance.Session.Call(new C2G_EnterMap());

                uiLobby.SetActive(false);
                Log.Info("EnterMap...");
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }