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


C# PhotonView.SerializeView方法代码示例

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


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

示例1: OnSerializeWrite

    // calls OnPhotonSerializeView (through ExecuteOnSerialize)
    // the content created here is consumed by receivers in: ReadOnSerialize
    private Hashtable OnSerializeWrite(PhotonView view)
    {
        PhotonStream pStream = new PhotonStream( true, null );
        PhotonMessageInfo info = new PhotonMessageInfo( this.mLocalActor, this.ServerTimeInMilliSeconds, view );

        // each view creates a list of values that should be sent
        view.SerializeView( pStream, info );

        if( pStream.Count == 0 )
        {
            return null;
        }

        object[] dataArray = pStream.data.ToArray();

        if (view.synchronization == ViewSynchronization.UnreliableOnChange)
        {
            if (AlmostEquals(dataArray, view.lastOnSerializeDataSent))
            {
                if (view.mixedModeIsReliable)
                {
                    return null;
                }

                view.mixedModeIsReliable = true;
                view.lastOnSerializeDataSent = dataArray;
            }
            else
            {
                view.mixedModeIsReliable = false;
                view.lastOnSerializeDataSent = dataArray;
            }
        }

        // EVDATA:
        // 0=View ID (an int, never compressed cause it's not in the data)
        // 1=data of observed type (different per type of observed object)
        // 2=compressed data (in this case, key 1 is empty)
        // 3=list of values that are actually null (if something was changed but actually IS null)
        Hashtable evData = new Hashtable();
        evData[(byte)0] = (int)view.viewID;
        evData[(byte)1] = dataArray;    // this is the actual data (script or observed object)


        if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
        {
            // compress content of data set (by comparing to view.lastOnSerializeDataSent)
            // the "original" dataArray is NOT modified by DeltaCompressionWrite
            // if something was compressed, the evData key 2 and 3 are used (see above)
            bool somethingLeftToSend = this.DeltaCompressionWrite(view, evData);

            // buffer the full data set (for next compression)
            view.lastOnSerializeDataSent = dataArray;

            if (!somethingLeftToSend)
            {
                return null;
            }
        }

        return evData;
    }
开发者ID:JonasSkaug,项目名称:afgangsprojekt-team-tj,代码行数:64,代码来源:NetworkingPeer.cs

示例2: OnSerializeWrite

    // calls OnPhotonSerializeView (through ExecuteOnSerialize)
    // the content created here is consumed by receivers in: ReadOnSerialize
    private object[] OnSerializeWrite(PhotonView view)
    {
        if (view.synchronization == ViewSynchronization.Off)
        {
            return null;
        }

        // each view creates a list of values that should be sent
        PhotonMessageInfo info = new PhotonMessageInfo(this.LocalPlayer, PhotonNetwork.ServerTimestamp, view);
        this.pStream.ResetWriteStream();
        this.pStream.SendNext((int)view.viewID);
        this.pStream.SendNext(false);
        this.pStream.SendNext(null);
        view.SerializeView(this.pStream, info);

        // check if there are actual values to be sent (after the "header" of viewId, (bool)compressed and (int[])nullValues)
        if (this.pStream.Count <= SyncFirstValue)
        {
            return null;
        }
        if (view.synchronization == ViewSynchronization.Unreliable)
        {
            return this.pStream.ToArray();
        }

        // ViewSynchronization: Off, Unreliable, UnreliableOnChange, ReliableDeltaCompressed

        object[] currentValues = this.pStream.ToArray();
        if (view.synchronization == ViewSynchronization.UnreliableOnChange)
        {
            if (AlmostEquals(currentValues, view.lastOnSerializeDataSent))
            {
                if (view.mixedModeIsReliable)
                {
                    return null;
                }

                view.mixedModeIsReliable = true;
                view.lastOnSerializeDataSent = currentValues;
            }
            else
            {
                view.mixedModeIsReliable = false;
                view.lastOnSerializeDataSent = currentValues;
            }

            return currentValues;
        }

        if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
        {
            // compress content of data set (by comparing to view.lastOnSerializeDataSent)
            // the "original" dataArray is NOT modified by DeltaCompressionWrite
            object[] dataToSend = this.DeltaCompressionWrite(view.lastOnSerializeDataSent, currentValues);

            // cache the values that were written this time (not the compressed values)
            view.lastOnSerializeDataSent = currentValues;

            return dataToSend;
        }

        return null;
    }
开发者ID:yuvadius,项目名称:need4bit,代码行数:65,代码来源:NetworkingPeer.cs


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