//-------------------------------------------------------------------------
    void _loadAssetBundleCallBack(string asset_path, AssetBundle asset_bundle)
    {
        if (asset_bundle != null)
        {
            MapBundle[asset_path] = asset_bundle;
            Dictionary <LoaderTicket, Action <LoaderTicket, string, UnityEngine.Object> > map_ticketandcallback = null;
            if (MapLoaderTicketAndCallBack.TryGetValue(asset_path, out map_ticketandcallback))
            {
                foreach (var ticket in map_ticketandcallback)
                {
                    string asset_name = ticket.Key.UserData;
                    string asset_key  = asset_path + asset_name;
                    var    asset      = asset_bundle.LoadAsset(asset_name);
                    if (!MapBundleAsset.ContainsKey(asset_key))
                    {
                        MapBundleAsset[asset_key] = asset;
                    }

                    ticket.Value(ticket.Key, asset_key, asset);
                }

                map_ticketandcallback.Clear();
                MapLoaderTicketAndCallBack.Remove(asset_path);
            }
        }
    }
    //-------------------------------------------------------------------------
    public LoaderTicket getAsset(string asset_path, string asset_name, _eAsyncAssetLoadType loader_type,
                                 Action <LoaderTicket, string, UnityEngine.Object> bundle_asset_callback)
    {
        LoaderTicket loader_ticket = null;

        UnityEngine.Object bundle_asset = null;
        string             asset_key    = asset_path + asset_name;

        if (MapBundleAsset.TryGetValue(asset_key, out bundle_asset))
        {
            bundle_asset_callback(loader_ticket, asset_key, bundle_asset);
        }
        else
        {
            if (loader_type == _eAsyncAssetLoadType.LocalBundleAsset)
            {
                if (MapBundle.ContainsKey(asset_path))
                {
                    var asset_bundle = MapBundle[asset_path];
                    bundle_asset = asset_bundle.LoadAsset(asset_name);
                    bundle_asset_callback(loader_ticket, asset_key, bundle_asset);
                }
                else
                {
                    loader_ticket = AsyncAssetLoaderMgr.LocalBundleAsyncLoader.getAssetBundle(asset_path, _loadAssetBundleCallBack);
                }
            }
            else
            {
                loader_ticket = AsyncAssetLoaderMgr.WWWAsyncLoader.getIsDoneWWW(asset_path, _loadAssetWWWCallBack);
            }

            if (loader_ticket != null)
            {
                loader_ticket.UserData = asset_name;
                Dictionary <LoaderTicket, Action <LoaderTicket, string, UnityEngine.Object> > map_ticketandcallback = null;
                if (!MapLoaderTicketAndCallBack.TryGetValue(asset_path, out map_ticketandcallback))
                {
                    map_ticketandcallback = new Dictionary <LoaderTicket, Action <LoaderTicket, string, UnityEngine.Object> >();
                    MapLoaderTicketAndCallBack[asset_path] = map_ticketandcallback;
                }
                map_ticketandcallback[loader_ticket] = bundle_asset_callback;
            }
        }

        return(loader_ticket);
    }
Exemple #3
0
    //-------------------------------------------------------------------------
    void _loadAssetWWWCallBack(string asset_path, WWW www)
    {
        if (www != null && www.isDone)
        {
            Dictionary <LoaderTicket, Action <LoaderTicket, string, UnityEngine.Object> > map_ticketandcallback = null;
            if (MapLoaderTicketAndCallBack.TryGetValue(asset_path, out map_ticketandcallback))
            {
                foreach (var ticket in map_ticketandcallback)
                {
                    string             asset_name = ticket.Key.UserData;
                    string             asset_key  = asset_path + asset_name;
                    UnityEngine.Object load_asset = null;
                    if (!MapBundleAsset.ContainsKey(asset_key))
                    {
                        if (string.IsNullOrEmpty(www.error))
                        {
                            if (www.texture != null)
                            {
                                load_asset = www.texture;
                            }
                            else if (www.GetAudioClip() != null)
                            {
                                load_asset = www.GetAudioClip();
                            }
                            else if (www.assetBundle != null)
                            {
                                load_asset = www.assetBundle;
                            }
                            MapBundleAsset[asset_key] = load_asset;
                        }
                    }

                    MapBundleAsset.TryGetValue(asset_key, out load_asset);
                    ticket.Value(ticket.Key, asset_key, load_asset);
                }

                map_ticketandcallback.Clear();
                MapLoaderTicketAndCallBack.Remove(asset_path);
            }
        }
    }
Exemple #4
0
 //-------------------------------------------------------------------------
 public void Close()
 {
     MapBundle.Clear();
     MapBundleAsset.Clear();
     MapLoaderTicketAndCallBack.Clear();
 }