Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save peroon/9c07cb5390056917c6f4 to your computer and use it in GitHub Desktop.

Select an option

Save peroon/9c07cb5390056917c6f4 to your computer and use it in GitHub Desktop.
IEnumerator LoadFromTextData(){
string path;
#if UNITY_EDITOR
path = "file://" + Application.streamingAssetsPath + "/TextData/PhaseTime.txt";
#else
path = Application.streamingAssetsPath + "/TextData/PhaseTime.txt";
#endif
Debug.Log ("path : " + path);
string text;
WWW data = new WWW(path);
yield return data;
if (string.IsNullOrEmpty (data.error)) {
text = data.text;
} else {
Debug.Log ("テキストロードエラー");
text = "text load error";
}
// 空白除去
text = Regex.Replace(text, @"\s+", "");
// Debug.Log ("テキストデータ : " + text);
// セミコロンで切る
string[] separator = {";"};
string[] splitted = text.Split(separator, System.StringSplitOptions.RemoveEmptyEntries);
phaseList = new List<Phase> ();
for (int i = 0; i < splitted.Length; i++) {
string rowData = splitted [i]; // 1行
// カンマで切る
string[] separator2 = {","};
string[] splitted2 = rowData.Split(separator2, System.StringSplitOptions.RemoveEmptyEntries);
var phase = new Phase ();
phase.startTime = int.Parse (splitted2 [0]);
phase.endTime = int.Parse (splitted2 [1]);
phaseList.Add (phase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment