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 + "/";
        }


       ///


        /// 获取文件钱路径 支持文件系统 UnityPath_StreamAesset目录在安卓平台只支持www的方式来读取
        ///

        ///
        ///
        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;
        }


        ///
        /// 获取文件URL路径 URL格式的路径则必须使用www来读取
        ///

        ///
        ///
        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;
        }
}

你可能感兴趣的:(游戏引擎,Unity3D)