public void LoadABSceneAsync(string sceneName, Action <string, bool> loadCallback = null, LoadSceneMode mode = LoadSceneMode.Single) { ResLoader nextLoader = ResLoader.Allocate(); //可以起到缓存已经加载的资源的作用,防止释放后又加载的重复动作 if (!AddSceneAB2Loader(sceneName, nextLoader)) { if (loadCallback != null) { loadCallback(sceneName, false); } return; } if (m_CurrentLoader != null) { m_CurrentLoader.ReleaseAllRes(); m_CurrentLoader.Recycle2Cache(); m_CurrentLoader = null; } m_CurrentLoader = nextLoader; m_CurrentLoader.LoadAsync(() => { StartCoroutine(LoadSceneAsync(sceneName, loadCallback, mode, true)); }); }
private static AppConfig LoadInstance() { if (m_ResLoader != null) { m_ResLoader.ReleaseAllRes(); } if (m_ResLoader == null) { m_ResLoader = ResLoader.Allocate(null); } m_ResLoader.Add2Load(ProjectPathConfigTemp.APP_CONFIG_PATH); m_ResLoader.LoadSync(); IRes res = ResMgr.Instance.GetRes(ProjectPathConfigTemp.APP_CONFIG_PATH, false); if (res != null) { s_Instance = res.asset as AppConfig; } return(s_Instance); }
public static AssetBundleManifest LoadInstance() { ResLoader loader = ResLoader.Allocate(); AssetBundleManifest manifest = loader.LoadSync(QFrameworkConfigData.ABMANIFEST_ASSET_NAME) as AssetBundleManifest; loader.UnloadImage(false); return(manifest); }
public static AssetBundleManifest LoadInstance() { ResLoader loader = ResLoader.Allocate(); AssetBundleManifest manifest = loader.LoadSync(ProjectPathConfigTemp.ABMANIFEST_ASSET_NAME) as AssetBundleManifest; loader.UnloadImage(false); return(manifest); }
// Use this for initialization void Start() { // 添加创建器 ResFactory.AddResCreator <MyResCreator>(); var resLoader = ResLoader.Allocate(); var resSearchKeys = ResSearchKeys.Allocate("myres://hello_world"); var myRes = resLoader.LoadResSync(resSearchKeys); resSearchKeys.Recycle2Cache(); Debug.Log(myRes.AssetName); Debug.Log(myRes.State); }
/// <summary> /// 添加常驻音频资源,建议尽早添加,不要在用的时候再添加 /// </summary> void AddRetainAudio(string audioName) { if (mRetainResLoader == null) { mRetainResLoader = ResLoader.Allocate(); } if (mRetainAudioNames == null) { mRetainAudioNames = new List <string>(); } if (!mRetainAudioNames.Contains(audioName)) { mRetainAudioNames.Add(audioName); mRetainResLoader.Add2Load(audioName); mRetainResLoader.LoadAsync(); } }
// Use this for initialization private IEnumerator Start() { var loader = ResLoader.Allocate(); ResMgr.Init(); var spriteAtlas = loader.LoadSync <SpriteAtlas>("spriteatlas"); var square = spriteAtlas.GetSprite("Square"); Log.I(spriteAtlas.spriteCount); mImage.sprite = square; yield return(new WaitForSeconds(5.0f)); loader.Recycle2Cache(); loader = null; }
public void SetAudio(GameObject root, string name, bool loop) { if (string.IsNullOrEmpty(name)) { return; } if (mName == name) { return; } if (mAudioSource == null) { mAudioSource = root.AddComponent <AudioSource>(); } //防止卸载后立马加载的情况 var preLoader = mLoader; mLoader = null; CleanResources(); mLoader = ResLoader.Allocate(); mIsLoop = loop; mName = name; mLoader.Add2Load(name, OnResLoadFinish); if (preLoader != null) { preLoader.Recycle2Cache(); preLoader = null; } if (mLoader != null) { mLoader.LoadAsync(); } }
public bool LoadABSceneFromSync(string sceneName, LoadSceneMode mode = LoadSceneMode.Single) { ResLoader nextLoader = ResLoader.Allocate(); //提前加入可以起到缓存已经加载的资源的作用,防止释放后又加载的重复动作 if (!AddSceneAB2Loader(sceneName, nextLoader)) { return(false); } if (m_CurrentLoader != null) { m_CurrentLoader.ReleaseAllRes(); m_CurrentLoader.Recycle2Cache(); m_CurrentLoader = null; } m_CurrentLoader = nextLoader; m_CurrentLoader.LoadSync(); try { SceneManager.LoadScene(sceneName, mode); } catch (Exception e) { Log.e("SceneManager LoadABSceneFromSync Failed! SceneName:" + sceneName); Log.e(e); UnloadSceneAssetBundle(sceneName); return(false); } UnloadSceneAssetBundle(sceneName); return(true); }
/// <summary> /// 增加UI层 /// </summary> public T CreateUI <T>(QUILevel level, QUIData initData = null) where T : QUIBehaviour { string behaviourName = GetUIBehaviourName <T> (); QUIBehaviour ui; if (mAllUI.TryGetValue(behaviourName, out ui)) { Debug.LogWarning(behaviourName + ": already exist"); //直接返回,不要再调一次Init(),Init()应该只能调用一次 return(ui as T); } ResLoader resLoader = ResLoader.Allocate(); GameObject prefab = resLoader.LoadSync(behaviourName) as GameObject; GameObject mUIGo = Instantiate(prefab); switch (level) { case QUILevel.Bg: mUIGo.transform.SetParent(mBgTrans); break; case QUILevel.Common: mUIGo.transform.SetParent(mCommonTrans); break; case QUILevel.PopUI: mUIGo.transform.SetParent(mPopUITrans); break; case QUILevel.Const: mUIGo.transform.SetParent(mConstTrans); break; case QUILevel.Toast: mUIGo.transform.SetParent(mToastTrans); break; case QUILevel.Forward: mUIGo.transform.SetParent(mForwardTrans); break; } var uiGoRectTrans = mUIGo.GetComponent <RectTransform> (); uiGoRectTrans.offsetMin = Vector2.zero; uiGoRectTrans.offsetMax = Vector2.zero; uiGoRectTrans.anchoredPosition3D = Vector3.zero; uiGoRectTrans.anchorMin = Vector2.zero; uiGoRectTrans.anchorMax = Vector2.one; mUIGo.transform.localScale = Vector3.one; mUIGo.gameObject.name = behaviourName; Debug.Log(behaviourName + " Load Success"); ui = mUIGo.AddComponent <T>(); mAllUI.Add(behaviourName, ui); ui.Init(resLoader, initData); return(ui as T); }