예제 #1
0
    void onLogin(EventMgr.EventData ed)
    {
        MsgReqCreateHero m = new MsgReqCreateHero();

        m.heroID = 1001;
        NetMgr.client.sendMsg((short)MyMsgId.ReqCreateHero, m);
    }
예제 #2
0
    void OnReqCreateHero(NetworkMessage msg)
    {
        Log.i("LanHost OnReqCreateHero", Log.Tag.Net);
        Client client = getClient(msg.conn);

        if (client.playerGUID != 0)
        {        //删除上个角色
            Unit lu = mUnitMgr.getUnit(client.playerGUID);
            if (lu != null)
            {
                lu.decState(UnitState.Exist, true);
            }
        }
        MsgReqCreateHero m = msg.ReadMessage <MsgReqCreateHero> ();
        Player           u = createPlayer(m.heroID, Vector3.zero, Vector3.forward, mClients [msg.conn.connectionId].accoundId);

        client.playerGUID = u.guid;

        //同步其周围玩家信息
        List <Unit> units = mUnitMgr.getUnitInSphere(1, u.pos, 1000);

        for (int i = 0; i < units.Count; ++i)
        {
            Unit o = units[i];
            if (o.guid == u.guid || !o.isState(UnitState.Exist))
            {
                continue;
            }
            MsgCreate reply = new MsgCreate();
            reply.agentId  = o.agentId;
            reply.guid     = o.guid;
            reply.pos      = o.pos;
            reply.dir      = o.dir;
            reply.state    = o.state;
            reply.tid      = o.tid;
            reply.unitType = o.type;
            sendTo(msg.conn.connectionId, (short)MyMsgId.Create, reply);
        }
    }