本文整理汇总了C#中BinaryReader.ReadChars方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadChars方法的具体用法?C# BinaryReader.ReadChars怎么用?C# BinaryReader.ReadChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadWavStreamReadHeaders
public static CWavStreamReadHeaders ReadWavStreamReadHeaders(BinaryReader r)
{
CWavStreamReadHeaders info = new CWavStreamReadHeaders();
info.bIsValid = false;
string riff = new string(r.ReadChars(4));
if (!riff.Equals("RIFF"))
throw new WavCutException("No 'RIFF' Tag, probably not a valid wav file.");
info.nCompleteLength = r.ReadUInt32(); // (length of file in bytes) - 8
string wave = new string(r.ReadChars(4));
if (!wave.Equals("WAVE"))
throw new WavCutException("No 'WAVE' tag, probably not a valid wav file.");
string format = new string(r.ReadChars(4)); // assume that fmt tag is first
if (!format.Equals("fmt "))
throw new WavCutException("No 'fmt ' tag");
uint size = r.ReadUInt32(); // size of fmt header
if (size != 16)
throw new WavCutException("Size of fmt header != 16");
info.nAudioFormat = r.ReadUInt16(); // audio format. 1 refers to uncompressed PCM
// read the format header
info.nChannels = r.ReadUInt16();
info.nSampleRate = r.ReadUInt32();
info.byteRate = r.ReadUInt32();
info.blockAlign = r.ReadUInt16();
info.nBitsPerSample = r.ReadUInt16();
info.bIsValid = true;
return info;
}
示例2: Load
public static void Load(string Path)
{
if (!File.Exists(Configuration.GameResources + "\\" + Path + "\\" + "cache.bin"))
throw new FileNotFoundException("Файл бэйсов не найден. Проверьте правильность пути.");
BinReader = new BinaryReader(File.OpenRead(Configuration.GameResources + "\\" + Path + "\\" + "cache.bin"));
if (BinReader.ReadInt16() != 500)
throw new FileLoadException("Неверная сигнатура файла.");
if (BinReader.ReadInt32() != BinReader.BaseStream.Length)
throw new FileLoadException("В заголовке указан неверный размер файла.");
BinReader.BaseStream.Seek(4, SeekOrigin.Current); // Константа - 01 00 00 00
while (BinReader.BaseStream.Position < BinReader.BaseStream.Length)
{
long TmpPosition = BinReader.BaseStream.Position;
if (BinReader.ReadInt16() != 1000)
throw new FileLoadException("Неверная сигнатура бейса. " + BinReader.BaseStream.Position);
int BlockSize = BinReader.ReadInt32();
GameObject Base = GameObject.Find(new string(BinReader.ReadChars(BinReader.ReadInt32())));
BinReader.BaseStream.Seek(0x4C, SeekOrigin.Current); // unknown
while (BinReader.BaseStream.Position < (TmpPosition + BlockSize))
{
if (BinReader.ReadInt16() != 2000)
throw new FileLoadException("Неверная сигнатура объекта." + BinReader.BaseStream.Position);
BinReader.BaseStream.Seek(4, SeekOrigin.Current);
string ObjectName = new string(BinReader.ReadChars(BinReader.ReadInt32()))
.Replace(".I3D", "").Replace(".i3d", "");
GameObject Object = ModelSceneLoader.Load("models" + "\\" + ObjectName);
Object.transform.parent = Base.transform;
Object.transform.position = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()) * Configuration.ScaleFactor;
Object.transform.rotation = new wxyz_s(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()).ToQuat();
Object.transform.localScale = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle());
BinReader.BaseStream.Seek(16, SeekOrigin.Current); // unknown
}
}
}
示例3: ReadString
public static string ReadString(BinaryReader b)
{
int strLen = b.ReadInt32();
char[] chars = b.ReadChars(strLen);
string str = new string(chars);
return str;
}
示例4: Load
public static GameObject Load(string ModelName)
{
if (ModelsInRAM.ContainsKey(ModelName))
return Object.Instantiate(ModelsInRAM[ModelName]);
if (!File.Exists(Configuration.GameResources + "\\" + ModelName + ".4ds"))
throw new FileNotFoundException("Модель не найдена. Проверьте правильность пути. ");
BinReader = new BinaryReader(File.OpenRead(Configuration.GameResources + "\\" + ModelName + ".4ds"));
if (new string(BinReader.ReadChars(4)) != "4DS\0")
throw new FileLoadException("Неверная сигнатура файла.");
if (BinReader.ReadUInt16() != (ushort)FileVersion.VERSION_MAFIA)
throw new FileLoadException("Данная версия модели не поддерживается.");
ulong TimeStamp = BinReader.ReadUInt64();
Model = new GameObject(Path.GetFileName(ModelName));
ReadMaterials(BinReader.ReadUInt16());
ReadNodes(BinReader.ReadUInt16());
BinReader.BaseStream.Dispose();
ModelsInRAM.Add(ModelName, Model);
return Model;
}
示例5: Start
// Use this for initialization
void Start()
{
Debug.Log("Starting Server");
server = new NamedPipeServerStream("NPtest");
//Console.WriteLine("Waiting for connection...");
Debug.Log("Waiting for connection...");
server.WaitForConnection();
//Console.WriteLine("Connected.");
Debug.Log("Connected.");
br = new BinaryReader(server);
bw = new BinaryWriter(server);
while (true)
{
try
{
var len = (int)br.ReadUInt32(); // Read string length
var str = new string(br.ReadChars(len)); // Read string
//Console.WriteLine("Read: \"{0}\"", str);
Debug.Log(String.Format("Read: {0}", str));
str = new string(str.Reverse().ToArray()); // Just for fun
var buf = Encoding.ASCII.GetBytes(str); // Get ASCII byte array
bw.Write((uint)buf.Length); // Write string length
bw.Write(buf); // Write string
//Console.WriteLine("Wrote: \"{0}\"", str);
Debug.Log(String.Format("Wrote: {0}", str));
}
catch (EndOfStreamException)
{
break; // When client disconnects
}
}
//Console.WriteLine("Client disconnected.");
Debug.Log("Client disconnected.");
server.Close();
server.Dispose();
}
示例6: Load_TimeData
//------------------------------------- time steps -------------------------------------
bool Load_TimeData(int numTimesteps)
{
int t_index = 0;
int index = 0;
double ephemTime;
char[] utcChar = new char[17];
string utc = "";
string filename = "Assets/Data/timeData.dat";
utcArray = new string[ numTimesteps ];
ephemTimeArray = new double[ numTimesteps ];
if ( File.Exists( filename ) )
{
Debug.Log( "Loading Time Data" );
BinaryReader binReader= new BinaryReader( File.Open( filename, FileMode.Open ) );
for ( t_index = 0; t_index < numTimesteps; t_index++ )
{
utcChar = binReader.ReadChars( 17 );
for ( index = 0; index < 17; index ++ )
{
if ( index == 0 )
{
utc = "UTC Time: ";
}
utc += utcChar[ index ];
}
ephemTime = binReader.ReadDouble();
utcArray[ t_index ] = utc;
ephemTimeArray[ t_index ] = ephemTime;
} // end for
binReader.Close();
return true;
}// end if
else
{
Debug.Log( "Could not load Time Data" );
return false;
}// end else
}
示例7: Load_TimeData
//------------------------------------- time steps -------------------------------------
bool Load_TimeData(int numTimesteps)
{
int t_index = 0;
int index = 0;
double ephemTime;
char[] utcChar = new char[17];
string utc = "";
utcArray = new string[ numTimesteps ];
ephemTimeArray = new double[ numTimesteps ];
if ( timeData )
{
Debug.Log( "Loading Time Data" );
BinaryReader binReader= new BinaryReader( new MemoryStream(timeData.bytes) );
for ( t_index = 0; t_index < numTimesteps; t_index++ )
{
utcChar = binReader.ReadChars( 17 );
for ( index = 0; index < 17; index ++ )
{
if ( index == 0 )
{
utc = "UTC Time: ";
}
utc += utcChar[ index ];
}
ephemTime = binReader.ReadDouble();
utcArray[ t_index ] = utc;
ephemTimeArray[ t_index ] = ephemTime;
} // end for
binReader.Close();
return true;
}// end if
else
{
Debug.Log( "Could not load Time Data" );
return false;
}// end else
}
示例8: StartWavAnalyze
public static void StartWavAnalyze(BinaryReader r, long nActualLength)
{
CWavStreamReadHeaders info = CWavStreamReadHeaders.ReadWavStreamReadHeaders(r);
// display header info
Console.WriteLine("Audio format: " + info.nAudioFormat + " (1 is uncompressed PCM)");
Console.WriteLine("Sample rate: " + info.nSampleRate);
Console.WriteLine("BitsPerSample: " + info.nBitsPerSample);
Console.WriteLine("Channels: " + info.nChannels);
if (nActualLength != info.nCompleteLength+8)
Console.WriteLine("Warning: length of file is "+nActualLength+" but expected "+info.nCompleteLength);
while (true)
{
// are we at the end of the file? if so, exit loop
byte[] arTest = r.ReadBytes(4);
if (arTest.Length == 0)
break;
else
r.BaseStream.Seek(-arTest.Length,SeekOrigin.Current);
// read the next chunk
string sDatatag = new string(r.ReadChars(4));
uint nDataSize = r.ReadUInt32();
Console.WriteLine("TYPE:" + sDatatag + " SIZE:" + nDataSize);
if (sDatatag == "data")
{
long nLengthInSamples = nDataSize / (info.nChannels * (info.nBitsPerSample / 8));
Console.WriteLine("\tlength in samples " + nLengthInSamples +
" length in secs " + (nLengthInSamples / ((double)info.nSampleRate)));
}
if (sDatatag != "data" && sDatatag != "LIST")
Console.WriteLine("warning, datatag is not 'data' or 'LIST'.");
r.BaseStream.Seek(nDataSize, SeekOrigin.Current);
}
Console.WriteLine("Looks ok.");
}
示例9: Recieve
public int Recieve()
{
try
{
_count = 0;
EndPoint endpoint = new IPEndPoint(address, _port);
byte[] rBuffer = new byte[500];
qSocket.ReceiveFrom(rBuffer, ref endpoint);
timestamp[1] = DateTime.Now;
using (MemoryStream stream = new MemoryStream(rBuffer))
{
using (BinaryReader reader = new BinaryReader(stream))
{
if (stream.Length <= 10)
return _count;
reader.ReadBytes(10);
switch (reader.ReadChar())
{
case 'i': // Information
{
results = new string[6];
results[_count++] = Convert.ToString(reader.ReadByte());
results[_count++] = Convert.ToString(reader.ReadInt16());
results[_count++] = Convert.ToString(reader.ReadInt16());
int hostnamelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(hostnamelen));
int gamemodelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(gamemodelen));
int mapnamelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(mapnamelen));
return _count;
}
case 'r': // Rules
{
int rulecount = reader.ReadInt16();
results = new string[rulecount * 2];
for (int i = 0; i < rulecount; i++)
{
int rulelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(rulelen));
int valuelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(valuelen));
}
return _count;
}
case 'c': // Client list
{
int playercount = reader.ReadInt16();
results = new string[playercount * 2];
for (int i = 0; i < playercount; i++)
{
int namelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(namelen));
results[_count++] = Convert.ToString(reader.ReadInt32());
}
return _count;
}
case 'd': // Detailed player information
{
int playercount = reader.ReadInt16();
results = new string[playercount * 4];
for (int i = 0; i < playercount; i++)
{
results[_count++] = Convert.ToString(reader.ReadByte());
int namelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(namelen));
results[_count++] = Convert.ToString(reader.ReadInt32());
results[_count++] = Convert.ToString(reader.ReadInt32());
}
return _count;
}
//.........这里部分代码省略.........
示例10: StreamThroughWave
public static void StreamThroughWave(BinaryReader r, long nActualLength)
{
string riff = new string(r.ReadChars(4));
if (!riff.Equals("RIFF"))
throw new Exception("No 'RIFF' Tag, probably not a valid wav file.");
uint length = r.ReadUInt32(); // (length of file in bytes) - 8
if (length != nActualLength - 8)
Console.WriteLine("Warning: claimed length of file="+length+" and actual="+nActualLength);
string wave = new string(r.ReadChars(4));
if (!wave.Equals("WAVE"))
throw new Exception("No 'WAVE' tag, probably not a valid wav file.");
string format = new string(r.ReadChars(4)); // assume that fmt tag is first
if (!format.Equals("fmt "))
throw new Exception("No 'fmt ' tag");
uint size = r.ReadUInt32(); // size of fmt header
if (size != 16)
throw new Exception("Size of fmt header != 16");
ushort audioformat = r.ReadUInt16(); // audio format. 1 refers to uncompressed PCM
Console.WriteLine("Audio format: " + audioformat + " (1 is uncompressed PCM)");
ushort nChannels = r.ReadUInt16();
uint nSampleRate = r.ReadUInt32();
uint byteRate = r.ReadUInt32();
int blockAlign = r.ReadUInt16();
ushort nBitsPerSample = r.ReadUInt16();
Console.WriteLine("Sample rate: " + nSampleRate);
Console.WriteLine("BitsPerSample: " + nBitsPerSample);
Console.WriteLine("Channels: " + nChannels);
while (true)
{
// Are we at the end of the file?
byte[] test = r.ReadBytes(4);
if (test.Length == 0)
break;
else
r.BaseStream.Seek(-test.Length, SeekOrigin.Current);
// read the next chunk
string datatag = new string(r.ReadChars(4));
uint dataSize = r.ReadUInt32();
if (dataSize > int.MaxValue) throw new Exception("Data size too large.");
Console.WriteLine("TYPE:" + datatag + " SIZE:" + dataSize);
if (datatag == "data")
{
long nLengthInSamples = dataSize / (nChannels * (nBitsPerSample/8));
Console.WriteLine("\t(length in samples " + nLengthInSamples+
" length in secs " + (nLengthInSamples / ((double)nSampleRate)));
}
if (datatag != "data" && datatag != "LIST")
Console.WriteLine("warning, datatag is not 'data' or 'LIST'.");
r.BaseStream.Seek(dataSize, SeekOrigin.Current);
}
Console.WriteLine("Looks ok.");
}
示例11: 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
{
MemoryStream ms2;
FileStream fs2;
BinaryReader sr2;
String str2;
if(File.Exists("Co5631Test.tmp"))
File.Delete("Co5631Test.tmp");
strLoc = "Loc_1989x";
iCountTestcases++;
try
{
sr2 = new BinaryReader((Stream)null);
iCountErrors++;
printerr( "Error_298vb! Expected exception not thrown");
}
catch (ArgumentNullException aexc)
{
printinfo("Info_7887g! Caught expected exception, aexc=="+aexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_t98bh! Incorrect exception thrown, exc=="+exc.ToString());
}
strLoc = "Loc_g37jb";
fs2 = new FileStream("Co5631Test.tmp", FileMode.Create, FileAccess.Write);
iCountTestcases++;
try
{
sr2 = new BinaryReader(fs2);
iCountErrors++;
printerr("Error_07t8b! Expected exception not thrown");
}
catch (ArgumentException aexc)
{
printinfo("Info_09877! Caught expected exception, aexc=="+aexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_9t798! Incorrect exception thrown, exc=="+exc.ToString());
}
fs2.Close();
strLoc = "Loc_gfu8g";
ms2 = new MemoryStream();
ms2.Close();
iCountTestcases++;
try
{
sr2 = new BinaryReader(ms2);
iCountErrors++;
printerr( "Error_9578b! Expected exception not thrown");
}
catch (ArgumentException aexc)
{
printinfo("Info_6t877! Caught expected exception, aexc=="+aexc.Message);
}
catch (Exception exc)
{
iCountErrors++;
printerr( "Error_7698b! Incorrect exception thrown, exc=="+exc.ToString());
}
strLoc = "Loc_787yg";
iCountTestcases++;
ms2 = new MemoryStream();
ms2.Write(new Byte[]{65,66,67,68}, 0, 4);
ms2.Position = 0;
sr2 = new BinaryReader(ms2);
str2 = new String(sr2.ReadChars(4));
if(!str2.Equals("ABCD"))
{
iCountErrors++;
printerr( "Error_6t897! Incorrect string read");
}
sr2.Close();
strLoc = "Loc_48yvd";
iCountTestcases++;
fs2 = new FileStream("Co5631Test.tmp", FileMode.Create);
fs2.Write(new Byte[]{65,66,67,68},0,4);
fs2.Position = 0;
sr2 = new BinaryReader(fs2);
str2 = new String(sr2.ReadChars(4));
if(!str2.Equals("ABCD"))
{
iCountErrors++;
printerr( "Error_9688y! Incorrect string read");
}
fs2.Close();
if(File.Exists("Co5631Test.tmp"))
File.Delete("Co5631Test.tmp");
strLoc = "Loc_44444";
iCountTestcases++;
//.........这里部分代码省略.........
示例12: StreamTest
private Boolean StreamTest(Stream stream, Boolean fSuppress){
if(!fSuppress)
Console.WriteLine("Testing " + stream.GetType() + " for read/write tests");
String strValue;
Int32 iValue;
Int32 iLength = 1 << 10;
stream.Seek(0, SeekOrigin.Begin);
for(int i=0; i<iLength; i++)
stream.WriteByte((Byte)i);
Byte[] btArr = new Byte[iLength];
for(int i=0; i<iLength; i++)
btArr[i] = (Byte)i;
stream.Write(btArr, 0, iLength);
BinaryWriter bw1 = new BinaryWriter(stream);
bw1.Write(false);
bw1.Write(true);
for(int i=0; i<10; i++){
bw1.Write((Byte)i);
bw1.Write((SByte)i);
bw1.Write((Int16)i);
bw1.Write((Char)i);
bw1.Write((UInt16)i);
bw1.Write(i);
bw1.Write((UInt32)i);
bw1.Write((Int64)i);
bw1.Write((UInt64)i);
bw1.Write((Single)i);
bw1.Write((Double)i);
}
Char[] chArr = new Char[iLength];
for(int i=0; i<iLength;i++)
chArr[i] = (Char)i;
bw1.Write(chArr);
bw1.Write(chArr, 512, 512);
bw1.Write(new String(chArr));
bw1.Write(new String(chArr));
stream.Seek(0, SeekOrigin.Begin);
for(int i=0; i<iLength; i++){
if(stream.ReadByte() != i%256){
return false;
}
}
btArr = new Byte[iLength];
stream.Read(btArr, 0, iLength);
for(int i=0; i<iLength; i++){
if(btArr[i] != (Byte)i){
Console.WriteLine(i + " " + btArr[i] + " " + (Byte)i);
return false;
}
}
BinaryReader br1 = new BinaryReader(stream);
if(br1.ReadBoolean())
return false;
if(!br1.ReadBoolean())
return false;
for(int i=0; i<10; i++){
if(br1.ReadByte() != (Byte)i)
return false;
if(br1.ReadSByte() != (SByte)i)
return false;
if(br1.ReadInt16() != (Int16)i)
return false;
if(br1.ReadChar() != (Char)i)
return false;
if(br1.ReadUInt16() != (UInt16)i)
return false;
if(br1.ReadInt32() != i)
return false;
if(br1.ReadUInt32() != (UInt32)i)
return false;
if(br1.ReadInt64() != (Int64)i)
return false;
if(br1.ReadUInt64() != (UInt64)i)
return false;
if(br1.ReadSingle() != (Single)i)
return false;
if(br1.ReadDouble() != (Double)i)
return false;
}
chArr = br1.ReadChars(iLength);
for(int i=0; i<iLength;i++){
if(chArr[i] != (Char)i)
return false;
}
chArr = new Char[512];
chArr = br1.ReadChars(iLength/2);
for(int i=0; i<iLength/2;i++){
if(chArr[i] != (Char)(iLength/2+i))
return false;
}
chArr = new Char[iLength];
for(int i=0; i<iLength;i++)
chArr[i] = (Char)i;
strValue = br1.ReadString();
if(!strValue.Equals(new String(chArr)))
return false;
strValue = br1.ReadString();
if(!strValue.Equals(new String(chArr))){
return false;
}
//.........这里部分代码省略.........
示例13: Load
public static void Load(string Path)
{
if (!File.Exists(Configuration.GameResources + "\\" + Path + "\\" + "scene2.bin"))
throw new FileNotFoundException("Файл миссии не найден. Проверьте правильность пути.");
BinReader = new BinaryReader(File.OpenRead(Configuration.GameResources + "\\" + Path + "\\" + "scene2.bin"));
if (BinReader.ReadInt16() != 19539)
throw new FileLoadException("Неверная сигнатура файла.");
if (BinReader.ReadInt32() != BinReader.BaseStream.Length)
throw new FileLoadException("В заголовке указан неверный размер файла.");
BinReader.BaseStream.Seek(160 + 2, SeekOrigin.Begin);
int BlockSize = BinReader.ReadInt32();
// Primary sector
{
BinReader.BaseStream.Seek(6, SeekOrigin.Current);
if (BinReader.ReadInt16() == 16)
{
new GameObject(new string(BinReader.ReadChars(BinReader.ReadInt32() - 6)));
if (BinReader.ReadInt16() == -19455)
BinReader.BaseStream.Seek(BinReader.ReadInt32() - 6, SeekOrigin.Current);
}
else
{
BinReader.BaseStream.Seek(-8, SeekOrigin.Current);
}
}
// <debug camera>
{
BinReader.BaseStream.Seek(6, SeekOrigin.Current);
if (BinReader.ReadInt16() == 16)
{
GameObject DebugCamera = new GameObject(new string(BinReader.ReadChars(BinReader.ReadInt32() - 6)));
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 20 00 + 12 00 00 00
DebugCamera.transform.position = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()) * Configuration.ScaleFactor;
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 22 00 + 16 00 00 00
DebugCamera.transform.rotation = new wxyz_s(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()).ToQuat();
}
else
{
BinReader.BaseStream.Seek(-8, SeekOrigin.Current);
}
}
while (BinReader.BaseStream.Position < (160 + BlockSize))
{
short Flag = BinReader.ReadInt16();
int Size = BinReader.ReadInt32();
if (BinReader.ReadInt16() != 16401)
{
BinReader.BaseStream.Seek(Size - 8, SeekOrigin.Current);
continue;
}
BinReader.BaseStream.Seek(4, SeekOrigin.Current);
if (BinReader.ReadInt32() == 9)
{
ModelObject ModelObject = new ModelObject();
BinReader.BaseStream.Seek(2, SeekOrigin.Current); // 10 00
ModelObject.Name = new string(BinReader.ReadChars(BinReader.ReadInt32() - 6));
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 20 00 + 12 00 00 00
ModelObject.Position = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle());
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 22 00 + 16 00 00 00
ModelObject.Rotation = new wxyz_s(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle()).ToQuat();
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 2D 00 + 12 00 00 00
ModelObject.Scale = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle());
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 2С 00 + 12 00 00 00
ModelObject.GlobalPosition = new Vector3(BinReader.ReadSingle(), BinReader.ReadSingle(), BinReader.ReadSingle());
if (BinReader.ReadInt16() == 16416)
{
BinReader.BaseStream.Seek(6, SeekOrigin.Current); // 1B 00 00 00 + 10 00
ModelObject.Parent = new string(BinReader.ReadChars(BinReader.ReadInt32() - 6));
}
else
BinReader.BaseStream.Seek(-2, SeekOrigin.Current);
BinReader.BaseStream.Seek(2, SeekOrigin.Current); // 12 20
ModelObject.Model = new string(BinReader.ReadChars(BinReader.ReadInt32() - 6))
.Replace(".I3D", "").Replace(".i3d", "");
GenerateObject(ModelObject);
}
//.........这里部分代码省略.........
示例14: readMesh
public static void readMesh(string path,string filename)
{
if (File.Exists (path + "/" + filename)) {
string nm = Path.GetFileNameWithoutExtension (filename);
GameObject ObjectRoot = new GameObject (nm);
MD2Model model = (MD2Model)ObjectRoot.AddComponent (typeof(MD2Model));
model.setup ();
int vertex_Count;
int uv_count;
int face_Count;
int frames_Count;
List<Face> faces = new List<Face> ();
List<Face> tfaces = new List<Face> ();
List<Vector2> uvCoords = new List<Vector2> ();
using (FileStream fs = File.OpenRead(path + "/" + filename)) {
BinaryReader file = new BinaryReader (fs);
int Magic = file.ReadInt32 ();
int Version = file.ReadInt32 ();
int SkinWidth = file.ReadInt32 ();
int SkinHeight = file.ReadInt32 ();
int FrameSize = file.ReadInt32 ();
int NumSkins = file.ReadInt32 ();
int NumVertices = file.ReadInt32 ();
int NumTexCoords = file.ReadInt32 ();
int NumTriangles = file.ReadInt32 ();
int NumGlCommands = file.ReadInt32 ();
int NumFrames = file.ReadInt32 ();
int OffsetSkins = file.ReadInt32 ();
int OffsetTexCoords = file.ReadInt32 ();
int OffsetTriangles = file.ReadInt32 ();
int OffsetFrames = file.ReadInt32 ();
int OffsetGlCommands = file.ReadInt32 ();
int OffsetEnd = file.ReadInt32 ();
frames_Count = NumFrames;
vertex_Count = NumVertices;
face_Count = NumTriangles;
uv_count = NumTexCoords;
file.BaseStream.Seek(OffsetTriangles,SeekOrigin.Begin);
Debug.Log("Num triangles"+NumTriangles);
for (int i=0; i<NumTriangles; i++)
{
int v0, v1, v2;
//vertex face
v0 =(int) file.ReadUInt16 ();
v1 =(int) file.ReadUInt16 ();
v2 =(int) file.ReadUInt16 ();
faces.Add (new Face (v0, v1, v2));
//texture faces
v0 =(int) file.ReadUInt16();
v1 =(int) file.ReadUInt16 ();
v2 =(int) file.ReadUInt16 ();
tfaces.Add (new Face (v0, v1, v2));
}
file.BaseStream.Seek(OffsetTexCoords,SeekOrigin.Begin);
Debug.Log("Num TextureCoord"+NumTexCoords);
for (int i=0; i<NumTexCoords; i++)
{
float u=(float) file.ReadInt16()/SkinWidth;
float v=(float)1*- file.ReadInt16()/SkinWidth;
uvCoords.Add(new Vector2(u,v));
}
//**************************************************
file.BaseStream.Seek(OffsetFrames,SeekOrigin.Begin);
Debug.Log("Num Frames"+OffsetFrames);
for (int i=0; i<NumFrames; i++)
{
Vector3 Scale=Vector3.zero;
Vector3 Translate=Vector3.zero;
Scale.x = file.ReadSingle();
Scale.y = file.ReadSingle();
Scale.z = file.ReadSingle();
Translate.x = file.ReadSingle();
Translate.y = file.ReadSingle();
Translate.z = file.ReadSingle();
char[] name= file.ReadChars(16);
//Debug.LogWarning(new string(name));
for (int j=0; j<NumVertices; j++)
{
//.........这里部分代码省略.........
示例15: extractDbHeaders
public void extractDbHeaders()
{
Int32 nBytes;
//dbOffset = 0;
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fileStream);
try
{
for (int db = 0; db < dbCount; db++)
{
dbHeader[db] = new htbHeader();
dbHeader[db].date = br.ReadChars(26);
dbHeader[db].ldate = br.ReadInt32();//offset + 26);
dbHeader[db].cfg_file = br.ReadChars(14);
dbHeader[db].pro_file = br.ReadChars(14);
dbHeader[db].unused0 = br.ReadChars(52);
dbHeader[db].speed = br.ReadUInt32();// offset + 110);
dbHeader[db].alloc = br.ReadUInt32();
dbHeader[db].offset = br.ReadInt32(); // offset + 118);
dbHeader[db].period = br.ReadUInt32(); // GetULONG(fid, offset + 122);
dbHeader[db].extension = br.ReadUInt32(); // GetULONG(fid, offset + 126);
dbHeader[db].skip = br.ReadUInt16();// GetUSHORT(fid, offset + 130);
dbHeader[db].first_channel = br.ReadUInt16();// GetUSHORT(fid, offset + 132);
dbHeader[db].nchannels = br.ReadUInt16();// GetUSHORT(fid, offset + 134);
dbHeader[db].sweep_limit = br.ReadUInt16();// GetUSHORT(fid, offset + 136);
dbHeader[db].cancel_override = br.ReadUInt32();// GetULONG(fid, offset + 138);
dbHeader[db].func = br.ReadByte(); // GetUCHAR(fid, offset + 142);
br.ReadByte();
dbHeader[db].tag = br.ReadUInt16(); // GetUSHORT(fid, offset + 144);
//br.ReadByte();
dbHeader[db].npages = br.ReadUInt16(); //GetUSHORT(fid, offset + 146);
dbHeader[db].nsamples = br.ReadUInt32(); //GetULONG(fid, offset + 148);
dbHeader[db].samples_per_page = br.ReadUInt16(); //GetUSHORT(fid, offset + 152);
dbHeader[db].sweep = br.ReadUInt16();// GetUSHORT(fid, offset + 154);
dbHeader[db].next_page = br.ReadUInt16();// GetUSHORT(fid, offset + 156);
dbHeader[db].next_off = br.ReadUInt16();// GetUSHORT(fid, offset + 158);
dbHeader[db].title = br.ReadChars(80); // GetString(fid, offset + 160, 80);
dbHeader[db].speed_units = br.ReadUInt32(); // GetULONG(fid, offset + 240);
dbHeader[db].filler = br.ReadChars(268);
dbOffset[0] = 0;
for (int i = 1; i < db+1; i++)
{
dbOffset[db] = dbOffset[db] + (int)dbHeader[i - 1].alloc;
}
br.BaseStream.Position += dbHeader[db].alloc - dbHeader[db].size() + 1;
}
}
finally { br.Close(); fileStream.Close(); }
}