您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
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+"//" + 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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。