纳金网

标题: Unity各种路径总结 [打印本页]

作者: 烟雨    时间: 2015-9-30 19:46
标题: Unity各种路径总结

Application.persistentDataPath
http://docs.unity3d.com/ScriptRe ... istentDataPath.html
Contains the path to a persistent data directory (Read Only).
设备中的公开目录,根据平台的不同而不同。这里面的文件不会因为App升级而删除;

Application.streamingAssetsPath
http://docs.unity3d.com/ScriptRe ... mingAssetsPath.html
工程目录下面的Assets/StreamingAssets。

Application.temporaryCachePath
http://docs.unity3d.com/ScriptRe ... oraryCachePath.html
Contains the path to a temporary data / cache directory (Read Only).
设备的临时存储路径。

Application.dataPath
http://docs.unity3d.com/ScriptReference/Application-dataPath.html
游戏数据的存储路径:
Contains the path to the game data folder (Read Only).
The value depends on which platform you are running on:
unity Editor: <path to project folder>/Assets
Mac player: <path to player app bundle>/Contents
iPhone player: <path to player app bundle>/<AppName.app>/Data
Win player: <path to executablename_Data folder>
Web player: The absolute url to the player data file folder (without the actual data file name)
Flash: The absolute url to the player data file folder (without the actual data file name)
Note that the string returned on a PC will use a forward slash as a folder separator.


public static string GetStreamingFilePath( string filename)  
    {  
        string path = "";  
   
   
        if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||  
            Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)  
            path = Application.dataPath + "/StreamingAssets/" + filename;  
        else if ( Application.platform == RuntimePlatform .IPhonePlayer)  
            path = Application.dataPath + "/Raw/" + filename;  
        else if ( Application.platform == RuntimePlatform .Android)  
            path = "jar:file://" + Application .dataPath + "!/assets/" + filename;  
        else
            path = Application.dataPath + "/config/" + filename;  
   
   
        return path;  
    }  
   
   
   
    public static string GetPersistentFilePath( string filename)  
    {  
        string filepath;  
   
   
        if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||  
            Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)  
            filepath = Application.dataPath + "/StreamingAssets/" + filename;  
        else if ( Application.platform == RuntimePlatform .IPhonePlayer || Application.platform == RuntimePlatform .Android)  
            filepath = Application.persistentDataPath + "/" + filename;  
        else
        {  
            filepath = Application.persistentDataPath + "/" + filename;  
        }
#if UNITY_IPHONE  
        iPhone.SetNoBackupFlag(filepath);
#endif  
        return filepath;  
    }





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5