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

百度做网站推广的费用网站管理建设的总结

百度做网站推广的费用,网站管理建设的总结,浙江省建设教育考试中心网站,上海外贸营销网站建设网站Unity persistentDataPath使用案例 一、Application.persistentDataPath 1、概念 persistentDataPath:此属性用于返回一个持久化数据存储目录的路径,可以在此路径下存储一些持久化的数据文件;是一个可读写的目录;此文件夹在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 List<string> collection = new List<string>();

        //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.FromJson<SaveData>(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;

    //Mac,Windows或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.yayakq.cn/news/808277/

相关文章:

  • 列出寻找网站关键词的几种途径国外平面设计教程网站
  • 有没有可以在线做化学实验的网站做pc网站排
  • 网站如何做反爬qq浏览器官网
  • 公众号制作的网站开发核心关键词举例
  • 营销网站怎么做合适山西建设工程执业注册中心网站
  • 哪个网站建设公司比较好站长工具亚洲
  • 上海新闻频道seo学途论坛网
  • 集约化网站建设项目郑州开发小程序平台
  • 长白山网站学做管理平台简述网站首页制作过程
  • 网站代运营价格windows8风格网站模板
  • 自己做的网页怎么上传网站电脑手机网站建设
  • app设计网站推荐大型门户网站系统
  • 网站做支付需要准备什么数据库和网站
  • 个人备案网站营业执照wordpress 插件 爬文章
  • 宁波建设银行网站首页ui设计线上培训
  • 沂源网站建设yx718一般网站使用什么做的
  • 久久建筑网站内搜索喂来苏州网络科技有限公司
  • 如何做招生网站网络推广网站怎么做
  • 成都网站制作计划宝塔重装WordPress
  • 2008iis7建立网站别人做的网站域名到期怎么办
  • 猎头做单都有什么网站东莞网站建设 手袋厂
  • 襄阳门户网站建设六灶网站建设
  • 牡丹江做网站建设wordpress列表分页 js
  • 马蜂窝网站怎么做ic设计公司排名
  • 寺庙 网站建设营销推广怎么做
  • 营销网站建设创意做公众号必备的网站
  • 温州中豪网站建设推广短视频培训课程
  • 顺的网站建设策划全国建设信息网
  • 湖北洈水水利水电建设公司网站上海微信网站建设公司
  • 网站源码带手机版品牌营销策划服务