private AssetBundle DoGetAssetBundle(string assetBundlePath)
    {
        if (dAssetBundles.ContainsKey(assetBundlePath))
        {
            return(dAssetBundles[assetBundlePath]);
        }
        var path = UStaticFuncs.ConfigSaveDir + "/" + assetBundlePath;

        if (!File.Exists(path))
        {
            return(null);
        }
        var ab = AssetBundle.LoadFromFile(path);

        if (ab == null)
        {
            return(null);
        }
        dAssetBundles.Add(assetBundlePath, ab);
        var depends = OnGetAssetBundleDependeces(UStaticFuncs.GetAssetBundleName(assetBundlePath));

        foreach (var d in depends)
        {
            OnGetAssetBundle(assetBundlePath);
        }
        return(ab);
    }
Exemple #2
0
    public T OnLoadAsset <T>(string assetBundlePath) where T : UnityEngine.Object
    {
        T prefab = null;

#if UNITY_EDITOR
        if (!UConfigManager.bUsingAb)
        {
            prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RemoteResources/" + assetBundlePath, typeof(T)) as T;
            if (prefab != null)
            {
                return(prefab);
            }
            if (assetBundlePath.Contains("."))
            {
                assetBundlePath = assetBundlePath.Substring(0, assetBundlePath.LastIndexOf("."));
            }
        }
#endif
        if (!UConfigManager.bUsingAb)
        {
            prefab = Resources.Load <T>(assetBundlePath);
        }
        if (prefab)
        {
            return(prefab);
        }

        assetBundlePath = assetBundlePath.ToLower();
        var assetName = UStaticFuncs.GetAssetBundleName(assetBundlePath);
        if (dAssets.ContainsKey(assetName) && dAssets[assetName] != null && dAssets[assetName] is T)
        {
            return(dAssets[assetName] as T);
        }
        var deps = OnGetAssetBundleDependeces(assetBundlePath + AssetBundleSuffix);
        foreach (var dep in deps)
        {
            OnGetAssetBundle(UStaticFuncs.GetAssetBundleName(dep));
        }
        var ab = OnGetAssetBundle(assetBundlePath);
        if (ab == null)
        {
            return(Resources.Load <T>(assetBundlePath));
        }
        var t = ab.LoadAsset <T>(assetName);
        dAssets.Add(assetName, t);
        return(t);
    }
    public void DownloadConfig(Action downloadConfigComplete)
    {
        //UILoading.SetLoadingContent("正在加载远端配置表。");
        UAssetBundleDownloader.Instance.DownloadResources((list) =>
        {
            foreach (var str in list)
            {
                var assetName = UStaticFuncs.GetAssetBundleName(str);
                if (!dExcelLoaders.ContainsKey(assetName))
                {
                    continue;
                }
                dExcelLoaders[assetName](UAssetBundleDownloader.Instance.OnLoadAsset <TextAsset>(str).text);
            }

            downloadConfigComplete?.Invoke();
        }
                                                          , null, filter, dExcelLoaders.Keys.ToArray());
    }
Exemple #4
0
    public T OnLoadAsset <T>(string assetBundlePath) where T : UnityEngine.Object
    {
        Debug.Log($"OnLoadAsset Enter.bUsingAb:{Enter.bUsingAb}");
#if UNITY_EDITOR
        if (!Enter.bUsingAb)
        {
            var prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RemoteResources/" + assetBundlePath, typeof(T)) as T;
            if (prefab != null)
            {
                return(prefab);
            }
            else
            {
                prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RemoteResources/" + assetBundlePath + ".prefab", typeof(T)) as T;
                if (prefab != null)
                {
                    return(prefab);
                }
            }
        }
#endif
        if (!Enter.bUsingAb)
        {
            var path = assetBundlePath;
            if (path.Contains("."))
            {
                path = path.Split('.')[0];
            }
            return(Resources.Load <T>(path));
        }

        var assetName = UStaticFuncs.GetAssetBundleName(assetBundlePath);
        if (dAssets.ContainsKey(assetName) && dAssets[assetName] != null && dAssets[assetName] is T)
        {
            return(dAssets[assetName] as T);
        }
        var ab = OnGetAssetBundle(assetBundlePath);
        if (ab == null)
        {
            return(Resources.Load <T>(assetBundlePath));
        }
        var deps = OnGetAssetBundleDependeces(assetBundlePath + AssetBundleSuffix);
        foreach (var dep in deps)
        {
            OnGetAssetBundle(dep);
        }
        if (dAssets.ContainsKey(assetName) &&
            dAssets[assetName] != null)
        {
            return(dAssets[assetName] as T);
        }
        var t = ab.LoadAsset <T>(assetName);
        if (t == null)
        {
            return(t);
        }
        if (dAssets.ContainsKey(assetName))
        {
            dAssets[assetName] = t;
        }
        else
        {
            dAssets.Add(assetName, t);
        }
        return(t);
    }