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


C# BinaryReader.ReadFloat方法代码示例

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


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

示例1: LoadMap


//.........这里部分代码省略.........
                        go = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        Debug.LogWarning(readString + " not found ");
                    }
                    go.name = readString;
                    modelObject = InitModel(go, readString);
                    modelObject.transform.position = ms.ReadVector();
                    modelObject.transform.eulerAngles = ms.ReadVector();
                    modelObject.transform.localScale = ms.ReadVector();

                    //if (!cells.Add(new KeyValuePair<Vector3, string>(g.pos, go.name)))
                    //{
                    //    Debug.Log("Destroy duplicate " + go.name, go);
                    //    Debug.Log("with " + go.name, go);
                    //    if (ingame)
                    //    Destroy(go);
                    //}
                }
                if (P == LevelPackets.FlyingModel && modelObject != null)
                    modelObject.flying = true;
                if (P == LevelPackets.roadtype)
                    spline.roadType = (RoadType)ms.ReadByte2();
                if (P == LevelPackets.Wall)
                    spline.wallTexture = true;
                if (P == LevelPackets.shapeMaterial)
                {
                    string readString = ms.ReadString();
                    spline.thumb = new Thumbnail() { url = Regex.Replace(readString, @"https?://server.critical-missions.com/tm/|https?://tmrace.net/tm/", "") };
                    //Debug.LogWarning(readString);
                }
                if (P == LevelPackets.textureTile)
                    spline.thumb.material.mainTextureScale = ms.ReadVector();
                if (P == LevelPackets.AntiFly)
                {
                    _GameSettings.gravitationAntiFly = ms.ReadFloat();
                    _GameSettings.gravitationFactor = ms.ReadFloat();
                }
                if (P == LevelPackets.Flying)
                    segment.flying = ms.ReadBool();

                if (P == LevelPackets.heightOffset)
                    spline.heightOffset = ms.ReadFloat();
                if (P == LevelPackets.Version)
                {
                    version = ms.ReadInt();
                    if (version >= 702)
                    {
                        foreach (var a in shapes.ToArray())
                        {
                            print("removing default brush " + a.name);
                            Destroy(a.gameObject);
                        }
                    }
                }
                if (P == LevelPackets.Nitro)
                {
                    Debug.Log("Nitro Loaded " + nitro);
                    nitro = ms.ReadFloat();
                }
                if (P == LevelPackets.Point)
                {
                    var readVector = ms.ReadVector();
                    AddPoint(readVector);
                    if (version >= 702)
                        segment.spls = new List<CurvySpline2>();
                    else
                        segment.spls = new List<CurvySpline2>(new[] { brushShapes[0] });
开发者ID:friuns,项目名称:New-Unity-Project-tm2---Copy,代码行数:67,代码来源:MapLoader.cs

示例2: ReadFloatTest

        public void ReadFloatTest()
        {
            // Test floats {-89171.12f, 1.783421e31f}

            // prepare test buffer
            UTF8Encoding utf8 = new UTF8Encoding();
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ms, utf8);
            bw.Write((float)-89171.12);
            bw.Write((float)1.783421e31);
            bw.Write(float.NaN);
            bw.Write(float.NegativeInfinity);
            bw.Write(float.PositiveInfinity);
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(ms, DeserializationHelper.CannedVersion);
            string name = string.Empty;
            float actual;
            actual = reader.ReadFloat(name);
            Assert.AreEqual((float)-89171.12, actual);
            actual = reader.ReadFloat(name);
            Assert.AreEqual((float)1.783421e31, actual);
            actual = reader.ReadFloat(name);
            Assert.IsTrue(float.IsNaN(actual));
            actual = reader.ReadFloat(name);
            Assert.IsTrue(float.IsNegativeInfinity(actual));
            actual = reader.ReadFloat(name);
            Assert.IsTrue(float.IsPositiveInfinity(actual));
        }
开发者ID:CoreylDagget,项目名称:tesla,代码行数:29,代码来源:FloatDeserializationTest.cs

示例3: ReadTooSmallFloatTest

        public void ReadTooSmallFloatTest()
        {
            System.IO.Stream stream = new SerializedStreamBuilder()
                .Double(double.MinValue)
                .ToStream();

            BinaryReader reader = new BinaryReader(stream, DeserializationHelper.CannedVersion);

            float actual = reader.ReadFloat(string.Empty);

            Assert.AreEqual<float>(float.NaN, actual);
        }
开发者ID:CoreylDagget,项目名称:tesla,代码行数:12,代码来源:FloatDeserializationTest.cs

示例4: ReadReplay

 private Replay ReadReplay(byte[] buffer)
 {
     Replay rep = new Replay();
     if (buffer == null) { print("Buffer is null"); return rep; }
     rep.contry = _Loader.Country;
     using (var ms = new BinaryReader(buffer))
     {
         Vector3 oldPos = Vector3.zero;
         float oldmeters = 0;
         PosVel posvel = null;
         int vers = 0;
         int errors = 0;
         while (ms.Position < ms.Length)
         {
             lastRd = curredRd;
             var b = curredRd = ms.ReadByte();
             try
             {
                 if (b == RD.playerName)
                 {
                     rep.playerName = ms.ReadString();
                     Debug.LogWarning(rep.playerName);
                 }
                 else if (b == RD.clan)
                     rep.clanTag = ms.ReadString();
                 else if (b == RD.version)
                 {
                     if (vers == 1241 || vers == 1234) return null;
                     vers = ms.ReadInt();
                 }
                 else if (b == RD.posVel)
                 {
                     posvel = new PosVel();
                     posvel.pos = ms.ReadVector();
                     if (oldPos == Vector3.zero)
                         oldPos = posvel.pos;
                     posvel.meters = oldmeters = oldmeters + (posvel.pos - oldPos).magnitude;
                     oldPos = posvel.pos;
                     posvel.rot.eulerAngles = ms.ReadVector();
                     posvel.vel = ms.ReadVector();
                     rep.posVels.Add(posvel);
                 }
                 else if (b == RD.score)
                     /*posvel.score = */
                     ms.ReadInt();
                 else if (b == RD.posVelMouse)
                     posvel.mouserot = ms.ReadFloat();
                 else if (b == RD.posVelSkid)
                     posvel.skid = ms.ReadFloat();
                 else if (b == RD.keyCode)
                 {
                     var kc = (KeyCode)ms.ReadInt();
                     float t = ms.ReadFloat();
                     bool d = ms.ReadBool();
                     //if (Player.recordKeys.Contains(kc))
                     rep.keyDowns.Add(new KeyDown() { down = d, keyCode = kc, time = t });
                 }
                 else if (b == RD.avatarId)
                     rep.avatarId = ms.ReadInt();
                 else if (b == RD.carSkin)
                     rep.carSkin = ms.ReadInt();
                 else if (b == RD.FinnishTime)
                     rep.finnishTime = ms.ReadFloat();
                 else if (b == RD.country)
                 {
                     CountryCodes countryCodes = (CountryCodes)ms.ReadByte();
                     //if (countryCodes != CountryCodes.fi)
                     rep.contry = countryCodes;
                     //print("Read Country " + rep.contry);
                 }
                 else if (b == RD.color)
                     rep.color = new Color(ms.ReadFloat(), ms.ReadFloat(), ms.ReadFloat());
                 else if (b == RD.avatarUrl)
                     rep.avatarUrl = ms.ReadString();
                 else if (b == RD.rank)
                     rep.rank = ms.ReadInt();
                 else
                 {
                     if (errors == 0)
                         Debug.LogError("byte unknown type " + b + " lastType " + lastRd + " version " + vers);
                     errors++;
                     //if (isDebug)
                     //    Debug.LogError("byte unknown type " + b);
                 }
             }
             catch (Exception e)
             {
                 if (errors == 0)
                     Debug.LogError("error curType" + b + " lastType " + lastRd + " version " + vers + "\n" + e);
                 errors++;
             }
         }
         print("Replay version " + vers + " errors" + errors);
     }
     return rep;
 }
开发者ID:friuns,项目名称:New-Unity-Project-tm2---Copy,代码行数:96,代码来源:Loader.cs


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