当前位置: 首页>>代码示例>>C#>>正文


C# BitStream.Serialize方法代码示例

本文整理汇总了C#中UnityEngine.BitStream.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.Serialize方法的具体用法?C# BitStream.Serialize怎么用?C# BitStream.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.BitStream的用法示例。


在下文中一共展示了BitStream.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSerializeNetworkView

    public int playerIndex = 0; // Player index of driver who spawned fake item box

    #endregion Fields

    #region Methods

    // Send data over network
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 position = Vector3.zero;
        Vector3 forwardVector = Vector3.zero;
        Vector3 upVector = Vector3.zero;
        if (stream.isWriting)
        {
            // Sending data...
            position = this.transform.position;
            forwardVector = this.transform.forward;
            upVector = this.transform.up;
            stream.Serialize(ref position);
            stream.Serialize(ref forwardVector);
            stream.Serialize(ref upVector);
            stream.Serialize(ref moveDirection);
            stream.Serialize(ref this.playerIndex);
        }
        else
        {
            // Receiving data...
            stream.Serialize(ref position);
            stream.Serialize(ref forwardVector);
            stream.Serialize(ref upVector);
            this.transform.position = position;
            this.transform.rotation = Quaternion.LookRotation(forwardVector, upVector);
            stream.Serialize(ref moveDirection);
            stream.Serialize(ref this.playerIndex);
        }
    }
开发者ID:RavenNevermore,项目名称:EndOfLine,代码行数:36,代码来源:SideBladeBehavior.cs

示例2: OnSerializeNetworkView

    //Rigidbody
    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        var lIsKinematic = true;
        var lPosition = Vector3.zero;
        var lRot = Quaternion.identity;

        if (stream.isWriting)
        {
            lPosition = transform.position;
            lRot = transform.rotation;
            lIsKinematic = rigidbody.isKinematic;
            //lBoxPos = _supplyBox.transform.position;
        }

        stream.Serialize(ref lIsKinematic);
        stream.Serialize(ref lPosition);
        stream.Serialize(ref lRot);
        //stream.Serialize(ref lBoxPos);

        if (stream.isReading)
        {
            transform.position = lPosition;
            transform.rotation = lRot;
            rigidbody.isKinematic = lIsKinematic;
        }

        if(!lIsKinematic)
        {
            networkView.observed = rigidbody;
            Destroy(this);
        }
    }
开发者ID:Seraphli,项目名称:TheInsectersWar,代码行数:33,代码来源:RigidbodyNetView.cs

示例3: OnSerializeNetworkView

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        float net_currentHealth = 0;
        float net_maxHealth = 0;
        bool net_isTargeted = false;

        if (stream.isWriting)
        {
            net_currentHealth = currentHealth;
            net_maxHealth = maxHealth;
            net_isTargeted = isTargeted;

            stream.Serialize(ref net_currentHealth);
            stream.Serialize(ref net_maxHealth);
            stream.Serialize(ref net_isTargeted);
        }
        else if (stream.isReading)
        {
            stream.Serialize(ref net_currentHealth);
            stream.Serialize(ref net_maxHealth);
            stream.Serialize(ref net_isTargeted);

            currentHealth = net_currentHealth;
            maxHealth = net_maxHealth;
            isTargeted = net_isTargeted;
        }
    }
开发者ID:datnewb,项目名称:Kartus,代码行数:27,代码来源:CharacterHealth.cs

示例4: OnSerializeNetworkView

    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;
        }
    }
开发者ID:Game-Group,项目名称:dog-fighter,代码行数:26,代码来源:NetworkSync.cs

示例5: OnSerializeNetworkView

    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;
        }
    }
开发者ID:DerBasti,项目名称:Rift-Wingsuit,代码行数:28,代码来源:Player.cs

示例6: OnSerializeNetworkView

    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);
        }
    }
开发者ID:chrisscherer,项目名称:ISGame,代码行数:25,代码来源:Predictor.cs

示例7: OnSerializeNetworkView

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (stream.isWriting)
        {
            //  Vector3 pos = transform.position;
            Quaternion rot = transform.rotation;
            //   int _animState = (int)animState;

            //   stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            //   stream.Serialize(ref _animState);

        }
        else
        {
            //   Vector3 revPos = Vector3.zero;
            Quaternion revRot = Quaternion.identity;
            //  int _animState = 0;

            //    stream.Serialize(ref revPos);
            stream.Serialize(ref revRot);
            //  stream.Serialize(ref _animState);

            //     currPos = revPos;
            currRot = revRot;
            //   animState = (AnimState)_animState;
        }
    }
开发者ID:InvitationToDeath,项目名称:InvitationToDeath-Ver3,代码行数:28,代码来源:PlayerCtrl.cs

示例8: OnSerializeNetworkView

    /* 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;
        }
    }
开发者ID:Midipil,项目名称:SansDessusDessous,代码行数:27,代码来源:NetworkEnemyController.cs

示例9: OnSerializeNetworkView

    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;
            }

        }
    }
开发者ID:rehabgame,项目名称:fighton,代码行数:33,代码来源:Ball.cs

示例10: OnSerializeNetworkView

    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;
        }
    }
开发者ID:ZachHoefler,项目名称:pokeMMOn,代码行数:33,代码来源:Player.cs

示例11: OnSerializeNetworkView

 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");
         }
     }
 }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:32,代码来源:NetworkInterpolatedTransform.cs

示例12: OnSerializeNetworkView

    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;
        }
    }
开发者ID:pmlamotte,项目名称:2Pac,代码行数:32,代码来源:BoardObject.cs

示例13: OnSerializeNetworkView

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        if (initialized) {
            Vector3 syncPosition = Vector3.zero;
            Quaternion syncRotation = Quaternion.identity;
            Vector3 syncVelocity = Vector3.zero;
            float syncHealth = 0f;

            if (stream.isWriting) {
                syncPosition = transform.position;
                syncRotation = transform.rotation;
                syncVelocity = rigidbody.velocity;
                syncHealth = playerDefense.health;
            }

            stream.Serialize(ref syncPosition);
            stream.Serialize(ref syncRotation);
            stream.Serialize(ref syncVelocity);
            stream.Serialize(ref syncHealth);

            if (stream.isReading) {
                syncTime = 0f;
                float currentTime = Time.time;
                syncDelay = currentTime - lastSynchronizationTime;
                lastSynchronizationTime = currentTime;

                startSyncPosition = transform.position;
                startSyncRotation = transform.rotation;
                endSyncPosition = syncPosition + syncVelocity * syncDelay;
                endSyncRotation = syncRotation;
                this.syncHealth = syncHealth;
            }
        }
    }
开发者ID:rvitale,项目名称:RaidBoss,代码行数:34,代码来源:NetworkSync.cs

示例14: OnSerializeNetworkView

    void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
    {
        Vector3 tempPos = Vector3.zero;
        Quaternion tempRot = Quaternion.identity;

        if((Network.isServer)&&(stream.isWriting))
        {
            //Debug.Log("Hellow");

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

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

        }
        else if(Network.isClient)
        {

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

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

        }
    }
开发者ID:rehabgame,项目名称:fighton,代码行数:27,代码来源:conveyorScript.cs

示例15: OnSerializeNetworkView

    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);
        }
    }
开发者ID:Final-Parsec,项目名称:TheVenomEvent,代码行数:28,代码来源:Predictor.cs


注:本文中的UnityEngine.BitStream.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。