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


C# BinaryWriter.ToArray方法代码示例

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


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

示例1: SavePlayerPrefs

    public IEnumerator SavePlayerPrefs(bool skip = false)
    {
        if (!allowSavePrefs || setting.disablePlayerPrefs)
            yield break;
        var act = win.act;
        SaveStrings();
        if (!skip)
            if (guest) yield break;

        //save= totalSeconds;
        win.ShowWindow(delegate { win.showBackButton = false; Label("Saving stats "); if (BackButtonLeft()) { ShowWindowNoBack(act); act = null; } }, act, true);
        yield return null;
        StringBuilder sb = new StringBuilder();
        byte[] array;
        using (var ms = new BinaryWriter())
        {
            //#if !UNITY_WP8
            ms.Write(_DefinePrefsTime);
            ms.Write(totalSeconds.ToString());
            //#endif
            var forb = new List<string> { "password", "Enc", _DefinePrefsTime };
            var plname = playerName;
            foreach (string key in playerPrefKeys)
            {
                if (!forb.Contains(key))
                {
                    if (ResLoader.isEditor && !key.StartsWith(plname)) continue;
                    var value = PlayerPrefsGetString(key);
                    //if (Key.EndsWith("reputation"))
                    //print("reputation:" + value);
                    if (value.Length < 200 && isDebug)
                        sb.AppendLine(key + "\t\t" + value);

                    if (value.Length > MaxLength || key.Length > MaxLength)
                    {
                        Debug.LogError(string.Format("too big value {0} {1}", key, value));
                        continue;
                    }
                    ms.Write(key);
                    ms.Write(value);
                }

            }
            array = GZipStream.CompressBuffer(ms.ToArray());
            Xor(array);
            print("saving stats_______ :" + ms.Length + " " + array.Length);
            if (isDebug)
                print(sb.ToString());
        }

        var w = DownloadAcc("savePrefs2", null, true, "file", array);
        yield return w;

        if (act != null)
            win.ShowWindow(act);

        if (!w.text.StartsWith("prefs uploaded"))
            Popup(_Loader.lastError = (w.text + w.error), MenuWindow);
    }
开发者ID:friuns,项目名称:New-Unity-Project-tm2---Copy,代码行数:59,代码来源:LoaderLoadPrefs.cs

示例2: SaveMap

    public IEnumerator SaveMap()
    {
        LogEvent(EventGroup.LevelEditor, "Save Map");
        tool = Tool.Height;
        Update();
        UpdateModelView();
        //foreach (var a in hideGroup)
        //    foreach (var b in a.Value.list)
        //        if (b != null)
        //            b.SetActive(true);
        //if (FindObjectsOfType<Coin>().Length > 5)
        //    mapSets.enableCoins = true;
        //if (GameObject.FindGameObjectWithTag(Tag.blueSpawn) && GameObject.FindGameObjectWithTag(Tag.redSpawn))
        //    mapSets.enableCtf = true;
        //mapSets.race = GameObject.FindGameObjectsWithTag("CheckPoint").Length >= 2;
        using (var ms = new BinaryWriter())
        {
            ms.Write((int)LevelPackets.Version);
            ms.Write(setting.version);
            Debug.Log("write map name " + unityMap);
            if (!string.IsNullOrEmpty(unityMap))
            {
                ms.Write((int)LevelPackets.unityMap);
                ms.Write(unityMap);
            }
            ms.Write((int)LevelPackets.Nitro);
            ms.Write(nitro);
            if (hideTerrain)
                ms.Write((int)LevelPackets.disableTerrain);
            ms.Write((int)LevelPackets.AntiFly);
            ms.Write(_GameSettings.gravitationAntiFly);
            ms.Write(_GameSettings.gravitationFactor);

            ms.Write((int)LevelPackets.levelTime);
            ms.Write(_GameSettings.levelTime);
            if (start != null)
            {
                ms.Write((int)LevelPackets.StartPos);
                ms.Write(start.position);
                ms.Write(start.forward);
            }


            foreach (ModelObject a in FindObjectsOfType(typeof(ModelObject)))
            {
                if (modelLib != null && modelLib.dict.ContainsKey(a.name2))
                {
                    ms.Write((int)LevelPackets.Block);
                    ms.Write(a.name2);
                    ms.Write(a.pos);
                    ms.Write(a.rot.eulerAngles);
                    ms.Write(a.transform.localScale);
                    if (a.flying)
                        ms.Write((int)LevelPackets.FlyingModel);
                }
                else
                {
                    print(a.name2 + " not found");
                }
            }


            var splines = this.splines.OrderByDescending(a => a.shape).ToArray();
            for (int i = 0; i < splines.Length; i++)
                splines[i].saveId = i;

            foreach (var a in checkPoints.Where(a => a.name.StartsWith("CheckPoint2")))
            {
                ms.Write((int)LevelPackets.CheckPoint2);
                ms.Write(a.transform.position);
                ms.Write(a.transform.eulerAngles);
            }
            foreach (CurvySpline2 sp in splines)
            {
                if (sp.shape)
                {
                    ms.Write((int)LevelPackets.shape);
                    ms.Write(sp.pivot.Position);
                    ms.Write(sp.saveId);
                    ms.Write(sp.tunnel);
                    ms.Write(sp.materialId);
                    ms.Write(sp.color);
                    ms.Write(sp.name);
                    if (sp.thumb != null)
                    {
                        ms.Write((int)LevelPackets.shapeMaterial);
                        ms.Write(sp.thumb.url);
                        ms.Write((int)LevelPackets.textureTile);
                        ms.Write(sp.thumb.material.mainTextureScale);
                    }
                    ms.Write((int)LevelPackets.roadtype);
                    ms.Write((byte)sp.roadType);
                    if (sp.wallTexture)
                        ms.Write((int)LevelPackets.Wall);
                    if (sp.rotateTexture)
                        ms.Write((int)LevelPackets.rotateTexture);

                }
                else
                    ms.Write((int)LevelPackets.Spline);
//.........这里部分代码省略.........
开发者ID:friuns,项目名称:New-Unity-Project-tm2---Copy,代码行数:101,代码来源:LevelEditor.cs


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