Пример #1
0
    public static void SerializeIKTarget(CNetworkStream _cStream)
    {
        GameObject          cSelfActor        = CGamePlayers.SelfActor;
        CPlayerIKController cSelfIKController = cSelfActor.GetComponent <CPlayerIKController>();

        if (cSelfActor != null && cSelfIKController.m_RightHandTarget != null)
        {
            // Write rotation states
            _cStream.Write((byte)ENetworkAction.SetRightTransform);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.x);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.y);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.position.z);

            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.x);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.y);
            _cStream.Write((float)cSelfIKController.m_RightHandTarget.rotation.eulerAngles.z);
        }

        if (cSelfActor != null && cSelfIKController.m_LeftHandTarget != null)
        {
            // Write rotation states
            _cStream.Write((byte)ENetworkAction.SetLeftTransform);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.x);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.y);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.position.z);

            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.x);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.y);
            _cStream.Write((float)cSelfIKController.m_LeftHandTarget.rotation.eulerAngles.z);
        }
    }
Пример #2
0
    public static void UnserializeIKTarget(CNetworkPlayer _cNetworkPlayer, CNetworkStream _cStream)
    {
        GameObject cPlayerActor = CGamePlayers.GetPlayerActor(_cNetworkPlayer.PlayerId);

        if (cPlayerActor != null)
        {
            CPlayerIKController cPlayerIKController = cPlayerActor.GetComponent <CPlayerIKController>();

            ENetworkAction eNetworkAction = (ENetworkAction)_cStream.ReadByte();

            switch (eNetworkAction)
            {
            case ENetworkAction.SetRightTransform:
            {
                Vector3 pos = new Vector3();
                Vector3 rot = new Vector3();

                pos.x = _cStream.ReadFloat();
                pos.y = _cStream.ReadFloat();
                pos.z = _cStream.ReadFloat();

                cPlayerIKController.m_RightHandTarget.position = pos;

                rot.x = _cStream.ReadFloat();
                rot.y = _cStream.ReadFloat();
                rot.z = _cStream.ReadFloat();

                cPlayerIKController.m_RightHandTarget.rotation = Quaternion.Euler(rot);

                cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_RightHandTarget.position);
                cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_RightHandTarget.rotation.eulerAngles);
            }
            break;

            case ENetworkAction.SetLeftTransform:
            {
                Vector3 pos = new Vector3();
                Vector3 rot = new Vector3();

                pos.x = _cStream.ReadFloat();
                pos.y = _cStream.ReadFloat();
                pos.z = _cStream.ReadFloat();

                cPlayerIKController.m_LeftHandTarget.position = pos;

                rot.x = _cStream.ReadFloat();
                rot.y = _cStream.ReadFloat();
                rot.z = _cStream.ReadFloat();

                cPlayerIKController.m_LeftHandTarget.rotation = Quaternion.Euler(rot);

                cPlayerIKController.m_RightHandNetworkedPos.Set(cPlayerIKController.m_LeftHandTarget.position);
                cPlayerIKController.m_RightHandNetworkedRot.Set(cPlayerIKController.m_LeftHandTarget.rotation.eulerAngles);
            }
            break;

            default:
                Debug.LogError(string.Format("Unknown network action ({0})", (byte)eNetworkAction));
                break;
            }
        }
    }