Beispiel #1
0
    public Object Load(string bundleName, string assetName, ELoadType loadType)
    {
        if (string.IsNullOrEmpty(bundleName))
        {
            return(null);
        }

        int nHashCode = bundleName.GetHashCode();

        LoadedAssetBundle loaded = ABManager.Instance.GetLoadedBundle(nHashCode);

        if (loaded != null)
        {
            loaded.Count();
        }
        else
        {
            loaded = LoadSyn(bundleName);
        }

        if (loaded != null)
        {
            loaded.mLoadType = loadType;
            Object asset = null;
            if (loaded.mAssetBundle != null)
            {
                AssetBundle ab = loaded.mAssetBundle;

                if (string.IsNullOrEmpty(assetName))
                {
                    asset = ab.mainAsset != null ? ab.mainAsset : ab.LoadAsset(ab.GetAllAssetNames()[0]);
                    if (asset != null)
                    {
                        loaded.SetMainAsset(asset);
                    }
                }
                else
                {
                    loaded.MapAssets();
                    asset = loaded.LoadAsset(assetName);
                }
                ABManager.Instance.AfterLoad(loaded);
                //Debug.Log("<color=yellow>assetName:" + assetName + "</color>");
            }
            else
            {
                asset = loaded.LoadAsset(assetName);
                //Debug.Log("<color=red>assetName:"+ assetName + "</color>");
            }
            return(asset);
        }
        return(null);
    }