您好,登錄后才能下訂單哦!
Unity3D IOS下保存和讀取資源(保存到文件夾目錄)
using UnityEngine; using System.Collections; using System.IO; using System; public class NvTestSave : MonoBehaviour { private string showtext = "not txt has been loaded!"; public string JsonPath { get{ string path=null; if(Application.platform==RuntimePlatform.IPhonePlayer) { path= Application.dataPath.Substring (0, Application.dataPath.Length - 5); path = path.Substring(0, path.LastIndexOf('/'))+"/Documents/"; } else { path=Application.dataPath+"/Resource/GameData/"; } return path; } } // Use this for initialization void Start () { SaveJson(" i love coding!!","MyText.txt"); StartCoroutine(WaitForRead()); } // Update is called once per frame void Update () { } void OnGUI() { GUI.Label(new Rect(10, 10, 500, 20), showtext); } void ShowText(string text) { showtext = text; } IEnumerator WaitForRead( ) { yield return new WaitForSeconds(0.5f); StartCoroutine(InstanceText("MyText.txt")); } //Unity3D教程手冊:www.unitymanual.com IEnumerator InstanceText(string fileName) { string path="file://"+JsonPath+fileName; Debug.LogError("======path: "+path); WWW wwwText=new WWW(path); yield return wwwText; Debug.LogError("======ShowText"); ShowText(wwwText.text); } //Unity3D教程手冊:www.unitymanual.com void SaveJson(string txt , string filepathandname) { string file = JsonPath+"http://" + filepathandname; StreamWriter sw; FileInfo t = new FileInfo(file); if(!t.Exists) { sw = t.CreateText(); } else { sw = t.AppendText(); } sw.WriteLine(txt); sw.Close(); sw.Dispose(); } }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。