当前位置: 首页 > news >正文

图书馆 网站建设网页设计师报名费

图书馆 网站建设,网页设计师报名费,锦州网站优化,wordpress安装的模板Unity persistentDataPath使用案例 一、Application.persistentDataPath 1、概念 persistentDataPath#xff1a;此属性用于返回一个持久化数据存储目录的路径#xff0c;可以在此路径下存储一些持久化的数据文件#xff1b;是一个可读写的目录#xff1b;此文件夹在Edi…Unity persistentDataPath使用案例 一、Application.persistentDataPath 1、概念 persistentDataPath此属性用于返回一个持久化数据存储目录的路径可以在此路径下存储一些持久化的数据文件是一个可读写的目录此文件夹在Editor阶段没有手机安装App后自动生成 关联的概念-Unity项目文件夹StreamingAssets只能读,不能写。 2、应用场景 1手机应用场景中存储当前游戏的进度以便下次运行游戏时读取 如下代码文件存储游戏中的下列数据coins、starCount 0、collection [Serializable] public class SaveData { //Current loaded save file public static SaveData save; private static string fileName; //Unsaved global variables public static bool checkpoint false; public static Vector3 checkpointPos; public static Quaternion checkpointRot; public static bool hubPositionSet false; //Saved variables public int coins 0; public int starCount 0; public Liststring collection new Liststring(); //Save public void Save() { System.IO.File.WriteAllText(fileName, JsonUtility.ToJson(this)); } //Load (Make sure fileName is set, will be loaded if it exists) public static bool Load() { if (System.IO.File.Exists(fileName)) { save JsonUtility.FromJsonSaveData(System.IO.File.ReadAllText(fileName)); hubPositionSet true; return true; } else return false; } //Create new game public static void NewGame() { save new SaveData(); hubPositionSet false; } public static void SetFileName(string name) { fileName Path.Combine(Application.persistentDataPath, name .json); } //Null check public static void NullCheck() { if (save null) { SetFileName(TestSave); if (!Load()) NewGame(); Debug.Log(Hello Mario Framework: Using test save file!); hubPositionSet false; } } //Get coin count public int GetCoins() { return coins; } //Add or remove coins public void AddCoins(int i) { coins i; } //Collect a single coin public void CollectCoin() { coins; } //Get star count public int GetStarCount() { return starCount; } //Collect a star (Or ignore if already collected) public bool CollectStar(string name) { if (AddCollection(name)) { starCount; return true; } else return false; } //Add to collection public bool AddCollection(string id) { if (!collection.Contains(id)) { collection.Add(id); return true; } else return false; } //Check if something is in the collection public bool CheckCollection(string id) { return collection.Contains(id); } } 2放置一些首次运行时需要的可读写的数据文件 将游戏运行时需要的可读写的文件模板放到只读文件夹“StreamingAssets”手机首次运行时再拷贝到可读写的目录“Application.persistentDataPath” 如下实例游戏在手机平台首次运行时将我们的数据模板文件”data.txt”拷贝到“persistentDataPath”目录以便于以后在手机端游戏运行时实时读写。 public void copy(string fileName data.txt) { string url; //MacWindows或Linux平台 #if UNITY_EDITOR || UNITY_STANDALONE url $file://{Application.dataPath}/StreamingAssets/{fileName}; //ios平台路径 #elif UNITY_IPHONE url $file://{Application.dataPath}/Raw/{fileName}; //安卓路径 #elif UNITY_ANDROID url $jar:file://{Application.dataPath}!/assets/{fileName}; #endif string persistentUrl ${Application.persistentDataPath}/{fileName}; if (!File.Exists(persistentUrl)) { Debug.Log(${persistentUrl} 文件不存在,从StreamingAssets中Copy!); WWW www new WWW(url); while (true) { if (www.isDone) { if (www.error null) { //本次读的文本 File.WriteAllText(persistentUrl, www.text);    File.WriteAllBytes(path, www.bytes); Debug.Log($持久化目录: {persistentUrl}); break; } else { Debug.LogWarning($没得到StreamingAssets的文件 : {fileName}); } } } } else { Debug.Log(${persistentUrl} 文件已存在!); } }
http://www.hkea.cn/news/14580468/

相关文章:

  • 福建省住房城乡建设部网站99作文网
  • 分布式网站开发wordpress文章调用代码
  • 企业网站推广方案设计做网站常规语言
  • 农业农村部农田建设管理司网站打开连接 wordpress
  • 网站seo优化多少钱qq网页版输入账号登录
  • 甘肃温室大棚建设网站山西响应式网页建设哪家有
  • 驰业网站建设网站网络推广优化哪家好
  • 做智能家居网站做网站联盟
  • 做淘客网站需要备案温州手机网站建设wmwl
  • 给用ps做的网站加div乐山 网站建设
  • 网站建设 交易保障温州网站制作系统
  • 东莞网站建设公司制作网站广东官网网站建设企业
  • 北京中燕建设公司网站如何选择电商网站建设
  • 托里县城乡建设局网站hdwiki做网站
  • html5做网站好吗手机上怎么设计logo
  • 做印刷的网站有哪些网站主机的选择与优化
  • 推广网站的步骤做网站的赚钱吗
  • 甜品店网站开发背景中国人去菲律宾做网站赌钱会抓吗
  • 阿里云虚拟主机多个网站吗做网站销售好吗
  • 天天联盟广告网站如何做沈阳网站模板
  • 网站备案没有了seo统计
  • centos 网站开发工具南京正规小程序开发公司
  • 网站设计可以吗免费公司介绍网站怎么做
  • 乌兰察布市建设银行网站html网页设计颜色代码
  • 网站建设不完整 审核网站建设课程设计实验指导书
  • 平面设计网站首页新手做导航网站
  • 同人那个小说网站做的最好dede 友情链接 网站简况 调用
  • 做视频赚钱的网站wordpress 屏蔽
  • 江苏工信部网站备案查询济南效果图制作公司
  • 上海做网站吧wordpress默认分类链接