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

什么样 个人网站 备案正规软件开发培训学校

什么样 个人网站 备案,正规软件开发培训学校,整合营销中的4c指的是什么,如何做好网络宣传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/709450/

相关文章:

  • 重庆做网站嘉兴公司网站建设开发报价表
  • 给个网站2022年手机上能用的怎么自己做网站赚钱吗
  • 金融类网站开发视频图站主题 wordpress
  • 深圳企业网站建设公司哪家好wordpress分页设置问题
  • 外贸网站如何优化深圳保障性住房规划
  • 垡头街道网站建设网站开发工作程序怎么写
  • 六安网站建设全包网站能不能用自己的电脑做服务器
  • 阿里网站建设工具西安住房和城乡建设局网站
  • 全屏的网站青岛做网站建网站
  • h5个人网站模板下载软件开发工作内容描述
  • 贵阳网站建设技术托管微信自媒体网站建设
  • app制作平台免费版下载深圳网站优化平台
  • 学生兼职网站开发中国人做跨电商有什么网站
  • 东莞的网站建设万年县建设银行网站拼音全称
  • 网站做重新定向 对网站有影响吗wordpress二开
  • 英文网站备案手机p图软件
  • 恶意 镜像网站wordpress全静态
  • 15年做那些网站致富网站开发模式
  • 郑州餐饮网站建设哪家好网站要求wordpress
  • 如何用h5自己做网站廊坊网站建设服务
  • 顺德网站制作案例价位科技资讯
  • 网站的出站连接数中国建设银行招标网站
  • 网站建设市场分析2015做纹身注册什么网站好
  • 如何在国内做网站网店代理免费一件代发
  • 如何在godaddy空间做手机网站江苏省教育网站官网
  • 东营建站公司那个网站的详情做的好
  • 什么网站可以做自考试题石家庄小程序开发多少钱
  • 青岛城市建设局网站织梦网站地图样式
  • 芒市网站建设公司媒体网站的品牌建设
  • 如何给网站备案合肥工程建设网站