コード例 #1
0
    void StartGame(Player[] players)
    {
        WorldBase world = WorldManager.CreateWorld <DemoWorld>();

        //TODO 模式选择没用了
        world.SyncRule = SyncRule.Status;

        world.m_RandomSeed = new Random().Next(); //随机一个种子

        for (int i = 0; i < players.Length; i++)
        {
            ConnectionComponent conn = new ConnectionComponent();
            conn.m_session  = players[i].session;
            conn.m_playerID = players[i].playerID;

            SyncComponent sc = new SyncComponent();

            world.CreateEntityImmediately("Player" + players[i].playerID, conn, sc);

            players[i].session.m_connect = conn;

            world.eventSystem.DispatchEvent(ServiceEventDefine.c_playerJoin, conn.Entity);

            Debug.Log("Send Game Start");
            //派发游戏开始消息
            PlayerMatchMsg_c msg = new PlayerMatchMsg_c();
            msg.predictTime = 0;
            msg.isMatched   = true;

            ProtocolAnalysisService.SendMsg(players[i].session, msg);
        }

        world.IsStart = true;
    }