いちいち、androidで見るのもめんどうなので
どっちも使えるようにしてみる。
こっちの方が先に、見つけました。
---------ReadTxtScr.cs Android対応---------
using UnityEngine;
using System.Collections;
using System.IO; //System.IO.FileInfo, System.IO.StreamReader, System.IO.StreamWriter//File.ReadAllLines
public class ReadTxtScr : MonoBehaviour {
public string guitxt = "";
private string outputFileName = "ReadText.txt";
private string line;
TextReader txtReader;
void Start()
{
StartCoroutine("LoadText2");
}
void OnGUI()
{
GUI.TextArea(new Rect(5, 55, Screen.width, 100), guitxt);
}
IEnumerator LoadText()
{
string txtBuffer = "";
string path = "";
#if UNITY_EDITOR
path = Application.streamingAssetsPath + "\\" + outputFileName;
FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
txtReader = new StreamReader(file);
yield return new WaitForSeconds(0f);
#elif UNITY_ANDROID
path = "jar:file://" + Application.dataPath + "!/assets" + "/" + outputFileName;
WWW www = new WWW(path);
yield return www;
txtReader = new StringReader(www.text);
#endif
while ((txtBuffer = txtReader.ReadLine()) != null)
{
guitxt = guitxt + txtBuffer + "\r\n";
}
}
}
---------ReadTxtScr.cs Android対応---------
#if UNITY_EDITOR //Windows 上の Unity エディター
#elif UNITY_ANDROID //Android プレイヤー
のように、場合分けをした。
if (Application.platform == RuntimePlatform.Android) {
// Android
}
else if (Application.platform == RuntimePlatform.WindowsEditor) {
// Windows 上の Unity エディター
}
else {
}
という、場合分けもできる。
- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2017/03/04(土) 21:41:42|
- Unity
-
| トラックバック:0
-
| コメント:0