Пример #1
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        //List<int> syncTemp;

        if (stream.isWriting)
        {
            //Debug.Log("Wirting!");
            //syncTemp = puzzle1Answer;

            /*
            for(int i =0;i<syncTemp.Count;i++)
            {
                stream.Serialize(ref syncTemp[i]);
            }
            */
            //stream.Serialize(ref syncTemp);
        }
        else
        {
            //Debug.Log("Received!");
            //stream.Serialize(ref syncTemp);

            /*
            for(int i =0;i<syncTemp.Count;i++)
            {
                syncTemp[i] = puzzle1Answer[i];
            }
            */
            //syncTemp = puzzle1Answer;
        }
    }
Пример #2
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Vector3 syncVelocity = Vector3.zero;
        if (stream.isWriting)
        {
            syncPosition = GetComponent<Rigidbody>().position;
            stream.Serialize(ref syncPosition);

            syncPosition = GetComponent<Rigidbody>().velocity;
            stream.Serialize(ref syncVelocity);

            //finPos = GetComponent<Rigidbody>().transform;
            //Debug.Log("FinPos: " + finPos);
        }
        else
        {
            stream.Serialize(ref syncPosition);
            stream.Serialize(ref syncVelocity);

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            syncEndPosition = syncPosition + syncVelocity * syncDelay;
            syncStartPosition = GetComponent<Rigidbody>().position;
        }
    }
Пример #3
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Vector3 syncVelocity = Vector3.zero;
        if (stream.isWriting)
        {
            syncPosition = rigidbody.position;
            stream.Serialize(ref syncPosition);

            syncPosition = rigidbody.velocity;
            stream.Serialize(ref syncVelocity);
        }
        else
        {
            stream.Serialize(ref syncPosition);
            stream.Serialize(ref syncVelocity);

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            syncEndPosition = syncPosition + syncVelocity * syncDelay;
            syncStartPosition = rigidbody.position;
        }
    }
Пример #4
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        BoardLocation newLocation= new BoardLocation(new IntVector2(0,0), new IntVector2(0,0));
        int maxSpeed = 0;
        IntVector2 direction = new IntVector2(0,0);
        BoardLocation lastBoardLocation = new BoardLocation(new IntVector2( 0, 0), new IntVector2(0,0));

        if (stream.isWriting)
        {
            newLocation = this.boardLocation;
            maxSpeed = this.maxSpeed;
            direction = this.direction;
            lastBoardLocation = this.lastBoardLocation;

            newLocation.Serialize( stream );
            stream.Serialize( ref maxSpeed );
            direction.Serialize( stream );
            lastBoardLocation.Serialize( stream );
        }
        else
        {
            newLocation.DeSerialize( stream );
            stream.Serialize( ref maxSpeed );
            direction.DeSerialize( stream );
            lastBoardLocation.DeSerialize( stream );

            this.boardLocation = newLocation;
            this.maxSpeed = maxSpeed;
            this.direction = direction;
            this.lastBoardLocation = lastBoardLocation;
        }
    }
Пример #5
0
    public void OnSerializeNetworkView2D(BitStream stream, NetworkMessageInfo info,
        UnitActionCommand pUnitActionCommand, bool pIsAlive)
    {
        Transform lTransform = characterController.transform;
        Vector3 lData = Vector3.zero;
        //---------------------------------------------------
        if (stream.isWriting)
        {
            lData = lTransform.position;
            lData.z = yVelocity;
        }
        //---------------------------------------------------
        stream.Serialize(ref lData);
        //---------------------------------------------------
        if (stream.isReading)
        {
            yVelocity = lData.z;
            lData.z = 0f;
            lTransform.position = lData;

            var lDeltaTime = (float)(Network.time - info.timestamp);
            if (lDeltaTime > 0.02f)
                update2D(pUnitActionCommand, UnitFace.getValue(pUnitActionCommand.face),
                    pIsAlive, lDeltaTime * Time.timeScale);
            lastUpdateTime = Time.time;

        }
    }
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (!stream.isWriting)
        {

        }
    }
Пример #7
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if(stream.isWriting) {
            //Position Synchronization
            Vector3 position = transform.position; stream.Serialize(ref position);

            //Rotation Synchronization
            Quaternion rotation = transform.rotation; stream.Serialize(ref rotation);

            //Current Movement
            Vector3 directionVector = motor.inputMoveDirection;
            stream.Serialize(ref directionVector);
        }
        else {
            //Position Synchronization
            Vector3 position = Vector3.zero; stream.Serialize(ref position);
            transform.position = position;

            //Rotation synchronization
            Quaternion rotation = Quaternion.identity; stream.Serialize(ref rotation);
            transform.rotation = rotation;

            //Current Movement
            Vector3 directionVector = Vector3.zero;
            stream.Serialize(ref directionVector);
            motor.inputMoveDirection = directionVector;
        }
    }
Пример #8
0
 public virtual void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     if (_animator != null) {
         foreach (AnimatorControllerParameter param in _animator.parameters) {
             AnimatorControllerParameterType paramType = param.type;
             switch (paramType) {
             case AnimatorControllerParameterType.Bool:
                 bool boolParam = _animator.GetBool (param.nameHash);
                 stream.Serialize (ref boolParam);
                 if (stream.isReading) {
                     _animator.SetBool (param.nameHash, boolParam);
                 }
                 break;
             case AnimatorControllerParameterType.Float:
                 float floatParam = _animator.GetFloat (param.nameHash);
                 stream.Serialize (ref floatParam);
                 if (stream.isReading) {
                     _animator.SetFloat (param.nameHash, floatParam);
                 }
                 break;
             case AnimatorControllerParameterType.Int:
                 int intParam = _animator.GetInteger (param.nameHash);
                 stream.Serialize (ref intParam);
                 if (stream.isReading) {
                     _animator.SetInteger (param.nameHash, intParam);
                 }
                 break;
             }
         }
     }
 }
    void OnSerializeNetworkView( BitStream stream, NetworkMessageInfo info )
    {
        Vector3 syncPosition = Vector3.zero; // для синхронизации позиции
        Vector3 syncVelocity = Vector3.zero; // для синхронизации действующей силы
        Quaternion syncRotation = Quaternion.identity; // для синхронизации поворота

        if ( stream.isWriting ) { // если отправляем в сеть то считываем данные обьекта и отправляем
            syncPosition = rigidbody.position;
            stream.Serialize( ref syncPosition );

            syncPosition = rigidbody.velocity;
            stream.Serialize( ref syncVelocity );

            syncRotation = rigidbody.rotation;
            stream.Serialize( ref syncRotation );
        } else { // иначе считываем из сети
            stream.Serialize( ref syncPosition );
            stream.Serialize( ref syncVelocity );
            stream.Serialize( ref syncRotation );

            syncTime = 0f; // сбрасываем время синхронизации
            syncDelay = Time.time - lastSynchronizationTime; // получаем дельту придыдущей синхронизации
            lastSynchronizationTime = Time.time; // записываем новое время последней синхронизации

            syncEndPosition = syncPosition + syncVelocity * syncDelay; // конечная точка в которую двигаеться обьект
            syncStartPosition = rigidbody.position; // начальная точка равна текущей позиции

            syncEndRotation = syncRotation; // конечный поворот
            syncStartRotation = rigidbody.rotation; // начальный поворот
        }
    }
Пример #10
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Quaternion rot = Quaternion.identity;

        if (stream.isWriting)
        {

            syncPosition = transform.position;
            rot = transform.rotation;

            stream.Serialize(ref syncPosition);

            stream.Serialize(ref rot);
        }
        else
        {
            stream.Serialize(ref syncPosition);
            stream.Serialize(ref rot);

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            syncStartPosition = transform.position;
            syncEndPosition = syncPosition;

            qSrot = transform.rotation;
            qErot = rot;
        }
    }
Пример #11
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncDest = Vector3.zero;
        Vector3 syncPos = Vector3.zero;
        if (stream.isWriting && Network.isServer)
        {
            syncDest = destination;
            syncPos = this.gameObject.transform.position;
            stream.Serialize(ref syncDest);
            stream.Serialize(ref syncPos);
        }
        else if (stream.isReading)
        {
            stream.Serialize(ref syncDest);
            stream.Serialize(ref syncPos);

            destination = syncDest;
            if (agent != null)
                agent.SetDestination (destination);

            /*
            Vector3 diffPos = this.gameObject.transform.position - syncPos;
            if (diffPos.sqrMagnitude >= 1){
                this.gameObject.transform.position = syncPos;
            }
            */
        }
    }
    //Sends or Recieves Serialized variables over the network.
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        //Variable to be used over the network.
        Vector3 syncPosition = Vector3.zero;

        //If you're the owner of the object you are sending the objects position over the network.
        if(stream.isWriting)
        {
            //Set syncPosition to this objects current position.
            syncPosition = transform.position;
            //Send the position over the network.
            stream.Serialize(ref syncPosition);
        }
        //You're recieving the position from the Owner.
        else
        {
            //Serialize the new incoming position.
            stream.Serialize(ref syncPosition);

            syncTime = 0.0f;
            syncDelay = Time.time - lastSyncTime;
            lastSyncTime = Time.time;

            syncStartPosition = transform.position;
            syncEndPosition = syncPosition;
        }
    }
Пример #13
0
    // Update is called once per frame
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        {
            Vector3 position = rigidbody.position;
            Vector3 forward = transform.forward;
            Vector3 velocity = rigidbody.velocity;
            Vector3 angularVelocity = rigidbody.angularVelocity;

            if(stream.isWriting)
            {
                stream.Serialize(ref position);
                stream.Serialize(ref forward);
                stream.Serialize(ref velocity);
                stream.Serialize(ref angularVelocity);
            }
            else
            {
                stream.Serialize(ref position);
                targetPosition = position;

                stream.Serialize(ref forward);
                targetForward = forward;

                stream.Serialize(ref velocity);
                speed = velocity;

                stream.Serialize(ref angularVelocity);
                angularSpeed = angularVelocity;
            }
        }
    }
Пример #14
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        if ((networkView.isMine) && stream.isWriting)
        {
            //Write data to stream
            syncPosition = transform.position;
            stream.Serialize(ref syncPosition);
            print (gameObject.name);
        }
        else
        {
            //Get data from stream
            stream.Serialize(ref syncPosition);

            //Calculate sync delay (ping, kind of)
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;
            NetworkManager.changeMenuDebugStatus("syncDelay: "+syncDelay);

            //Set new start and end position for movement interpolation
            syncStartPosition = syncEndPosition;
            syncEndPosition = syncPosition;
            print (syncStartPosition);
            print ("end: "+syncEndPosition);
        }
    }
Пример #15
0
 protected virtual void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     if (selected == _PlayerOwn || stream.isReading)
     {
         if (stream.isWriting)
         {
             syncPos = pos;
             syncRot = rot;
             //syncVel = controller.velocity;
         }
         stream.Serialize(ref syncPos);
         stream.Serialize(ref syncRot);
         //stream.Serialize(ref syncVel);
         if (stream.isReading)
         {
             if (syncPos == Vector3.zero)
             { }
             else
             {
                 pos = syncPos;
                 rot = syncRot;
             }
             //vel = syncVel;
         }
     }
 }
    /*
    [RPC]
    public void reeling(float angle)
    {

    }
    */
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (stream.isWriting) {

        } else {

        //            if (boat)
        //                transform.position = new Vector3(transform.position.x, boat.transform.position.y + boatOffsetY, transform.position.z);

           /* Quaternion receivedRot = new Quaternion(0, 0, 0, 0);
            stream.Serialize(ref receivedRot);
            Quaternion rotationToUse = receivedRot;
            transform.rotation = rotationToUse;*/

            Vector3 receivedRot = Vector3.zero;
            stream.Serialize (ref receivedRot);
            acceRotationVector = receivedRot;

            Quaternion rotation = Quaternion.LookRotation (receivedRot);
            float angle = Quaternion.Angle (transform.rotation, rotation);

            rotZ = rotation.eulerAngles.z;
            rotX = rotation.eulerAngles.x;
            rotY = rotation.eulerAngles.y;

            if (angle > rotationBreak) {
                transform.rotation = Quaternion.Lerp (transform.rotation, rotation, Time.deltaTime * rotationSpeed);
                // Works -> transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);

        }
        }
    }
Пример #17
0
    public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 pos = observedTransform.position;
        Quaternion rot = observedTransform.rotation;

        if (stream.isWriting) {
            //Debug.Log("Server is writing");
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
        }
        else {
            //This code takes care of the local client!
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            receiver.serverPosition = pos;
            receiver.serverRotation = rot;
            //Smoothly correct clients position
            //receiver.lerpToTarget();

            //Take care of data for interpolating remote objects movements
            // Shift up the buffer
            for ( int i = serverStateBuffer.Length - 1; i >= 1; i-- ) {
                serverStateBuffer[i] = serverStateBuffer[i-1];
            }
            //Override the first element with the latest server info
            serverStateBuffer[0] = new NetworkState((float)info.timestamp, pos, rot);
        }
    }
Пример #18
0
    public void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 pos = observedTransform.position;
        Quaternion rot = observedTransform.rotation;

        if(stream.isWriting) {
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
        }
        else{
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            reciever.serverPos = pos;
            reciever.serverRot = rot;

            reciever.lerpToTarget();

            for( int i = serverStateBuffer.Length - 1; i >= 1;i--){
                serverStateBuffer[i] = serverStateBuffer[i-1];
            }

            serverStateBuffer[0] = new NetState();
            serverStateBuffer[0].setState((float)info.timestamp, pos, rot);
        }
    }
Пример #19
0
    private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (stream.isWriting)
        {
            Debug.Log("Writing.");

            Vector3 pos = this.transform.position;
            Vector3 orientation = this.transform.eulerAngles;

            stream.Serialize(ref pos);
            stream.Serialize(ref orientation);
        }
        else
        {
            Debug.Log("Receiving.");

            Vector3 pos = Vector3.zero;
            Vector3 orientation = Vector3.zero;

            stream.Serialize(ref pos);
            stream.Serialize(ref orientation);

            this.transform.position = pos;
            this.transform.eulerAngles = orientation;
        }
    }
    /* This function is automatically called every time it sends or receives datas.
    (To use for data that constantly changed) */
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Quaternion syncRotation = Quaternion.identity;

        // The player is writing to the stream (= he moves its own Character...)
        if (stream.isWriting)
        {
            syncRotation = transform.localRotation;
            stream.Serialize(ref syncRotation);
        }
        // The ClientInstance of the player's opponent need to be moved
        else
        {
            stream.Serialize(ref syncRotation);

            // Interpolation : smoothing the transition from the old to the new data values
            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            // Prediction : the rotation is "updated" before the new data is received
            syncStartRotation = transform.localRotation;
            syncEndRotation = syncRotation;
        }
    }
Пример #21
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        //locateMarkersAndLimbs();
        Vector3 tempPos = Vector3.zero;
        Quaternion tempRot = Quaternion.identity;

        //ADD THE parentP2 changes here as well! To stop jitter!!

        if((Network.isServer)&&(stream.isWriting))
        {
            if(!parentP1)
            {
                tempPos = transform.position;
                tempRot = transform.rotation;

                stream.Serialize(ref tempPos);
                stream.Serialize(ref tempRot);
            }

        }
        if(Network.isClient)
        {
            if(!parentP1)
            {
                stream.Serialize(ref tempPos);
                stream.Serialize(ref tempRot);

                transform.position = tempPos;
                transform.rotation = tempRot;
            }

        }
    }
 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     if (stream.isWriting)
     {
         Vector3 pos = transform.localPosition;
         Quaternion rot = transform.localRotation;
         stream.Serialize(ref pos);
         stream.Serialize(ref rot);
     }
     else
     {
         Vector3 pos = Vector3.zero;
         Quaternion rot = Quaternion.identity;
         stream.Serialize(ref pos);
         stream.Serialize(ref rot);
         for (int i = m_BufferedState.Length - 1; i >= 1; i--)
         {
             m_BufferedState[i] = m_BufferedState[i - 1];
         }
         State state;
         state.timestamp = info.timestamp;
         state.pos = pos;
         state.rot = rot;
         m_BufferedState[0] = state;
         m_TimestampCount = Mathf.Min(m_TimestampCount + 1, m_BufferedState.Length);
         for (int i = 0; i < m_TimestampCount - 1; i++)
         {
             if (m_BufferedState[i].timestamp < m_BufferedState[i + 1].timestamp)
                 Debug.Log("State inconsistent");
         }
     }
 }
Пример #23
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Quaternion 	_syncDirection 	= Quaternion.identity;
        Vector3 	_syncPosition	= Vector3.zero;
        Vector3 	_syncVelocity 	= Vector3.zero;

        if (stream.isWriting)
        {

            _syncDirection = this.transform.rotation;
            _syncPosition = this.transform.position;
            _syncVelocity = this.rigidbody.velocity;

            stream.Serialize(ref _syncDirection);
            stream.Serialize(ref _syncPosition);
            stream.Serialize(ref _syncVelocity);
        }
        else
        {
            stream.Serialize(ref _syncDirection);
            stream.Serialize(ref _syncPosition);
            stream.Serialize(ref _syncVelocity);
            if(Quaternion.Angle(this.transform.rotation,_syncDirection) > 10   ){
                this.gameObject.transform.rotation = Quaternion.Lerp(this.transform.rotation, _syncDirection,5 );
            }
            if( Vector3.Distance(this.transform.position,_syncPosition) > 10 ){
                this.gameObject.transform.position = Vector3.Lerp(this.transform.position, _syncPosition,5);
            }
            if(Vector3.Distance(this.rigidbody.velocity,_syncVelocity)> 10){
                this.rigidbody.velocity = Vector3.Lerp(this.rigidbody.velocity, _syncVelocity , 5);
            }

        }
    }
Пример #24
0
    public void OnSerialNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        float punch = punchSpeed;
        float direction = directionMultiplyerX;
        float health = HP;
        if (stream.isWriting)
        {

            punch = punchSpeed;
            stream.Serialize(ref punch);

            direction = directionMultiplyerX;
            stream.Serialize(ref direction);

            health = HP;
            stream.Serialize(ref health);
        }
        else
        {
            stream.Serialize(ref punch);
            punchSpeed = punch;

            stream.Serialize(ref direction);
            directionMultiplyerX = direction;

            stream.Serialize(ref health);
            HP = health;

        }
    }
Пример #25
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        float net_currentAmmo = 0;
        float net_maxAmmo = 0;
        float net_ammoRegenRate = 0;

        if (stream.isWriting)
        {
            net_currentAmmo = currentAmmo;
            net_maxAmmo = maxAmmo;
            net_ammoRegenRate = ammoRegenRate;

            stream.Serialize(ref net_currentAmmo);
            stream.Serialize(ref net_maxAmmo);
            stream.Serialize(ref net_ammoRegenRate);
        }
        else if (stream.isReading)
        {
            stream.Serialize(ref net_currentAmmo);
            stream.Serialize(ref net_maxAmmo);
            stream.Serialize(ref net_ammoRegenRate);

            currentAmmo = net_currentAmmo;
            maxAmmo = net_maxAmmo;
            ammoRegenRate = net_ammoRegenRate;
        }
    }
Пример #26
0
    private void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Vector3 syncVelocity = Vector3.zero;
        if (stream.isWriting)
        {
            syncPosition = transform.position;
            stream.Serialize(ref syncPosition);

            syncVelocity = _controller.velocity;
            stream.Serialize(ref syncVelocity);
        }
        else
        {
            stream.Serialize(ref syncPosition);
            stream.Serialize(ref syncVelocity);

            _syncTime = 0f;
            _syncDelay = Time.time - _lastSynchroTime;
            _lastSynchroTime = Time.time;

            _syncEndPosition = syncPosition + syncVelocity * _syncDelay;
            _syncStartPosition = transform.position;
        }
    }
Пример #27
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 pos = observedRigidbody.position;
        Quaternion rot = observedRigidbody.rotation;
        float vel = observedRigidbody.velocity.magnitude;

        if(stream.isWriting)
        {
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref vel);
        }
        else
        {
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref vel);
            receiver.serverPosition = pos;
            receiver.serverRotation = rot;
            receiver.serverVelocity = vel;

            receiver.lerpToTarget();

            for(int i = serverStateBuffer.Length - 1; i >= 1; i--)
            {
                serverStateBuffer[i] = serverStateBuffer[i-1];
            }

            serverStateBuffer[0] = new NetState(info.timestamp, pos, rot);
        }
    }
Пример #28
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        var sync_pos = new Vector3();
        var sync_rot = new Quaternion();
        var sync_hp = 0.0f;

        if (stream.isReading)
        {
            stream.Serialize(ref sync_pos);
            stream.Serialize(ref sync_rot);
            stream.Serialize(ref sync_hp);

            transform.position = sync_pos;
            transform.rotation = sync_rot;
            m_CurrentHP = sync_hp;
        }
        else
        {
            sync_pos = transform.position;
            sync_rot = transform.rotation;
            sync_hp = m_CurrentHP;

            stream.Serialize(ref sync_pos);
            stream.Serialize(ref sync_rot);
            stream.Serialize(ref sync_hp);
        }
    }
Пример #29
0
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 syncPosition = Vector3.zero;
        Quaternion syncRotation = Quaternion.identity;
        Vector3 syncVelocity = Vector3.zero;
        if (stream.isWriting)
        {
            syncPosition = transform.position;
            stream.Serialize(ref syncPosition);

            syncRotation = transform.rotation;
            stream.Serialize(ref syncRotation);

            syncVelocity = controller.velocity;
            stream.Serialize(ref syncVelocity);
        }
        else
        {
            stream.Serialize(ref syncPosition);
            stream.Serialize(ref syncRotation);
            stream.Serialize(ref syncVelocity);

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            syncEndPosition = syncPosition + syncVelocity * syncDelay;
            syncStartPosition = transform.position;

            syncEndRotation = syncRotation;
            syncStartRotation = transform.rotation;
        }
    }
	void OnSerializeNetworkView (BitStream stream, NetworkMessageInfo info)
	{
		if (stream.isWriting) {
			//This is executed on the owner of the networkview
			//The owner sends it's color over the network
			
			//send color
			Vector3 tempcolor = new Vector3(gameObject.GetComponent<Renderer>().material.color.r,gameObject.GetComponent<Renderer>().material.color.g,gameObject.GetComponent<Renderer>().material.color.b);
			
			stream.Serialize (ref tempcolor);//"Encode" it, and send it
			
		} else {
			//Executed on all non-owners
			//receive a color and set the object to it
			
			//get color
			Vector3 tempcolor = Vector3.zero;
			Color colorReceive = Color.black;
			stream.Serialize (ref tempcolor);
			
			colorReceive = new Color(tempcolor.x, tempcolor.y, tempcolor.z, 1.0f);

			//We've just recieved the current servers position of this object in 'posReceive'.
			
			renderer.material.color = colorReceive;
			//To reduce laggy movement a bit you could comment the line above and use position lerping below instead:	
			//transform.position = Vector3.Lerp(transform.position, posReceive, 0.9f); //"lerp" to the posReceive by 90%
			//It would be even better to save the last received server position and lerp to it in Update because it is executed more often than OnSerializeNetworkView
			
		}
	}
Пример #31
0
 public override void WriteOutOfBandHeader(BitStream bitStream)
 {
     RakNetPINVOKE.RakPeer_WriteOutOfBandHeader(swigCPtr, BitStream.getCPtr(bitStream));
 }
 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
 {
     callIfExist(idOnSerializeNetworkView, stream, info);
 }
Пример #33
0
        public override void Crack(DataCracker context, BitStream data, long?size)
        {
            long      startPos  = data.PositionBits;
            BitStream sizedData = ReadSizedData(data, size);

            if (this.Count > 0)
            {
                origionalElement = this[0];
                Clear();
            }

            long min = minOccurs;
            long max = maxOccurs;

            var rel = relations.Of <CountRelation>().Where(context.HasCracked).FirstOrDefault();

            if (rel != null)
            {
                min = max = rel.GetValue();
            }
            else if (minOccurs == 1 && maxOccurs == 1)
            {
                min = max = occurs;
            }

            if (((min > maxOccurs && maxOccurs != -1) || (min < minOccurs)) && min != occurs)
            {
                string msg = "{0} has invalid count of {1} (minOccurs={2}, maxOccurs={3}, occurs={4}).".Fmt(
                    debugName, min, minOccurs, maxOccurs, occurs);
                throw new CrackingFailure(msg, this, data);
            }

            for (int i = 0; max == -1 || i < max; ++i)
            {
                logger.Debug("Crack: ======================");
                logger.Debug("Crack: {0} Trying #{1}", origionalElement.debugName, i + 1);

                long pos = sizedData.PositionBits;
                if (pos == sizedData.LengthBits)
                {
                    logger.Debug("Crack: Consumed all bytes. {0}", sizedData.Progress);
                    break;
                }

                var clone = makeElement(i);
                Add(clone);

                try
                {
                    context.CrackData(clone, sizedData);

                    // If we used 0 bytes and met the minimum, we are done
                    if (pos == sizedData.PositionBits && i == min)
                    {
                        RemoveAt(clone.parent.IndexOf(clone));
                        break;
                    }
                }
                catch (CrackingFailure)
                {
                    logger.Debug("Crack: {0} Failed on #{1}", debugName, i + 1);

                    // If we couldn't satisfy the minimum propigate failure
                    if (i < min)
                    {
                        throw;
                    }

                    RemoveAt(clone.parent.IndexOf(clone));
                    sizedData.SeekBits(pos, System.IO.SeekOrigin.Begin);
                    break;
                }
            }

            if (this.Count < min)
            {
                string msg = "{0} only cracked {1} of {2} elements.".Fmt(debugName, Count, min);
                throw new CrackingFailure(msg, this, data);
            }

            if (size.HasValue && data != sizedData)
            {
                data.SeekBits(startPos + sizedData.PositionBits, System.IO.SeekOrigin.Begin);
            }
        }
Пример #34
0
 public override void Crack(DataCracker context, BitStream data, long?size)
 {
     // Consume padding bytes
     ReadSizedData(data, size);
 }
Пример #35
0
        public void ReadWriteNumbersOddOffset()
        {
            BitStream bs = new BitStream();
            BitWriter w  = new BitWriter(bs);
            BitReader r  = new BitReader(bs);

            w.LittleEndian();
            r.LittleEndian();

            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);

            Assert.AreEqual(3, bs.LengthBits);
            Assert.AreEqual(3, bs.PositionBits);

            //Max
            w.WriteSByte(sbyte.MaxValue);

            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(0, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());

            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MaxValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MaxValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(67305985);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(67305985, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MaxValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MaxValue, r.ReadInt64());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteByte(byte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(byte.MaxValue, r.ReadByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt16(ushort.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(ushort.MaxValue, r.ReadUInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt32(UInt32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt32.MaxValue, r.ReadUInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt64(UInt64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt64.MaxValue, r.ReadUInt64());


            //Min
            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteSByte(sbyte.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MinValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MinValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MinValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MinValue, r.ReadInt64());

            // BIG ENDIAN //////////////////////////////////////////

            bs.SetLength(0);
            r.BigEndian();
            w.BigEndian();

            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);

            //Max
            w.WriteSByte(sbyte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MaxValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MaxValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(67305985);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(67305985, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MaxValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MaxValue, r.ReadInt64());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteByte(byte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(byte.MaxValue, r.ReadByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt16(ushort.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(ushort.MaxValue, r.ReadUInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt32(UInt32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt32.MaxValue, r.ReadUInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt64(UInt64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt64.MaxValue, r.ReadUInt64());

            //Min
            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteSByte(sbyte.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MinValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MinValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MinValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MinValue, r.ReadInt64());
        }
Пример #36
0
 protected override void OnLoadBegin(BitStream stream, Action <T> loadingDoneHandler)
 {
     OnLoad(stream, loadingDoneHandler);
 }
Пример #37
0
 /// <summary>
 /// When overridden in the derived class, handles sending data to the server.
 /// </summary>
 /// <param name="bs">The data to send.</param>
 protected abstract void SendData(BitStream bs);
Пример #38
0
        protected override BitStream internalEncode(BitStream data)
        {
            var b64s = System.Text.ASCIIEncoding.ASCII.GetString(data.Value);

            return(new BitStream(System.Convert.FromBase64String(b64s)));
        }
Пример #39
0
        public static bool DeserializeCompressed(string str, BitStream bs, bool readLanguageId)
        {
            bool ret = RakNetPINVOKE.RakString_DeserializeCompressed__SWIG_2(str, BitStream.getCPtr(bs), readLanguageId);

            return(ret);
        }
Пример #40
0
 public void ReadMsg(BitStream stream)
 {
     Type       = PrefetchType.Sound;
     SoundIndex = stream.ReadInt(SourceConstants.MAX_SOUND_INDEX_BITS);
 }
Пример #41
0
 public static void SerializeCompressed(string str, BitStream bs)
 {
     RakNetPINVOKE.RakString_SerializeCompressed__SWIG_5(str, BitStream.getCPtr(bs));
 }
Пример #42
0
        public static bool DeserializeCompressed(string str, BitStream bs)
        {
            bool ret = RakNetPINVOKE.RakString_DeserializeCompressed__SWIG_3(str, BitStream.getCPtr(bs));

            return(ret);
        }
Пример #43
0
 public void SerializeCompressed(BitStream bs)
 {
     RakNetPINVOKE.RakString_SerializeCompressed__SWIG_2(swigCPtr, BitStream.getCPtr(bs));
 }
Пример #44
0
        public bool Deserialize(BitStream bs)
        {
            bool ret = RakNetPINVOKE.RakString_Deserialize__SWIG_0(swigCPtr, BitStream.getCPtr(bs));

            return(ret);
        }
Пример #45
0
 public static void Serialize(string str, BitStream bs)
 {
     RakNetPINVOKE.RakString_Serialize__SWIG_1(str, BitStream.getCPtr(bs));
 }
Пример #46
0
 public static void SerializeCompressed(string str, BitStream bs, byte languageId)
 {
     RakNetPINVOKE.RakString_SerializeCompressed__SWIG_4(str, BitStream.getCPtr(bs), languageId);
 }
 // Token: 0x060032A5 RID: 12965 RVA: 0x000BFFB0 File Offset: 0x000BE1B0
 void Deserialize(BitStream stream)
 {
     base.Deserialize(stream);
 }
Пример #48
0
 public void SerializeCompressed(BitStream bs, byte languageId, bool writeLanguageId)
 {
     RakNetPINVOKE.RakString_SerializeCompressed__SWIG_0(swigCPtr, BitStream.getCPtr(bs), languageId, writeLanguageId);
 }
Пример #49
0
        public void Read(BitStream stream)
        {
            stream.Read(out this.mapName);

            int ilc = 0;

            stream.Read(out ilc);
            for (int i = 0; i < ilc; i++)
            {
                int   id;
                Vec3f pos, dir;
                stream.Read(out id);
                stream.Read(out pos);
                stream.Read(out dir);

                Vob v = sWorld.VobDict[id];
                v.Position  = pos;
                v.Direction = dir;
                addVob(v);

                v.Spawn(this.Map, v.Position, v.Direction);
            }

            int vlc = 0;

            stream.Read(out vlc);
            for (int i = 0; i < vlc; i++)
            {
                int   id;
                Vec3f pos, dir;
                stream.Read(out id);
                stream.Read(out pos);
                stream.Read(out dir);

                Vob v = sWorld.VobDict[id];
                v.Position  = pos;
                v.Direction = dir;
                addVob(v);

                v.Spawn(this.Map, v.Position, v.Direction);
            }

            int nlc = 0;

            stream.Read(out nlc);
            for (int i = 0; i < nlc; i++)
            {
                int   id;
                Vec3f pos, dir;
                stream.Read(out id);
                stream.Read(out pos);
                stream.Read(out dir);

                if (id == Player.Hero.ID)
                {
                    continue;
                }

                Vob v = sWorld.VobDict[id];
                v.Position  = pos;
                v.Direction = dir;
                addVob(v);

                v.Spawn(this.Map, v.Position, v.Direction);
                //((NPCProto)v).Disable();
            }
        }
Пример #50
0
 public void Serialize(BitStream bs)
 {
     RakNetPINVOKE.RakString_Serialize__SWIG_0(swigCPtr, BitStream.getCPtr(bs));
 }
 void IReplicationServerCallback.SendEvent(BitStream stream, bool reliable, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.RPC, stream, reliable, endpoint);
 }
 // Token: 0x060032A4 RID: 12964 RVA: 0x000BFFA4 File Offset: 0x000BE1A4
 void Serialize(BitStream stream)
 {
     base.Serialize(stream);
 }
 void IReplicationServerCallback.SendWorldBattleData(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.WORLD_BATTLE_DATA, stream, true, endpoint);
 }
 void IReplicationServerCallback.SentClientJoined(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.CLIENT_CONNNECTED, stream, true, endpoint);
 }
 void IReplicationServerCallback.SendReplicationDestroy(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.REPLICATION_DESTROY, stream, true, endpoint);
 }
 void IReplicationServerCallback.SendJoinResult(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.JOIN_RESULT, stream, true, endpoint);
 }
 void IReplicationServerCallback.SendServerData(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.SERVER_DATA, stream, true, endpoint);
 }
 void IReplicationServerCallback.SendStateSync(BitStream stream, EndpointId endpoint, bool reliable)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.SERVER_STATE_SYNC, stream, reliable, endpoint);
 }
Пример #59
0
        public bool Deserialize(BitStream inBitStream)
        {
            bool ret = RakNetPINVOKE.FileList_Deserialize(swigCPtr, BitStream.getCPtr(inBitStream));

            return(ret);
        }
 void IReplicationServerCallback.SendReplicationCreateStreamed(BitStream stream, EndpointId endpoint)
 {
     SyncLayer.TransportLayer.SendMessage(MyMessageId.REPLICATION_STREAM_BEGIN, stream, true, endpoint);
 }