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

wordpress 今日头条快速排名优化推广手机

wordpress 今日头条,快速排名优化推广手机,松江城乡建设委员会的网站,商城网站建设是什么意思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.zhongyajixie.com/news/13184.html

相关文章:

  • 网站平台做推广方案谷歌推广一年多少钱
  • 网站视频做背景如何做好网络销售技巧
  • 天津制作公司网站seo点石论坛
  • 网站关键词seo怎么做公司想做网络推广贵不
  • 厦门市同安区建设工程质量安全监督站网站seo知识点
  • 关键字挖掘爱站网厦门网络推广外包
  • 自己做报名网站教程为企业策划一次网络营销活动
  • 红色色系做网站的配色seo做的比较牛的公司
  • h5在哪个网站中做直播引流推广方法
  • 怎么用html做图片展示网站今天株洲最新消息
  • html企业网站系统下载手机百度最新版
  • 做盗版网站吗公司网站设计要多少钱
  • 温州中小企业网站建设想在百度上推广怎么做
  • 网站开发代码无中文外贸接单十大网站
  • 网站建设一条龙全包谷歌建站
  • 网站怎么做不违法吗电商培训机构排名
  • 给公司做网站需要多少钱发布新闻
  • 备案网站内容说明茶叶网络营销策划方案
  • 做一个展示型网站多少钱怀化seo推广
  • 成都网站搭建公司市场调研分析
  • 云主机和云服务器有什么区别seo快速入门教程
  • 建设网站租服务器今日国际新闻大事件
  • 网络服务示范区创建情况商丘seo
  • 网站 功能建设上 不足佛山百度提升优化
  • 做门户网站挣钱吗网站描述和关键词怎么写
  • 网站建设售后服务内容山西seo基础教程
  • 网站建设选择北京华网天下优势的seo网站优化排名
  • 六安网站建设 220做网站推广好做吗
  • 做网站不会P图怎么办百度推广开户渠道公司
  • 采购在哪些网站开发供应商昆明seocn整站优化