Ejemplo n.º 1
0
    public IEnumerator LoadSpriteAtlasFromAB(ABFileURL _fileURL, Action <SpriteAtlas> _saDealer, string _spriteAltasName)
    {
        bool loadingSA = true;

        // Check AB already in Disk
        yield return(StartCoroutine(CoreABDownloader(
                                        _fileURL,
                                        (UnityWebRequest _uwr) => {
            StartCoroutine(AsyncLoadSAFromAB(_uwr,
                                             (SpriteAtlas _sa) =>
            {
                _saDealer(_sa);
                loadingSA = false;
            },
                                             _spriteAltasName
                                             ));
        },
                                        null, // fail
                                        null  // progress
                                        )));

        while (loadingSA)
        {
            yield return(null);
        }

        Debug.Log("LoadSpriteAtlasFromAB Finished");
    }
Ejemplo n.º 2
0
    public IEnumerator LoadTextureFromAB(ABFileURL _fileURL, Action <List <Texture2D> > _textureDealer, params string[] _textureNames)
    {
        bool loadingTexture = true;

        // Check AB already in Disk
        yield return(StartCoroutine(CoreABDownloader(
                                        _fileURL,
                                        (UnityWebRequest _uwr) => {
            StartCoroutine(AsyncLoadFromAB <Texture>(_uwr,
                                                     (List <UnityEngine.Object> _txts) =>
            {
                var result = new List <Texture2D>();
                for (int i = 0; i < _txts.Count; i++)
                {
                    result.Add(_txts[i] as Texture2D);
                }
                _textureDealer(result);
                loadingTexture = false;
            },
                                                     _textureNames
                                                     ));
        },
                                        null,
                                        null
                                        )));

        while (loadingTexture)
        {
            yield return(null);
        }

        Debug.Log("Load Textures Finished");
    }
Ejemplo n.º 3
0
    /// <summary>
    /// CoreABDownloader is BOTH AssetBundle DOWNLOADER and USER
    /// It checks AB_Hash with Cache then download Latest AB if it has to
    /// </summary>
    /// <param name="_fileURL"></param>
    /// <param name="_success"></param>
    /// <param name="_fail"></param>
    /// <param name="_progress"></param>
    IEnumerator CoreABDownloader(ABFileURL _fileURL, Action <UnityWebRequest> _success = null, Action <string> _fail = null, Action <float> _progress = null)
    {
        if (myABM == null)
        {
            Debug.LogError("ABM not loaded!");
        }

        Hash128 abHash = myABM.GetAssetBundleHash(_fileURL.fileName);

        //Clean up older AB in Cache
        Caching.ClearOtherCachedVersions(_fileURL.fileName, abHash);

        Debug.Log("Try to Download " + _fileURL);

#if UNITY_2018_1_OR_NEWER
        using (var _uwr = UnityWebRequestAssetBundle.GetAssetBundle(_fileURL.fullURL, abHash, 0))
#else
        using (var _uwr = UnityWebRequest.GetAssetBundle(_fileURL.fullURL, abHash, 0))
#endif
        {
            _uwr.SendWebRequest();

            yield return(null);

            while (!_uwr.isDone)
            {
                if (_progress != null)
                {
                    _progress(_uwr.downloadProgress);
                }

                yield return(null);
            }

            if (_uwr.isNetworkError || _uwr.isHttpError)
            {
                Debug.LogError("File Download Failed " + _uwr.error);
                if (_fail != null)
                {
                    _fail(_uwr.error);
                }
            }
            else
            {
                if (_success != null)
                {
                    _success(_uwr);
                }
            }

            yield return(null);

            yield return(null);

            yield return(null);
        }
    }
Ejemplo n.º 4
0
    public IEnumerator LoadGameObjetFromAB(ABFileURL _fileURL, List <ObjectNamePosition> _GameObjDesc)
    {
        bool loadingGO = true;

        var nameArr = new string[_GameObjDesc.Count];

        for (int i = 0; i < _GameObjDesc.Count; i++)
        {
            nameArr[i] = _GameObjDesc[i].name;
        }

        yield return(StartCoroutine(CoreABDownloader(
                                        _fileURL,
                                        (UnityWebRequest _uwr) => {
            StartCoroutine(AsyncLoadFromAB <GameObject>(_uwr,
                                                        (List <UnityEngine.Object> _objs) =>
            {
                for (int i = 0; i < _objs.Count; i++)
                {
                    Instantiate((_objs[i] as GameObject), _GameObjDesc[i].position, Quaternion.identity);
                }

                loadingGO = false;
            },
                                                        nameArr
                                                        ));
        },
                                        null,
                                        null
                                        )));

        while (loadingGO)
        {
            yield return(null);
        }

        Debug.Log("LoadGameObjetFromAB Finished");
    }