Exemplo n.º 1
0
    // 当所有角色加载场景完毕,通知客户端开始游戏;
    public void StartClientGame()
    {
        NotifyStartGame startGame = new NotifyStartGame();

        startGame.Players = new List <ScnPlayerInfo>();

        for (int i = 0; i < mPlayersList.Count; ++i)
        {
            Player player = mPlayersList[i];

            ScnPlayerInfo playerInfo = new ScnPlayerInfo();
            playerInfo.Name   = player.mNickName;
            playerInfo.UserID = player.UserID;
            playerInfo.GID    = player.gid;
            startGame.Players.Add(playerInfo);
        }
        startGame.ServerStartTime = Time.ElapsedSeconds;

        for (int i = 0; i < mPlayersList.Count; ++i)
        {
            Player player = mPlayersList[i];

            NetWork.NotifyMessage <NotifyStartGame>(player.UserID, STC.STC_StartClienGame, startGame);

            player.PacketAtb();
        }
    }
Exemplo n.º 2
0
    void OnInitPlayers(byte[] data)
    {
        NotifyStartGame startGame = ProtoBufUtils.Deserialize <NotifyStartGame>(data);
        excel_scn_list  scnList   = SceneSystem.Instance.mCurrentScene.mScnLists;

        GameController.mServerStartTime = startGame.ServerStartTime;
        GameController.mClientStartTime = Time.realtimeSinceStartup;

        for (int i = 0; i < startGame.Players.Count; ++i)
        {
            ScnPlayerInfo playerInfo = startGame.Players[i];

            excel_cha_class chaClass = excel_cha_class.Find(mScnLists.temp);
            if (chaClass == null)
            {
                continue;
            }

            excel_cha_list chaList = excel_cha_list.Find(chaClass.chaListID);

            GameObject o = ResourceSystem.Load <GameObject>(chaList.path);
            if (o != null)
            {
                GameObject mainPlayer = GameObject.Instantiate(o);
                Player     player     = mainPlayer.GetComponent <Player>();
                player.gid      = playerInfo.GID;
                player.UserID   = playerInfo.UserID;
                player.mChaList = chaList;

                mainPlayer.transform.position   = new Vector3(82.51f, 7.25f, 34.82f);
                mainPlayer.transform.localScale = new Vector3(chaList.scale[0], chaList.scale[1], chaList.scale[2]);

                mPlayersList.Add(player);
                mCharacterList.Add(player);
                mPlayers.Add(player.gid, player);
                mCharacters.Add(player.gid, player);

                if (GameController.mUserInfo.uid == playerInfo.UserID)
                {
                    player.mEvent += TargetChgEvent;

                    MessageSystem.Instance.MsgDispatch(MessageType.OnSetChaClass, chaClass);

                    GameController.OnPlayerInit(player);
                }
            }

            //ResourceSystem.LoadAsync<GameObject>(chaList.path, (obj) =>
            //{
            //    GameObject o = obj as GameObject;
            //    if (o != null)
            //    {
            //        GameObject mainPlayer = GameObject.Instantiate(o);
            //        Player player = mainPlayer.GetComponent<Player>();
            //        player.gid = playerInfo.GID;
            //        player.UserID = playerInfo.UserID;
            //        player.mChaList = chaList;

            //        mainPlayer.transform.position = new Vector3(82.51f, 7.25f, 34.82f);
            //        mainPlayer.transform.localScale = new Vector3(chaList.scale[0], chaList.scale[1], chaList.scale[2]);

            //        mPlayersList.Add(player);
            //        mCharacterList.Add(player);
            //        mPlayers.Add(player.gid, player);
            //        mCharacters.Add(player.gid, player);

            //        if (GameController.mUserInfo.uid == playerInfo.UserID)
            //        {
            //            player.mEvent += TargetChgEvent;

            //            MessageSystem.Instance.MsgDispatch(MessageType.OnSetChaClass, chaClass);

            //            GameController.OnPlayerInit(player);
            //        }
            //    }
            //});
        }
    }