下保存和读取资源(保存到文件夹目录)_第1页
下保存和读取资源(保存到文件夹目录)_第2页
下保存和读取资源(保存到文件夹目录)_第3页
下保存和读取资源(保存到文件夹目录)_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Unity3DIOS下保存和读取资源(保存到文件夹目录)Postedon2013年07月08日byU3d/\o"查看Unity3D脚本/插件中的全部文章"Unity3D脚本/插件/被围观33次

001002usingUnityEngine;003

004usingSystem.Collections;005

006usingSystem.IO;007

008usingSystem;009

010

011publicclassNvTestSave:MonoBehaviour012

013{014

015

016

017privatestringshowtext="nottxthasbeenloaded!";018

019

020

021publicstringJsonPath022

023{024

025get{026

027stringpath=null;028

029if(Application.platform==RuntimePlatform.IPhonePlayer)030

031{032

033path=Application.dataPath.Substring(0,Application.dataPath.Length-5);034

035path=path.Substring(0,path.LastIndexOf('/'))+"/Documents/";036

037}038

039else040

041{042

043path=Application.dataPath+"/Resource/GameData/";044

045}046

047returnpath;048

049}050

051}052

053

054

055//Usethisforinitialization056

057voidStart()058

059{060

061SaveJson("ilovecoding!!","MyText.txt");062

063StartCoroutine(WaitForRead());064

065}066

067

068

069//Updateiscalledonceperframe070

071voidUpdate()072

073{074

075

076

077}078

079

080

081voidOnGUI()082

083{084

085GUI.Label(newRect(10,10,500,20),showtext);086

087}088

089

090

091voidShowText(stringtext)092

093{094

095showtext=text;096

097}098

099

100

101IEnumeratorWaitForRead()102

103{104

105yieldreturnnewWaitForSeconds(0.5f);106

107StartCoroutine(InstanceText("MyText.txt"));108

109}110

111//Unity3D教程手册:112

113IEnumeratorInstanceText(stringfileName)114

115{116

117stringpath="file://"+JsonPath+fileName;118

119

120

121Debug.LogError("======path:"+path);122

123WWWwwwText=newWWW(path);124

125yieldreturnwwwText;126

127Debug.LogError("======ShowText");128

129ShowText(wwwText.text);130

131}132

133//Unity3D教程手册:134

135voidSaveJson(stringtxt,stringfilepathandname)136

137{138

139stringfile=JsonPath+"//"+filepathandname;140

141

142

143StreamWritersw;144

145FileInfot=newFileInfo(file);146

147if(!t.Exists)148

149{150

151sw=t.CreateText();152

153}154

155else156

157{158

1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论