Пример #1
0
        private void OnAskName(string[] data)
        {
            // Set this client's ID

            // Send our name to the server
            NetworkSend.Reliable("NAMEIS|" + ConnectedCharacters.MyDatabasePlayer.character_name + "|" + ConnectedCharacters.MyDatabasePlayer.character_id);

            // Create all the other players
            for (int i = 2; i < data.Length; i++)
            {
                string[] d = data[i].Split('%');
                _playerFactory.Spawn(
                    int.Parse(d[0]),
                    d[1],
                    d[2],
                    float.Parse(d[3]), float.Parse(d[4]), float.Parse(d[5]),
                    float.Parse(d[6]), float.Parse(d[7]), float.Parse(d[8]),
                    int.Parse(d[9]),
                    int.Parse(d[10]),
                    int.Parse(d[11]),
                    int.Parse(d[12]),
                    int.Parse(d[13]),
                    int.Parse(d[14]),
                    int.Parse(d[15]),
                    int.Parse(d[16]),
                    int.Parse(d[17]),
                    int.Parse(d[18]),
                    int.Parse(d[19]),
                    float.Parse(d[20]), float.Parse(d[21]), float.Parse(d[22]),
                    bool.Parse(d[23])
                    );
            }
        }
Пример #2
0
        private void OnAskPosition(string[] data)
        {
            if (!NetworkSettings.IsStarted)
            {
                return;
            }

            // Update everyone else
            for (int i = 1; i < data.Length; i++)
            {
                string[] d = data[i].Split('%');

                // Prevent the server from updating us
                if (ConnectedCharacters.MyPlayer.CharacterId != int.Parse(d[0]))
                {
                    Vector3 position = Vector3.zero;
                    position.x = float.Parse(d[1]);
                    position.y = float.Parse(d[2]);
                    position.z = float.Parse(d[3]);

                    Quaternion rotation = Quaternion.identity;
                    rotation.w = float.Parse(d[4]);
                    rotation.x = float.Parse(d[5]);
                    rotation.y = float.Parse(d[6]);
                    rotation.z = float.Parse(d[7]);

                    ConnectedCharacters.Characters[int.Parse(d[0])].LastRealPosition =
                        ConnectedCharacters.Characters[int.Parse(d[0])].RealPosition;
                    ConnectedCharacters.Characters[int.Parse(d[0])].LastRealRotation =
                        ConnectedCharacters.Characters[int.Parse(d[0])].RealRotation;

                    ConnectedCharacters.Characters[int.Parse(d[0])].RealPosition = position;
                    ConnectedCharacters.Characters[int.Parse(d[0])].RealRotation = rotation;

                    ConnectedCharacters.Characters[int.Parse(d[0])].TimeToLerp = float.Parse(d[8]);
                    if (ConnectedCharacters.Characters[int.Parse(d[0])].RealPosition !=
                        ConnectedCharacters.Characters[int.Parse(d[0])].Avatar.transform.position)
                    {
                        ConnectedCharacters.Characters[int.Parse(d[0])].IsLerpingPosition = true;
                    }
                    else
                    {
                        ConnectedCharacters.Characters[int.Parse(d[0])].IsLerpingPosition = false;
                    }

                    if (ConnectedCharacters.Characters[int.Parse(d[0])].RealRotation !=
                        ConnectedCharacters.Characters[int.Parse(d[0])].Avatar.transform.rotation)
                    {
                        ConnectedCharacters.Characters[int.Parse(d[0])].IsLerpingRotation = true;
                    }
                    else
                    {
                        ConnectedCharacters.Characters[int.Parse(d[0])].IsLerpingRotation = false;
                    }

                    ConnectedCharacters.Characters[int.Parse(d[0])].TimeStartedLerping = Time.time;
                }
            }

            // Send our own position
            Vector3    myPosition = ConnectedCharacters.MyPlayer.Avatar.transform.position;
            Quaternion myRotation = ConnectedCharacters.MyPlayer.Avatar.transform.rotation;

            ConnectedCharacters.MyPlayer.TimeBetweenMovementEnd = Time.time;
            string message = "MYPOSITION|" + myPosition.x + '|' + myPosition.y + '|' + myPosition.z + '|' + myRotation.w +
                             '|' + +myRotation.x + '|' + +myRotation.y + '|' + +myRotation.z + '|' +
                             (ConnectedCharacters.MyPlayer.TimeBetweenMovementEnd -
                              ConnectedCharacters.MyPlayer.TimeBetweenMovementStart);

            NetworkSend.Unreliable(message);
            ConnectedCharacters.MyPlayer.TimeBetweenMovementStart = Time.time;
        }