Unity3D IOS下保存和读取资源(保存到文件夹目录)
![](/upload/ad_content/xuanchuantu-22.jpg)
创新互联始终坚持【策划先行,效果至上】的经营理念,通过多达十载累计超上千家客户的网站建设总结了一套系统有效的全网整合营销推广解决方案,现已广泛运用于各行各业的客户,其中包括:
成都湿喷机等企业,备受客户夸奖。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();
}
}
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
当前文章:Unity3DIOS下保存和读取资源(保存到文件夹目录)-创新互联
本文来源:
http://cdxtjz.cn/article/eeggi.html