Example #1
0
    private void StartGame(GameRoomDto dto)
    {
        Debug.Log("开始游戏");
        SceneMesg sm = new SceneMesg(2, () =>
        {
            Debug.Log("游戏场景加载完毕");
            //将传来的房间数据里的玩家保存并根据位置信息生成对应角色
            //foreach (var item in dto.UserAccDtoDict.Values)
            //{
            //    Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_ADD, item);
            //}
            //foreach (var item in dto.UserTransDto.Values)
            //{
            //    Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_SPAWN, item);
            //}
            foreach (var item in dto.UserAccDtoDict.Keys)
            {
                Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_ADD, dto.UserAccDtoDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_SPAWN, dto.UserTransDto[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_HP, dto.UserHpDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_HG, dto.UserHgDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_KILL, dto.UserKillDict[item]);
            }
        });

        Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sm);
    }
Example #2
0
    public override void OnReceive(int subCode, object value)
    {
        switch (subCode)
        {
        case AccCode.ACC_LOGIN_SREP:
            SceneMesg sMesg = new SceneMesg(1, () => {
                Debug.Log("场景加载成功");
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                //TODO 接受返回的数据刷新视图
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sMesg);
            break;

        case AccCode.ACC_LOGIN_NOACC:
            Dispatch(AreaCode.UI, UIEvent.UI_LOGIN_NOACC, null);
            break;

        case AccCode.ACC_CREATE_SREP:
            SceneMesg sceneMesg = new SceneMesg(1, () => {
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                if (userDto.Account == "0")
                {
                    return;
                }
                ShowToast.MakeToast("创建成功");
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sceneMesg);
            break;

        case AccCode.ACC_RELOAD_SREP:
            SceneMesg Mesg = new SceneMesg(1, () => {
                Debug.Log("场景加载成功");
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                //TODO 接受返回的数据刷新视图
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, Mesg);
            break;

        default:
            break;
        }
    }
Example #3
0
    /// <summary>
    /// 开始游戏
    /// </summary>
    private void StartGame()
    {
        Debug.Log("开始游戏");
        SceneMesg sm = new SceneMesg(2, () =>
        {
            Debug.Log("游戏场景加载完毕");
        });

        Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sm);
        //TODO
        //加载完场景向服务端发一个消息告知服务端,服务端再发送房间数据,或者把开始游戏挪到Game里(不出问题就不弄了
    }
Example #4
0
    private void Exit()
    {
        SceneMesg sceneMesg = new SceneMesg(1, () =>
        {
            string id = PlayerPrefs.GetString("ID");
            Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, id);
        });
        SocketMessage smg = new SocketMessage(OpCode.GAME, GameCode.GAME_EXIT_CERQ, null);

        Dispatch(AreaCode.NET, 0, smg);
        Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sceneMesg);
    }
Example #5
0
    public override void Execute(int eventCode, object message)
    {
        switch (eventCode)
        {
        case SceneEvent.SCENE_LOAD:
            SceneMesg sMesg = message as SceneMesg;
            LoadScene(sMesg);
            break;

        default: break;
        }
    }
Example #6
0
 /// <summary>
 /// 加载场景并且执行加载完成后的回调
 /// </summary>
 /// <param name="sMesg"></param>
 private void LoadScene(SceneMesg sMesg)
 {
     if (sMesg.index != -1)
     {
         SceneManager.LoadScene(sMesg.index);
     }
     else if (sMesg.name != null)
     {
         SceneManager.LoadScene(sMesg.name);
     }
     if (sMesg.onSceneLoaded != null)
     {
         onSceneLoaded = sMesg.onSceneLoaded;
     }
 }
Example #7
0
    private void Enter(GameRoomDto dto)
    {
        if (dto == null)
        {
            smg.Change(OpCode.MATCH, MatchCode.MATCH_ENTER_CREQ, null);
            Dispatch(AreaCode.NET, 0, smg);
            return;
        }
        SceneMesg sm = new SceneMesg(2, () =>
        {
            foreach (var item in dto.UserAccDtoDict.Keys)
            {
                Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_ADD, dto.UserAccDtoDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_PLAYER_SPAWN, dto.UserTransDto[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_HP, dto.UserHpDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_HG, dto.UserHgDict[item]);
                Dispatch(AreaCode.GAME, GameEvent.GAME_SYNC_KILL, dto.UserKillDict[item]);
                //ArmsDto armsDto = new ArmsDto(item, dto.UserArmsDict[item]);
                //Dispatch(AreaCode.FIGHT, FightEvent.FIGHT_SYNC_ARMSTYPS, armsDto);
            }
        });

        Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sm);
    }