Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (guiJoystackController == null)
     {
         return;
     }
     if (Input.GetButtonDown("Fire2"))
     {
         context.FireEvent(this, EventType.EVT_MOUSE_FIRE2, new MouseFire2EvtArg());
     }
     if (Input.GetButtonDown("Fire1"))
     {
         context.FireEvent(this, EventType.EVT_MOUSE_FIRE1, new MouseFire1EvtArg());
     }
     //更新控制目标的位置
     if (bMoved && target != null)
     {
         //位置的移动
         //Vector3 move = guiJoystackController.movePosNorm * Time.deltaTime * moveSpeed;
         //target.localPosition += move;
         ////从JoytackController移动方向 算出自身的角度
         //angle = Mathf.Atan2(guiJoystackController.movePosNorm.x,
         //    guiJoystackController.movePosNorm.z) * Mathf.Rad2Deg;
         //target.localRotation = Quaternion.Euler(Vector3.up * angle);
     }
 }
Пример #2
0
        public void DoCmd(Cmd cmd, string param, int roleId)
        {
            switch (cmd)
            {
            case Cmd.UseSkill:
                for (int i = 0; i < entities.Count; ++i)
                {
                    if (entities[i].mCharData.clientID == roleId)
                    {
                        (entities[i] as CreatureEntity).DoSkill(int.Parse(param));
                    }
                }
                break;

            case Cmd.Move:
                break;

            case Cmd.Turn:
                break;

            case Cmd.UnitMoveBegin:
            {
                for (int i = 0; i < entities.Count; i++)
                {
                    //单位名字和玩家ID要对应上
                    if (entities[i].mCharData.clientID == roleId && entities[i].mCharData.entityName == param)
                    {
                        if (GlobalClient.GameManager.ViewManager.ViewObjMap.ContainsKey(entities[i].ID))
                        {
                            Actor ac = GlobalClient.GameManager.ViewManager.ViewObjMap[entities[i].ID].actor;
                            UnitMoveBeginEvtArg arg = new UnitMoveBeginEvtArg();
                            arg.actor = ac;
                            context.FireEvent(this, EventType.EVT_UNIT_MOVE_BEGIN, arg);
                        }
                    }
                }
            }
            break;

            case Cmd.UnitMoveEnd:
            {
                for (int i = 0; i < entities.Count; i++)
                {
                    //单位名字和玩家ID要对应上
                    if (entities[i].mCharData.clientID == roleId && entities[i].mCharData.entityName == param)
                    {
                        if (GlobalClient.GameManager.ViewManager.ViewObjMap.ContainsKey(entities[i].ID))
                        {
                            Actor             ac  = GlobalClient.GameManager.ViewManager.ViewObjMap[entities[i].ID].actor;
                            UnitMoveEndEvtArg arg = new UnitMoveEndEvtArg();
                            arg.actor = ac;
                            context.FireEvent(this, EventType.EVT_UNIT_MOVE_END, arg);
                        }
                    }
                }
            }
            break;

            default:
                Debug.LogError("无效命令");
                break;
            }
        }
Пример #3
0
        public void OnMessage(MessageBuffer msg)
        {
            int cproto = msg.ReadInt();

            //Debug.Log(cproto);
            switch (cproto)
            {
            case cProto.CONNECT:
            {
                int id = msg.ReadInt();
                clientID = id;
                Debug.Log("玩家客户端id = " + id);
                //服务器已连接
                ServerOnConnectArg arg = new ServerOnConnectArg();
                arg.ClientID = id;
                m_context.FireEvent(this, EventType.EVT_SERVER_ON_CONNECT, arg);
            }
            break;

            case cProto.READY:
                break;

            //位置同步
            case cProto.SYNC_POS:
                int    clientId = msg.ReadInt();
                int    entityId = msg.ReadInt();
                string pos      = msg.ReadString();
                GameManager.instance.ViewManager.SyncPos(clientId, pos, entityId);
                //Debug.Log(string.Format("玩家 {0} ,pos = {1}", cRoleId ,pos));
                break;

            //同步关键帧k
            case cProto.TO_TEAM_SELECT:
            {
                int             playerID       = msg.ReadInt();
                string          playerName     = msg.ReadString();
                string          playerIconPath = msg.ReadString();
                GamePlayer      playerInfo     = new GamePlayer(playerID, playerName, playerIconPath);
                ToSelectTeamArg arg            = new ToSelectTeamArg();
                arg.playerInfo = playerInfo;
                m_context.FireEvent(this, EventType.EVT_TO_TEAM_SELECT, arg);
                break;
            }

            case cProto.SYNC_KEY:
                //读取服务器帧数
                int servFrameCount = msg.ReadInt();
                //Debug.LogWarning(string.Format("服务器关键帧={0}", servFrameCount));
                GlobalClient.KeyFrameManager.serverKeyFrameNo = servFrameCount;
                //当服务器帧数>=当前客户端帧数的时候,客户端本地帧才更新
                if (servFrameCount >= GlobalClient.KeyFrameManager.curKeyFrameNo)
                {
                    //解析出所有用户的KeyDataList
                    string keyStr = msg.ReadString();
                    //分号分离各个用户的KeyDataList;
                    string[] keyData = keyStr.Split(';');
                    for (int i = 0; i < keyData.Length; ++i)
                    {
                        if (keyData[i] == "")
                        {
                            continue;
                        }
                        KeyFrame kf = new KeyFrame(keyData[i]);
                        //插入关键帧管理器中
                        GlobalClient.KeyFrameManager.AddKeyData(servFrameCount, kf);
                    }
                }
                break;

            case cProto.START:
                //读取玩家列表
                string players = msg.ReadString();
                //创建所有玩家
                GameManager.instance.ViewManager.CreateAllPlayer(players);
                //初始化服务器关键帧为1
                GlobalClient.KeyFrameManager.serverKeyFrameNo = 0;
                //每50毫秒向服务器发送位置信息
                //TimerHeap.AddTimer(0, 50, SycMePos);
                //每100毫秒向服务器关键帧数据
                // TimerHeap.AddTimer(0, 100, SycKey);
                break;
            }
        }