阅读背景:

Unity对应各平台的路径配置,跟别人不一样的写法

来源:互联网 

    /// <summary>
    /// 根据平台和加载位置,返回资源的完整加载路径
    /// </summary>
    /// <returns>完整路径.</returns>
    /// <param name="name">文件名</param>
    /// <param name="path">资源的加载位置</param>
    public static string GetLocalURL( string name = "", PathType path = PathType.persistent)
    {
        string URL = "";

        string typePath = "";
        try
        {
            if (path == PathType.persistent)
            {
                typePath = Application.persistentDataPath;
            }
            else
            {
                typePath = Application.streamingAssetsPath;
            }
        }
        catch (Exception e)
        {
            Debug.LogError(e.ToString());
        }

#if UNITY_STANDALONE_WIN || UNITY_EDITOR
        
        	    URL = "file://" + typePath + "/" + name;

#elif UNITY_ANDROID
		
			URL = typePath + "/"+name; 
		
#elif UNITY_IOS
		
			URL = "file://"+ typePath + "/"+name; 
		
#endif

        if (!File.Exists(URL))
        {
            if (path == PathType.persistent)
            {
                return GetLocalURL(name, PathType.streaming);
            }
            else
            {
                Debug.Log("资源文件不存在:"+name);
            }
        }
        
        return URL;
    }    /// <summary>
    /// 根据平台和加载位置,返回资源的完整加



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: