unity安卓环境特殊文件夹(热更时候的用法)

来源:互联网 发布:淘宝实物有色差 编辑:程序博客网 时间:2024/04/30 00:08
  1. Application.dataPath  这个不想过多结束。此属性用于返回程序的数据文件所在文件夹的路径。例如在Editor中就是Assets了。
  2. Application.streamingAssetsPath     这个文件夹内的东西可读不可以写,可以被复制和替换,但是不能被删除。热更新涉及的Assetbundle和Lua文本一般都放在这个文件夹下。
  3. Application.persistentDataPath       这个文件夹在运行过程中既可以读也可以写。可以用File.Exist,也可以用File.Delete。但是注意在安卓移动平台下不能用File.Copy(),只能用www类来下载。然后用File.WriteAllBite这个文件夹来复制。

  1. coldshower一般在做热更的时候会把服务器的资源下载到Application.persistentDataPath ,然后再把Application.persistentDataPath 中的资源替换到

Application.streamingAssetsPath 。之后再异步判断一下Application.persistentDataPath这个资源还有吗,有的话用File.Delete的方法删除。这里注意必须用异步的方法。CS我在试验的时候发现,用同步的方法有时候不能删除Application.persistentDataPath这个文件夹内的东西。


我在下面的项目中用了移动平台动态读取Debug内容的方法,

我们需要借助 Android SDK 来查看可以使用双击打开,但是我以前这样打开会 时不时的自动退出,,以我自己的路径为例(先连接手机,手机打开开发者模式,打开USB调试,还有别把手机设成只充电模式):然后找到,打开 sdk 路径下 E:\Android\sdk\tools ,按住shift,右键,在此处选择用命令窗口打开,然后输入ddms.bat  


接下来就是和这位老哥一样的方法了http://blog.csdn.net/u014230923/article/details/51615746

最后放上我工程的代码截图.项目下载为链接: https://pan.baidu.com/s/1jHLp9sU 密码: u4se



using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;




public class lzysd : MonoBehaviour {
    // Use this for initialization
    void Start()
    {
        m_infile = DataPathTWO + "index.xml";
        m_outfile = DataPath + "index.xml";
        if (Directory.Exists(DataPath)) Directory.Delete(DataPath, true);
        Directory.CreateDirectory(DataPath);
        if (Directory.Exists(DataPath))
        {
            Debug.Log("今天在手机上也可以创建文件夹");
        }


        StartCoroutine(OnExtractResource2());


    }


    // Update is called once per frame
    void Update()
    {




    }
    string m_infile = "";
    string m_outfile = "";
    string GUIwenzi = "";


    public void WAYTWO()
    {


        if (Application.platform == RuntimePlatform.Android)
        {


            StartCoroutine(OnExtractResource3());


        }
    }


    IEnumerator OnExtractResource2()
    {




     
        WWW www2 = new WWW(m_infile);
        yield return www2;


        if (www2.isDone)
        {
            Debug.Log("今天在手机上的沙盒中仍然存在文件++++++");
            File.WriteAllBytes(m_outfile, www2.bytes);
        }




        www2.Dispose();
        www2 = null;


         www2 = new WWW(m_outfile);
        yield return www2;


        if (www2.isDone)
        {
            Debug.Log("今天在手机上的沙盒中仍然存在文件--------------");
            File.WriteAllBytes(m_infile, www2.bytes);
        }


        //  www3.Dispose();


        Thrre();
        www2.Dispose();
        www2 = null;
        //临时增加,会被删除
        StartCoroutine(OnExtractResource3());
        yield break;


    }


    IEnumerator OnExtractResource3()
    {
        yield return new WaitForSeconds(0);


        if (File.Exists(m_outfile))
        {
            File.Delete(m_outfile);
            Debug.Log("今天在手机上的沙盒中仍然存在文件+3");


        }
        else
        {
            Debug.Log("今天在手机上的沙盒中文件直接就没有了+3");
        }
        if (File.Exists(m_outfile))
        {
            Debug.Log("今天在手机上的沙盒中仍然存在文件");


        }
        else
        {
            Debug.Log("今天在手机上的沙盒中文件直接就没有了+1");
        }


      
    }


    void Thrre()
    {
        if (File.Exists(m_outfile))
        {
            Debug.Log("今天在手机上的沙盒中仍然存在文件");


        }
        else
        {
            Debug.Log("今天在手机上的沙盒中文件直接就没有了+1");
        }




        if (File.Exists(m_outfile))
        {
            Debug.Log("今天在手机上的沙盒中仍然存在文件+2");


        }
        else
        {
            Debug.Log("今天在手机上的沙盒中文件直接就没有了+2");
        }


        if (File.Exists(m_outfile))
        {
            File.Delete(m_outfile);
            Debug.Log("今天在手机上的沙盒中仍然存在文件+3");


        }
        else
        {
            Debug.Log("今天在手机上的沙盒中文件直接就没有了+3");
        }
    }












    public string DataPath
    {
        get
        {


            if (Application.isMobilePlatform)
            {
                return Application.persistentDataPath + "/";
            }
            return "c:/";
        }
    }


    public string DataPathTWO
    {
        get
        {


            if (Application.isMobilePlatform)
            {
                return Application.streamingAssetsPath + "/";
            }
            return "c:/";
        }
    }


}