Unity3D中各种Path

Unity中Path在不同平台下值

IOS:

Application.dataPath :                    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data

Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw

Application.persistentDataPath :    Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents

Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches

Android:

Application.dataPath :            /data/app/xxx.xxx.xxx.apk

Application.streamingAssetsPath :    jar:file:///data/app/xxx.xxx.xxx.apk/!/assets

Application.persistentDataPath :    /data/data/xxx.xxx.xxx/files

Application.temporaryCachePath :    /data/data/xxx.xxx.xxx/cache

Windows Web Player:

Application.dataPath :            file:///D:/MyGame/WebPlayer (即导包后保存的文件夹,html文件所在文件夹)

Application.streamingAssetsPath :

Application.persistentDataPath :

Application.temporaryCachePath :

****************************************************************************************************************

路径拼装方法:

    public class PathUtils
    {
        private static PathUtils _instance = null;
        public static PathUtils Instance()
        {
            if (_instance == null)
            {
                _instance = new PathUtils();
            }
            return _instance;
        }

        //private static string ApplicationDataPath = "";
        private static string ApplicationStreamingPath = "";
        private static string ApplicationPersistentDataPath = "";
        private static string ApplicationTemporaryDataPath = "";
        private static bool m_bIsEditor = false;

        public enum UnityPathType
        {
            UnityPath_Resources = 0,    // Unity内置路径,只支持Resource.Load方法读取 
            UnityPath_StreamAsset,      // Unity流目录,只读目录
            UnityPath_PersistentData,   // Untity持久目录, 支持读写 文本文件或者二进制文件可以存放 
            UnityPath_TemporaryCache,   // Unity临时缓存目录 功能同 UnityPath_PersistentData
        }


        public PathUtils()
        {
            //ApplicationDataPath = Application.dataPath + "/";
            if (Application.platform == RuntimePlatform.Android) /// Application.streamingAssetsPath在安卓平台下已经自带了 jar:file:///
            {
                ApplicationStreamingPath = Application.dataPath + "!/assets/";
            }
            else
            {
                ApplicationStreamingPath = Application.streamingAssetsPath + "/";
            }


            ApplicationPersistentDataPath = Application.persistentDataPath + "/";
            ApplicationTemporaryDataPath = Application.temporaryCachePath + "/";
        }


       /// <summary>
        /// 获取文件钱路径 支持文件系统 UnityPath_StreamAesset目录在安卓平台只支持www的方式来读取
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public string FullPathFileName(ref string strFileName, UnityPathType pathType = UnityPathType.UnityPath_PersistentData)
        {
            string strFullPath = "";


            switch (pathType)
            {
                case UnityPathType.UnityPath_StreamAsset:
                    strFullPath = ApplicationStreamingPath + strFileName;
                    break;
                case UnityPathType.UnityPath_PersistentData:
                    strFullPath = ApplicationPersistentDataPath + strFileName;
                    break;
                case UnityPathType.UnityPath_TemporaryCache:
                    strFullPath = ApplicationTemporaryDataPath + strFileName;
                    break;
                case UnityPathType.UnityPath_CustomPath:
                    strFullPath = ResourcePath + strFileName;
                    break;
            }


            return strFullPath;
        }


        /// <summary>
        /// 获取文件URL路径 URL格式的路径则必须使用www来读取
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public string FullUrlFileName(ref string strFileName, UnityPathType pathType = UnityPathType.UnityPath_StreamAsset)
        {
            string strFullUrl = "";


            switch (pathType)
            {
                case UnityPathType.UnityPath_StreamAsset:
                    strFullUrl = ApplicationStreamingPath + strFileName;
                    break;
                case UnityPathType.UnityPath_PersistentData:
                    strFullUrl = ApplicationPersistentDataPath + strFileName;
                    break;
                case UnityPathType.UnityPath_TemporaryCache:
                    strFullUrl = ApplicationTemporaryDataPath + strFileName;
                    break;
                case UnityPathType.UnityPath_CustomPath:
                    strFullUrl = ResourcePath + strFileName;
                    break;
            }


            switch (Application.platform)
            {
                case RuntimePlatform.Android:
                    if (pathType == UnityPathType.UnityPath_StreamAsset)
                    {
                        strFullUrl = "jar:file://" + strFullUrl;
                    }
                    else
                    {
                        strFullUrl = "file://" + strFullUrl;
                    }
                    break;
                case RuntimePlatform.IPhonePlayer:
                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                case RuntimePlatform.OSXEditor:
                    {
                        strFullUrl = "file://" + strFullUrl;
                    }
                    break;
            }


            return strFullUrl;
        }
}

转载于:https://my.oschina.net/windeer/blog/1547834

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值