public static string AssetBundleUrl2Name(string url)
        {
            string retName = null;
            var    parren  = FilePath.StreamingAssetsPath + "AssetBundles/" + PlatformUtil.GetPlatformName() + "/";

            retName = url.Replace(parren, "");

            parren  = FilePath.PersistentDataPath + "AssetBundles/" + PlatformUtil.GetPlatformName() + "/";
            retName = retName.Replace(parren, "");
            return(retName);
        }
        public static string AssetBundleName2Url(string name)
        {
            var retUrl = FilePath.PersistentDataPath + "AssetBundles/" + PlatformUtil.GetPlatformName() + "/" + name;

            if (File.Exists(retUrl))
            {
                return(retUrl);
            }

            return(FilePath.StreamingAssetsPath + "AssetBundles/" + PlatformUtil.GetPlatformName() + "/" + name);
        }
Exemple #3
0
 public ResourceUpdate(ResourceManager resourceManager)
 {
     platform        = PlatformUtil.GetPlatformName();
     assetBundlePath = Application.persistentDataPath + "/" + platform;
     if (!Directory.Exists(assetBundlePath))
     {
         Directory.CreateDirectory(assetBundlePath);
     }
     this.resourceManager = resourceManager;
     localConfig          = new Dictionary <string, string>();
     newConfig            = new Dictionary <string, string>();
     updateFiles          = new List <string>();
 }
Exemple #4
0
    private static int GetPlatformName(IntPtr L)
    {
        int result;

        try
        {
            ToLua.CheckArgsCount(L, 1);
            PlatformUtil platformUtil = (PlatformUtil)ToLua.CheckObject(L, 1, typeof(PlatformUtil));
            string       platformName = platformUtil.GetPlatformName();
            LuaDLL.lua_pushstring(L, platformName);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaDLL.toluaL_exception(L, e, null);
        }
        return(result);
    }
            /// <summary>
            /// 读取AssetBundle
            /// </summary>
            /// <returns></returns>
            public IEnumerator ReadAll()
            {
                //从streamingAsset中读取
                if (resourceManager.readType == ReadType.FromStreamingAssets)
                {
                    assetBundlePath = Application.streamingAssetsPath + "/" + PlatformUtil.GetPlatformName();
                    yield return(FileUtil.ReadStreamingFile(assetBundlePath + "/config.txt", (data) =>
                    {
                        if (data != null)
                        {
                            localConfig = FileUtil.TxtToDic(data.text);
                            Debug.Log("读取资源配置文件");
                        }
                    }));
                }
                //从persistentPath中读取
                if (resourceManager.readType == ReadType.FromPersistentPath)
                {
                    assetBundlePath = Application.persistentDataPath + "/" + PlatformUtil.GetPlatformName();
                    localConfig     = FileUtil.TxtToDic(File.ReadAllText(assetBundlePath + "/config.txt"));
                }

                foreach (var item in localConfig)
                {
                    if (item.Key == "version")
                    {
                        continue;
                    }
                    Debug.Log("加载AssetBundle:" + item.Key);
                    AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(assetBundlePath + "/" + item.Key);
                    yield return(request);

                    if (request.assetBundle == null)
                    {
                        onReadError?.Invoke();
                        yield break;
                    }
                    else
                    {
                        AddBundle(request.assetBundle);
                    }
                }
                onReadCompleted?.Invoke();
            }