Exemple #1
0
    protected IEnumerator InstantiateSpriteAsync(string assetBundleName, string assetName, LoadBundleAssetCallback <Sprite> callBack, Hashtable param)
    {
        if (_ResFromBundle)
        {
            AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(Sprite));
            if (request == null)
            {
                Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + assetBundleName + ".");
                yield break;
            }
            yield return(StartCoroutine(request));

            Sprite resData = request.GetAsset <Sprite>();

            if (callBack != null)
            {
                callBack.Invoke(assetName, resData, param);
            }
        }
        else
        {
            Sprite resData = Resources.Load <Sprite>(assetBundleName);

            if (callBack != null)
            {
                callBack.Invoke(assetName, resData, param);
            }
        }
    }
Exemple #2
0
    protected IEnumerator InstantiateGameObjectAsync(string assetBundleName, string assetName, LoadBundleAssetCallback <GameObject> callBack, Hashtable param)
    {
        if (_ResFromBundle)
        {
            AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject));
            if (request == null)
            {
                Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + assetBundleName + ".");
                yield break;
            }
            yield return(StartCoroutine(request));

            GameObject prefab     = request.GetAsset <GameObject>();
            var        instanceGO = GameObject.Instantiate(prefab);

            if (callBack != null)
            {
                callBack.Invoke(assetName, instanceGO, param);
            }
        }
        else
        {
            //Debug.Log("LoadPrefab:" + assetBundleName);
            GameObject prefab     = Resources.Load <GameObject>(assetBundleName);
            var        instanceGO = GameObject.Instantiate(prefab);

            if (callBack != null)
            {
                callBack.Invoke(assetName, instanceGO, param);
            }
        }
    }
Exemple #3
0
    public void LoadEffect(string effectRes, LoadBundleAssetCallback <EffectController> callBack, Hashtable hash)
    {
        if (_LoadedEffects.ContainsKey(effectRes))
        {
            callBack.Invoke(effectRes, _LoadedEffects[effectRes], hash);
            return;
        }

        string effectPath = "Effect/" + effectRes;

        ResourceManager.Instance.LoadPrefab(effectPath, (effectName, effectGo, callBackHash) =>
        {
            EffectController effct = effectGo.GetComponent <EffectController>();
            effct.transform.SetParent(transform);
            effct.name = effectName;
            _LoadedEffects.Add(effectRes, effct);
            callBack.Invoke(effectRes, _LoadedEffects[effectRes], callBackHash);
        }, hash);
    }
Exemple #4
0
    public void LoadModel(string modelName, LoadBundleAssetCallback <GameObject> callBack, Hashtable hash)
    {
        if (_IdleModelItems.ContainsKey(modelName))
        {
            var instance = PopIdleModel(modelName);
            callBack.Invoke(modelName, instance, hash);
            return;
        }

        string modelPath = "Model/" + modelName;

        ResourceManager.Instance.LoadPrefab(modelPath, (resName, modelGO, callBackHash) =>
        {
            modelGO.transform.SetParent(transform);
            modelGO.name = modelName;
            _IdleModelItems.Add(modelName, new Stack <GameObject>());
            _IdleModelItems[modelName].Push(modelGO);
            var instance = PopIdleModel(modelName);
            callBack.Invoke(modelName, instance, hash);
        }, hash);
    }
Exemple #5
0
    public IEnumerator LoadPrefab(string prefabName, LoadBundleAssetCallback <GameObject> callBack)
    {
        string bundleName = "Asset/" + prefabName + ".common";
        string assetName  = System.IO.Path.GetFileNameWithoutExtension(bundleName);

        if (_ResFromBundle)
        {
            AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(bundleName.ToLower(), assetName, typeof(GameObject));
            if (request == null)
            {
                Debug.LogError("Failed AssetBundleLoadAssetOperation on " + assetName + " from the AssetBundle " + bundleName + ".");
                yield break;
            }
            yield return(StartCoroutine(request));

            GameObject prefab = request.GetAsset <GameObject>();
            Debug.Log("LoadPrefab:" + prefabName);
            var instanceGO = GameObject.Instantiate(prefab);

            callBack.Invoke(assetName, instanceGO, null);
        }
        else
        {
            Debug.Log("LoadPrefab:" + bundleName);
            GameObject resData    = Resources.Load <GameObject>(prefabName);
            var        instanceGO = GameObject.Instantiate(resData);

            Debug.Log("LoadPrefab instanceGO:" + prefabName);
            if (callBack != null)
            {
                callBack.Invoke(assetName, instanceGO, null);
            }

            Debug.Log("LoadPrefab callBack.Invoke:" + prefabName);
        }
    }
Exemple #6
0
    public void LoadConfig(string resName, LoadBundleAssetCallback <GameObject> callBack, Hashtable hash)
    {
        if (_LoadedConfig.ContainsKey(resName))
        {
            GameObject configInstance = GameObject.Instantiate(_LoadedConfig[resName]);
            callBack.Invoke(resName, configInstance, hash);
            return;
        }

        string resPath = resName;

        ResourceManager.Instance.LoadPrefab(resPath, (effectName, effectGo, callBackHash) =>
        {
            effectGo.transform.SetParent(transform);
            effectGo.name = effectName;
            if (!_LoadedConfig.ContainsKey(resName))
            {
                _LoadedConfig.Add(resName, effectGo);
            }

            GameObject configInstance = GameObject.Instantiate(_LoadedConfig[resName]);
            callBack.Invoke(resName, configInstance, hash);
        }, hash);
    }
Exemple #7
0
    public void SetImage(Image image, string spriteName, LoadBundleAssetCallback <Sprite> callBack = null, Hashtable hash = null)
    {
        var valid = false;

        if (image != null)
        {
            if (image.sprite == null)
            {
                image.enabled = false;
                valid         = true;
            }
            else
            {
                valid = !image.sprite.name.Equals(spriteName);
            }
        }
        if (!valid)
        {
            return;
        }

        string bundleName = "Icon/" + spriteName;

        if (_ResFromBundle)
        {
            bundleName = "Asset/" + bundleName + ".common";
            bundleName = bundleName.ToLower();
        }
        string assetName = System.IO.Path.GetFileNameWithoutExtension(bundleName);

        StartCoroutine(InstantiateSpriteAsync(bundleName, assetName, (resName, resData, hashParam) =>
        {
            image.enabled = true;
            image.sprite  = resData;
            if (callBack != null)
            {
                callBack.Invoke(resName, resData, hash);
            }
        }, null));
    }