public BinaryReader PlayFileToBinary (string _fname)
{
TextAsset _textAsset = Resources.Load (_fname) as TextAsset;
Stream _s;
//if file not exist read from device storage
if (_textAsset == null) {
_s = GetBinaryFileStream (_fname);
} else {
_s = new MemoryStream (_textAsset.bytes);
}
BinaryReader br = new BinaryReader (_s, Encoding.Default);
return br;
}
//get file from device storage
public Stream GetBinaryFileStream (string _fname)
{
string a_filePath = DeviceFilePath (_fname + ".txt");
FileStream a_fstrem = new FileStream (a_filePath, FileMode.Open, FileAccess.Read);
byte[] a_fileByte = null;
a_fileByte = new byte[a_fstrem.Length];
a_fstrem.Read (a_fileByte, 0, (int)a_fstrem.Length);
Stream a_sw = new MemoryStream (a_fileByte);
return a_sw;
}
public string DeviceFilePath (string _fname = null)
{
string _path = "";
if (Application.platform == RuntimePlatform.Android) {
_path = Application.persistentDataPath;
_path = _path.Substring (0, _path.LastIndexOf ('/'));
} else if (Application.platform == RuntimePlatform.IPhonePlayer) {
_path = Application.persistentDataPath;
_path = _path.Substring (0, _path.LastIndexOf ('/'));
_path = _path + "/Documents";
} else {
_path = Application.dataPath;
_path = _path.Substring (0, _path.LastIndexOf ('/'));
}
if (_fname == null) {
return _path;
}
return _path + "/" + _fname; // Path.Combine (_path, _fname);
}
----
----
BinaryReader _br = PlayFileToBinary(filename);
_bodyInfo.VerSion_1 = _br.ReadByte ();
_bodyInfo.TracCount = _br.ReadInt32 ();
_bodyInfo.BeatPerMs = _br.ReadSingle ();
_bodyInfo.Bpm = _br.ReadInt32 ();
_bodyInfo.TotalTime = _br.ReadUInt32 ();
'Programming > 유니티' 카테고리의 다른 글
안드로이드 스튜디오 플러그인 만들기 (2018.11.03) : aar 형식 (3) | 2018.11.03 |
---|---|
UGUI - UI Button OnClick 리스너 비활성화 (0) | 2017.06.24 |
UGUI - text 글자길이에 맞게 Recttransform 크기 변경하기 (recttransform resize as text length) (1) | 2017.02.17 |
c# 타임스템프 사용하기 (0) | 2017.02.13 |
c# 숫자앞에 0 넣기 (0) | 2017.02.13 |