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


C# BinaryReader.PeekChar方法代码示例

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


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

示例1: makeBuilding

    public void makeBuilding(float interval,float tmpWidth,int regionWidth,float tmpDepth,float tmpHeight,float[] height)
    {
        int afterX,afterY,galo,selo,building_height;
        FileStream building_fs = new FileStream ("building_data_bin", FileMode.Open);
        BinaryReader reader = new BinaryReader (building_fs);

        int ncols_building = reader.ReadInt32();
        int nrows_building = reader.ReadInt32();

        //Debug.Log ("ncols_building :" + ncols_building);
        //Debug.Log ("nrows_building : " + nrows_building);

        while (reader.PeekChar () != -1) {

            afterX = reader.ReadInt32 ()/(int)interval;		//To adjust the resolution, divid with interval
            afterY = reader.ReadInt32 ()/(int)interval;
            galo = reader.ReadInt32 ();
            selo = reader.ReadInt32 ();

            building_height = reader.ReadInt32();

            /*Debug.Log ("afterX : " + afterX);
            Debug.Log ("afterY : " + afterY);
            Debug.Log ("galo : " + galo);
            Debug.Log ("selo : " + selo);
            Debug.Log ("height : " + building_height);*/

            GameObject building = GameObject.CreatePrimitive(PrimitiveType.Cube);
            building.transform.localScale = new Vector3(galo,selo,building_height);
            building.transform.position = new Vector3(afterX*interval - tmpWidth,((height [regionWidth * afterY + afterX] - tmpDepth)*5f)+(building.transform.localScale.y/2),(afterY* interval - tmpHeight));
            //building.AddComponent<BoxCollider>();
            //building.AddComponent<Rigidbody>().useGravity=false;
            building.AddComponent<clicked_building>();
        }
    }
开发者ID:Hyunsik-Yoo,项目名称:Flood-Simulation,代码行数:35,代码来源:ForTest.cs

示例2: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BinaryReader sr2;
			BinaryWriter sw2;
			FileStream fs2;
			if(File.Exists("Co5633Test.tmp"))
				File.Delete("Co5633Test.tmp");			
			strLoc = "Loc_9577b";
			fs2 = new FileStream("Co5633Test.tmp", FileMode.Create);
			sw2 = new BinaryWriter(fs2);
			sw2.Write("Dette er sjef");
			sw2.Close();
			strLoc = "Loc_49t8e";
			fs2 = new FileStream("Co5633Test.tmp", FileMode.Open);
			sr2 = new BinaryReader(fs2);
			sr2.Close();
			sr2.Close();
			sr2.Close();
			iCountTestcases++;
			try {
				sr2.PeekChar();
				iCountErrors++;
				printerr( "Error_687yv! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_y67y9! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_9y7g7! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.Read();
				iCountErrors++;
				printerr( "ERror_y658b! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_7y857! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_t87yg! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.Read(new Byte[2], 0, 2);
				iCountErrors++;
				printerr( "Error_9177g! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_80093! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_7100b! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.Read(new Char[2], 0, 2);
				iCountErrors++;
				printerr( "Error_2398j! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_t877b! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_787yb! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.ReadBoolean();
				iCountErrors++;
				printerr( "Error_10408! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_1098t! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_178t5! Incorrect exception thrown, exc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.ReadByte();
				iCountErrors++;
				printerr( "Error_17985! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_0984s! Caught expected exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_019g8! Incorrect exception thrown, excc=="+exc.ToString());
			}
			iCountTestcases++;
			try {
				sr2.ReadBytes(2);
				iCountErrors++;
				printerr( "Error_10989! Expected exception not thrown");
			} catch (ObjectDisposedException iexc) {
				printinfo( "Info_01099! Caught expectede exception, exc=="+iexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5633close.cs

示例3: ReadDBF

    // Read an entire standard DBF file into a DataTable
    public static DataTable ReadDBF(string dbfFile)
    {
		long start = DateTime.Now.Ticks;
        DataTable dt = new DataTable();
		BinaryReader recReader;
		string number;
		string year;
		string month;
		string day;
		long lDate;
		long lTime;
		DataRow row;
		int	fieldIndex;

        // If there isn't even a file, just return an empty DataTable
        if ((false == File.Exists(dbfFile)))
        {
            return dt;
        }

        BinaryReader br = null;
        try
        {
            // Read the header into a buffer
            br = new BinaryReader(File.OpenRead(dbfFile));
            byte[] buffer = br.ReadBytes(Marshal.SizeOf(typeof(DBFHeader)));

            // Marshall the header into a DBFHeader structure
            GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            DBFHeader header = (DBFHeader) Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(DBFHeader));
            handle.Free();

            // Read in all the field descriptors. Per the spec, 13 (0D) marks the end of the field descriptors
            ArrayList fields = new ArrayList();
            while ((13 != br.PeekChar()))
            {
                buffer = br.ReadBytes(Marshal.SizeOf(typeof(FieldDescriptor)));
                handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                fields.Add((FieldDescriptor)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(FieldDescriptor)));
                handle.Free();
            }

			// Read in the first row of records, we need this to help determine column types below
			((FileStream) br.BaseStream).Seek(header.headerLen + 1, SeekOrigin.Begin);
			buffer = br.ReadBytes(header.recordLen);
			recReader = new BinaryReader(new MemoryStream(buffer));

            // Create the columns in our new DataTable
            DataColumn col = null;
            foreach (FieldDescriptor field in fields)
            {
				number = Encoding.ASCII.GetString(recReader.ReadBytes(field.fieldLen));
                switch (field.fieldType)
                {
					case 'N':
						if (number.IndexOf(".") > -1)
						{
							col = new DataColumn(field.fieldName, typeof(decimal));
						}
						else
						{
							col = new DataColumn(field.fieldName, typeof(int));
						}
						break;
					case 'C':
						col = new DataColumn(field.fieldName, typeof(string));
						break;
					case 'T':
						// You can uncomment this to see the time component in the grid
						//col = new DataColumn(field.fieldName, typeof(string));
						col = new DataColumn(field.fieldName, typeof(DateTime));
						break;
					case 'D':
						col = new DataColumn(field.fieldName, typeof(DateTime));
						break;
					case 'L':
						col = new DataColumn(field.fieldName, typeof(bool));
						break;
					case 'F':
						col = new DataColumn(field.fieldName, typeof(Double));
						break;
                }
                dt.Columns.Add(col);
            }

			// Skip past the end of the header. 
			((FileStream) br.BaseStream).Seek(header.headerLen, SeekOrigin.Begin);

            // Read in all the records
            for (int counter = 0; counter <= header.numRecords - 1; counter++)
            {
                // First we'll read the entire record into a buffer and then read each field from the buffer
                // This helps account for any extra space at the end of each record and probably performs better
                buffer = br.ReadBytes(header.recordLen);
                recReader = new BinaryReader(new MemoryStream(buffer));

				// All dbf field records begin with a deleted flag field. Deleted - 0x2A (asterisk) else 0x20 (space)
				if (recReader.ReadChar() == '*')
				{
//.........这里部分代码省略.........
开发者ID:faloi,项目名称:csharp.utils,代码行数:101,代码来源:ParseDBF.cs

示例4: StartListeningTcp

    public static void StartListeningTcp() 
    {
        TcpThreadListener listener = new TcpThreadListener(0);
        NetworkStream ns = null;
        BinaryReader br = null;

        try 
        {
            listener.Start();
            IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint;
            Interlocked.Exchange(ref iPortNumber, ipe.Port);
            Console.WriteLine("Using port: {0}", iPortNumber);
            m_PortSetEvent.Set();

            Socket s = listener.AcceptSocket();
            ns = new NetworkStream(s);
            br = new BinaryReader( ns );   
            Int32 tmp = 0;
            for(int i = 0 ; i < chArr.Length ; i++) 
            {
                tmp = br.PeekChar();
                if(tmp != -1) 
                {
                    iCountErrors++;
                    Console.WriteLine( "It's a network stream.... We always expect -1... but the real value..." + tmp);
                }
                br.Read();
            }
            Console.WriteLine("We are done with the listening");
        }
        catch(Exception e) 
        {
            Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace);
            m_PortSetEvent.Set();
        }
        finally
        {
            if (listener != null)
            {
                listener.Stop();
            }
            if (ns != null)
            {
                ns.Close();
            }
            if(br != null)
            {
                br.Close();
            }
        } //finally
    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:51,代码来源:co5635peekchar.cs

示例5: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BinaryReader sr2;
         StreamWriter sw2;
         MemoryStream ms2;
         FileStream fs2;
         String filName = s_strTFAbbrev+"Test.tmp";
         if(File.Exists(filName))
             File.Delete(filName);			
         try 
         {
             ms2 = new MemoryStream();
             sw2 = new StreamWriter(ms2);
             for(int i = 0 ; i < chArr.Length ; i++)
                 sw2.Write(chArr[i]);
             sw2.Flush();
             ms2.Position = 0;
             sr2 = new BinaryReader(ms2);
             Int32 tmp = 0;
             for(int i = 0 ; i < chArr.Length ; i++) 
             {
                 iCountTestcases++;
                 tmp = sr2.PeekChar();
                 if(tmp != (Int32)chArr[i]) 
                 {
                     iCountErrors++;
                     printerr( "Error_298vc_"+i+"! Expected=="+(Int32)chArr[i]+", got=="+tmp);
                 }
                 sr2.Read();
             }
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_298yg! Unexpected exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_9848v";
         try 
         {
             fs2 = new FileStream(filName, FileMode.Create);
             sw2 = new StreamWriter(fs2);
             for(int i = 0 ; i < chArr.Length ; i++)
                 sw2.Write(chArr[i]);
             sw2.Flush();
             sw2.Close();
             fs2 = new FileStream(filName, FileMode.Open);
             sr2 = new BinaryReader(fs2);
             Int32 tmp = 0;
             for(int i = 0 ; i < chArr.Length ; i++) 
             {
                 iCountTestcases++;
                 if((tmp = sr2.PeekChar()) != (Int32)chArr[i]) 
                 {
                     iCountErrors++;
                     printerr( "Error_98yv8!_"+i+"! Expected=="+(Int32)chArr[i]+", got=="+tmp);
                 }
                 sr2.Read();
             }
             sr2.Close();
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_698y7! Unexpected exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_958hb";
         int temp = 0;
         fs2 = new FileStream(filName, FileMode.Create);
         sw2 = new StreamWriter(fs2, Encoding.UTF8, 4);
         sw2.Write("\u00FF\u00FF");
         sw2.Close();
         fs2 = new FileStream(filName, FileMode.Open);
         sr2 = new BinaryReader(fs2);
         temp = sr2.PeekChar(); 
         sr2.Read();
         iCountTestcases++;
         if((temp = sr2.PeekChar()) != 0xFF) 
         {
             iCountErrors++;
             printerr( "Error_t8yc! Incorrect character read" + temp);
         }
         sr2.Read();
         if((temp = sr2.PeekChar()) != 0xFF) 
         {
             iCountErrors++;
             printerr("Error_8yb78! Incorrect character read" + temp);
         }
         sr2.Read();
         iCountTestcases++;
         if(( temp = sr2.PeekChar()) != -1) 
         {
             iCountErrors++;
             printerr( "Error_987yg! Incorrect character" + temp);
         }
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5635peekchar.cs

示例6: Entry

    public static void Entry(String filestr, ref String xmlpublickey)
    {
        byte[] x509key;
        byte[] seq = new byte[15];
        int x509size;
        /*
        if (filename == "")  //exit while(true) loop
            return;
        if (!File.Exists(filename))
        {
            throw new FileNotFoundException("File does not exist!\n");
        }

        StreamReader sr = File.OpenText(filename);
        String filestr = sr.ReadToEnd();
        sr.Close();
        */
        StringBuilder sb = new StringBuilder(filestr);
        sb.Replace("-----BEGIN PUBLIC KEY-----", "");  //remove headers/footers, if present
        sb.Replace("-----END PUBLIC KEY-----", "");

        try
        {        //see if the file is a valid Base64 encoded cert
            x509key = Convert.FromBase64String(sb.ToString());
        }
        catch (System.FormatException)
        {		//if not a b64-encoded publiccert, assume it's binary
        //            Console.WriteLine("Not a valid  b64 blob; assume binary");
        //            Stream stream = new FileStream(filename, FileMode.Open);
        //            int datalen = (int)stream.Length;
        //            x509key = new byte[datalen];
        //            stream.Read(x509key, 0, datalen);
        //            stream.Close();
            return;

        }
        x509size = x509key.Length;

        //Console.WriteLine(sb.ToString()) ;
        //PutFileBytes("x509key", x509key, x509key.Length) ;

        // ---------  Set up stream to read the asn.1 encoded SubjectPublicKeyInfo blob  ------
        MemoryStream mem = new MemoryStream(x509key);
        BinaryReader binr = new BinaryReader(mem);    //wrap Memory Stream with BinaryReader for easy reading
        byte bt = 0;
        ushort twobytes = 0;

        try
        {

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8130)	//data read as little endian order (actual data order for Sequence is 30 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8230)
                binr.ReadInt16();	//advance 2 bytes
            else
                return;

            seq = binr.ReadBytes(15);		//read the Sequence OID
            if (!CompareBytearrays(seq, SeqOID))	//make sure Sequence for OID is correct
                return;

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8103)	//data read as little endian order (actual data order for Bit String is 03 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8203)
                binr.ReadInt16();	//advance 2 bytes
            else
                return;

            bt = binr.ReadByte();
            if (bt != 0x00)		//expect null byte next
                return;

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8130)	//data read as little endian order (actual data order for Sequence is 30 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8230)
                binr.ReadInt16();	//advance 2 bytes
            else
                return;

            twobytes = binr.ReadUInt16();
            byte lowbyte = 0x00;
            byte highbyte = 0x00;

            if (twobytes == 0x8102)	//data read as little endian order (actual data order for Integer is 02 81)
                lowbyte = binr.ReadByte();	// read next bytes which is bytes in modulus
            else if (twobytes == 0x8202)
            {
                highbyte = binr.ReadByte();	//advance 2 bytes
                lowbyte = binr.ReadByte();
            }
            else
                return;
            byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };   //reverse byte order since asn.1 key uses big endian order
            int modsize = BitConverter.ToInt32(modint, 0);

            int firstbyte = binr.PeekChar();
            if (firstbyte == 0x00)
//.........这里部分代码省略.........
开发者ID:hajimen,项目名称:flowerflower,代码行数:101,代码来源:pempublic.cs

示例7: GetPublicKey

    /*******************************************************************
     * 
     * Code for reading RSA keys taken from:
     * https://langcongnghe.com/2014/11/10/tony/cach-thuc-doc-rsa-private-key-va-public-key-trong-c.html
     * 
     *******************************************************************/

    private static RSACryptoServiceProvider GetPublicKey(string publicKeyString)
    {
        // encoded OID sequence for  PKCS #1 rsaEncryption szOID_RSA_RSA = "1.2.840.113549.1.1.1"
        byte[] SeqOID = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
        byte[] x509key;
        byte[] seq = new byte[15];
        int x509size;

        x509key = Convert.FromBase64String(publicKeyString);
        x509size = x509key.Length;

        // ---------  Set up stream to read the asn.1 encoded SubjectPublicKeyInfo blob  ------
        MemoryStream mem = new MemoryStream(x509key);
        BinaryReader binr = new BinaryReader(mem);    //wrap Memory Stream with BinaryReader for easy reading
        byte bt = 0;
        ushort twobytes = 0;

        try
        {

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8130)	//data read as little endian order (actual data order for Sequence is 30 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8230)
                binr.ReadInt16();	//advance 2 bytes
            else
                return null;

            seq = binr.ReadBytes(15);		//read the Sequence OID
            if (!CompareBytearrays(seq, SeqOID))	//make sure Sequence for OID is correct
                return null;

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8103)	//data read as little endian order (actual data order for Bit String is 03 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8203)
                binr.ReadInt16();	//advance 2 bytes
            else
                return null;

            bt = binr.ReadByte();
            if (bt != 0x00)		//expect null byte next
                return null;

            twobytes = binr.ReadUInt16();
            if (twobytes == 0x8130)	//data read as little endian order (actual data order for Sequence is 30 81)
                binr.ReadByte();	//advance 1 byte
            else if (twobytes == 0x8230)
                binr.ReadInt16();	//advance 2 bytes
            else
                return null;

            twobytes = binr.ReadUInt16();
            byte lowbyte = 0x00;
            byte highbyte = 0x00;

            if (twobytes == 0x8102)	//data read as little endian order (actual data order for Integer is 02 81)
                lowbyte = binr.ReadByte();	// read next bytes which is bytes in modulus
            else if (twobytes == 0x8202)
            {
                highbyte = binr.ReadByte();	//advance 2 bytes
                lowbyte = binr.ReadByte();
            }
            else
                return null;
            byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };   //reverse byte order since asn.1 key uses big endian order
            int modsize = BitConverter.ToInt32(modint, 0);

            int firstbyte = binr.PeekChar();
            if (firstbyte == 0x00)
            {	//if first byte (highest order) of modulus is zero, don't include it
                binr.ReadByte();	//skip this null byte
                modsize -= 1;	//reduce modulus buffer size by 1
            }

            byte[] modulus = binr.ReadBytes(modsize);	//read the modulus bytes

            if (binr.ReadByte() != 0x02)			//expect an Integer for the exponent data
                return null;
            int expbytes = (int)binr.ReadByte();		// should only need one byte for actual exponent data (for all useful values)
            byte[] exponent = binr.ReadBytes(expbytes);

            // ------- create RSACryptoServiceProvider instance and initialize with public key -----
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            RSAParameters RSAKeyInfo = new RSAParameters();
            RSAKeyInfo.Modulus = modulus;
            RSAKeyInfo.Exponent = exponent;
            RSA.ImportParameters(RSAKeyInfo);

            return RSA;
        }

        finally
//.........这里部分代码省略.........
开发者ID:mezosaurus,项目名称:eae-project,代码行数:101,代码来源:ServerMessaging.cs

示例8: loadTransformArrayAndInstantiate

    public static GameObject[] loadTransformArrayAndInstantiate(string filename, GameObject go)
    {
        if(!EasySave.fileExists(filename))
        {
            Debug.LogError("Could not load file: File does not exist.");
            return null;
        }

        BinaryReader br = new BinaryReader(new MemoryStream(getBytesFromFile(filename)));
        try
        {
            int noOfItems = br.ReadInt32();

            GameObject[] t = new GameObject[noOfItems];
            for(int i=0;i<noOfItems;i++)
            {
                t[i] = Instantiate(go,new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle()),
                                    new Quaternion(br.ReadSingle(),br.ReadSingle(),br.ReadSingle(),br.ReadSingle())) as GameObject;
                t[i].transform.localScale = new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
                if(br.PeekChar() != -1)
                    t[i].tag = br.ReadString();
            }
            br.Close();
            return t;
        }
        catch(Exception e)
        {
            Debug.LogError("Could not load file: File specified is not in the correct format.\nDetails: "+e.Message);
            return null;
        }
    }
开发者ID:wuzhida,项目名称:YUMI,代码行数:31,代码来源:EasySave.cs

示例9: loadTransformArray

    public static void loadTransformArray(string filename, GameObject[] go)
    {
        if(!EasySave.fileExists(filename))
        {
            Debug.LogError("Could not load file: File does not exist.");
            return;
        }

        BinaryReader br = new BinaryReader(new MemoryStream(getBytesFromFile(filename)));
        try
        {
            int noOfItems = br.ReadInt32();
            if(noOfItems != go.Length)
            {
                Debug.LogError("Could not auto-assign transforms: Length of GameObject array provided is not equal to number of transforms in 									save file.");
                return;
            }
            Transform[] t = new Transform[noOfItems];
            for(int i=0;i<noOfItems;i++)
            {
                t[i] = go[i].GetComponent("Transform") as Transform;
                t[i].position = new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
                t[i].rotation = new Quaternion(br.ReadSingle(),br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
                t[i].localScale = new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
                if(br.PeekChar() != -1)
                    t[i].tag = br.ReadString();
            }
            br.Close();
        }
        catch(Exception e)
        {
            Debug.LogError("Could not load file: File specified is not in the correct format.\nDetails: "+e.Message);
        }
        return;
    }
开发者ID:wuzhida,项目名称:YUMI,代码行数:35,代码来源:EasySave.cs

示例10: loadTransform

    public static void loadTransform(string filename, GameObject go)
    {
        if(!EasySave.fileExists(filename))
        {
            Debug.LogError("Could not load file: File does not exist.");
            return;
        }

        BinaryReader br = new BinaryReader(new MemoryStream(getBytesFromFile(filename)));
        try
        {
            br.ReadInt32();
            Transform t = go.transform;
            t.position = new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
            t.rotation = new Quaternion(br.ReadSingle(),br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
            t.localScale = new Vector3(br.ReadSingle(),br.ReadSingle(),br.ReadSingle());
            if(br.PeekChar() != -1)
                t.tag = br.ReadString();
            br.Close();
        }
        catch(Exception e)
        {
            Debug.LogError("Could not load file: File specified is not in the correct format.\nDetails: "+e.Message);
        }
        return;
    }
开发者ID:wuzhida,项目名称:YUMI,代码行数:26,代码来源:EasySave.cs


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