Example #1
0
        public void MoveTo(Vector3 hitPosition)
        {
            Vector3     destPosition = NavPosition(hitPosition);
            NavMeshPath navMeshPath  = new NavMeshPath();

            var navMeshAgent = _3dObj.gameObject.GetComponent <NavMeshAgent>();

            navMeshAgent.CalculatePath(destPosition, navMeshPath);

            // 能移动到该点
            if (navMeshPath.status != NavMeshPathStatus.PathPartial)
            {
                //navMeshAgent.SetDestination(destPosition);
                Proto.Move proto = new Proto.Move();
                foreach (Vector3 one in navMeshPath.corners)
                {
                    proto.Position.Add(new Proto.Vector3()
                    {
                        X = one.x, Y = one.y, Z = one.z
                    });
                }

                UnityEngine.Debug.Log($"move to. position:{destPosition}");
                NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2SMove, proto);
            }
        }
Example #2
0
 protected override void OnUpdate()
 {
     if (_loginState == UiLoginState.Connect)
     {
         NetworkMgr.GetInstance().Connect(_serverIp, _serverPort, AppType.Login);
         Hide();
         UiMgr.GetInstance().OpenModalBox0("网络连接", $"正在连接服务器...");
         _loginState = UiLoginState.Normal;
     }
 }
Example #3
0
        private void EventNetworkConnected(AppType appType)
        {
            // 发送登录协议
            Proto.AccountCheck protoCheck = new Proto.AccountCheck
            {
                Account  = _inputAccount.text.Trim(),
                Password = Md5(System.Text.Encoding.Default.GetBytes(_inputPassword.text.Trim()))
            };

            NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2LAccountCheck, protoCheck);

            Hide();
            UiMgr.GetInstance().OpenModalBox0("登录消息", "正在验证账号...");
        }
        private void EventNetworkConnected(AppType appType)
        {
            if (appType != AppType.Game)
            {
                return;
            }

            // 发送Token
            Proto.LoginByToken protoToken = new Proto.LoginByToken
            {
                Token   = _token,
                Account = _account,
            };

            NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2GLoginByToken, protoToken);
        }
        private void MsgGameToken(Google.Protobuf.IMessage msg)
        {
            Proto.GameToken gameInfo = msg as Proto.GameToken;
            if (gameInfo == null)
            {
                return;
            }

            _token = gameInfo.Token;

            UiMgr.GetInstance().OpenModalBox0("登录消息", "正在连接游戏服务器...");

            NetworkMgr.GetInstance().Disconnect();
            NetworkMgr.GetInstance().Connect(gameInfo.Ip, gameInfo.Port, AppType.Game);

            _linkAppType = AppType.Game;
        }
        private void OnClickPlayer()
        {
            foreach (var one in _players)
            {
                if (!one.IsOn())
                {
                    continue;
                }

                UiMgr.GetInstance().OpenModalBox0("选择角色", "正在进入地图...");
                Proto.SelectPlayer proto = new Proto.SelectPlayer();
                proto.PlayerSn = one.PlayerSn;

                NetworkMgr.GetInstance().SendPacket(Proto.MsgId.C2LSelectPlayer, proto);
                return;
            }
        }
        private void OnClickCreate( )
        {
            if (string.IsNullOrEmpty(_inputName.text))
            {
                UiMgr.GetInstance( ).OpenModalBox1("创建角色", "角色名不能为空", null);
                return;
            }

            UiMgr.GetInstance( ).OpenModalBox0("创建角色", "角色正在创建中...");
            Proto.CreatePlayer proto = new Proto.CreatePlayer( );
            proto.Name = _inputName.text;
            if (_toggleFemale.isOn)
            {
                proto.Gender = Proto.Gender.Female;
            }
            else
            {
                proto.Gender = Proto.Gender.Male;
            }

            NetworkMgr.GetInstance( ).SendPacket(Proto.MsgId.C2LCreatePlayer, proto);
        }