Unity 获得不同平台下文件的保存路径

该代码示例展示了在Unity中如何根据不同的运行平台(如编辑器、Android、iOS等)获取文件的持久化存储路径。在Android上,路径为`jar:file:// + Application.dataPath + "!/assets/"`,在iOS上,路径为`Application.dataPath + "/Raw"`,而在PC上,路径为`Application.dataPath + "/StreamingAssets"`。
摘要由CSDN通过智能技术生成

/// <summary>
/// 获得不同平台下文件的路径
/// </summary>
public class GetFilePath
{
    /// <summary>
    /// 获得当前文件保存的路径
    /// </summary>
    /// <returns></returns>
    public static string getPath()
    {
        string src =
#if UNITY_EDITOR
 Application.persistentDataPath;
#elif UNITY_ANDROID
  Application.persistentDataPath;
#else
 Application.persistentDataPath;
#endif
        return src;
    }

    public static string FilePath = "";//文件的路径

    /// <summary>
    /// 获得不同平台文件的保存位置
    /// </summary>
    /// <returns></returns>
    public static string GetPath()
    {
        if (Application.isMobilePlatform)
        {
            if (Application.platform == RuntimePlatform.Android)
            {
                //安卓平台
                FilePath = "jar:file://" + Application.dataPath + "!/assets/";
                return FilePath;
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                //IOS平台
                FilePath = Application.dataPath + "/Raw";
                return FilePath;
            }
            else
            {
                return FilePath;
            }
        }
        else
        {
            //PC平台
            FilePath = Application.dataPath + "/StreamingAssets";
            return FilePath;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值