Last active
April 10, 2020 11:37
-
-
Save openroomxyz/6fe5c8a41316052341c493956f2aaec4 to your computer and use it in GitHub Desktop.
Unity : How to read Binary File Until The End of it (size not written inside file )?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ReadBinFile(string path, System.Action<Vector3, float> f) | |
{ | |
if (!File.Exists(path)) //if file does not exist we will not try reading it | |
{ | |
return; | |
} | |
BinaryReader br; | |
//reading from the file | |
try | |
{ | |
br = new BinaryReader(new FileStream(path, FileMode.Open)); | |
} | |
catch (IOException e) | |
{ | |
Debug.Log(e.Message + "\n Cannot open file."); | |
return; | |
} | |
try | |
{ | |
while (br.BaseStream.Position != br.BaseStream.Length) | |
{ | |
float x = br.ReadSingle(); | |
float y = br.ReadSingle(); | |
float z = br.ReadSingle(); | |
float radij = br.ReadSingle(); | |
int second = br.ReadInt32(); | |
f(new Vector3(x, y, z), radij); | |
} | |
} | |
catch (IOException e) | |
{ | |
Debug.Log(e.Message + "\n Cannot read from file."); | |
return; | |
} | |
br.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment