Esempio n. 1
0
    /// <summary>
    /// 返回资源的路径。
    /// 在PC平台下,直接返回GetAssetBundlePath()路径下的资源路径
    /// 在iOS平台下先查询iOSAssetPath下,如果资源存在,则返回这个资源,否则再查询 /myapplication.app/目录下。
    /// 外部类应该使用这个接口来获取某一个资源的路径
    /// 如果updated为true,用以上逻辑,false的情况,只从.app路径里读取
    /// </summary>
    /// <param name="assetName">文件名</param>
    /// <param name="extname">文件后缀名</param>
    /// <returns>file://文件路径</returns>
    public static string GetResourceURL(string assetName, string extname, bool tryCacheFirst)
    {
        string cachedDataPath     = GamePath.GetCachedAssetBundlePath();
        string cachedDataPathFull = null;

        if (cachedDataPath != null)
        {
            cachedDataPath     = string.Format("{0}{1}.{2}", cachedDataPath, assetName, extname);
            cachedDataPathFull = "file:///" + cachedDataPath;
        }
        string dataPath     = string.Format("{0}{1}.{2}", GamePath.GetLocalAssetPath(), assetName, extname);
        string dataPathFull = string.Format("{0}{1}.{2}", GamePath.GetLocalAssetPathFullQualified(), assetName, extname);

        if (tryCacheFirst && cachedDataPath != null)
        {
            if (File.Exists(cachedDataPath))
            {
                Debug.Log("[GetResourceURL]dataPath = " + cachedDataPathFull);
                return(cachedDataPathFull);
            }
        }

        // #if !USE_FINAL_DATA
        //         if (GamePlatform.InEditor)
        //         {
        //             string editorDataPath = string.Format("{0}{1}.{2}", Application.dataPath + "/Binaries/", assetName, extname);
        //             //editor优先使用Binary中的数据
        //             if (File.Exists(editorDataPath))
        //             {
        //                 //DebugOutPut.Log("dataPath = " + editorDataPath, DebugLogLevel.LogLevel1);
        //                 return "file://" + editorDataPath;
        //             }
        //         }
        // #endif
        if (File.Exists(dataPath))
        {
            Debug.Log("[GetResourceURL]dataPath = " + dataPathFull);
            return(dataPathFull);
        }
        else
        {
            DebugUtil.Error("Can not find dataPath = " + dataPath + "!!!");
        }

        //DebugOutPut.Log("data not found : " + dataPath, DebugLogLevel.LogLevel5);
        return(null);
    }