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); } } }
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); } } }
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); }
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); }
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); } }
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); }
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)); }