public void LoadBuildInSceneAsync(string sceneName, Action <string, bool> loadCallback = null, LoadSceneMode mode = LoadSceneMode.Single) { if (m_CurrentLoader != null) { m_CurrentLoader.ReleaseAllRes(); m_CurrentLoader.Recycle2Cache(); m_CurrentLoader = null; } StartCoroutine(LoadSceneAsync(sceneName, loadCallback, mode, false)); }
private void OnDestroy() { if (!MonoSingleton.isApplicationQuit) { if (m_ResLoader != null) { m_ResLoader.Recycle2Cache(); m_ResLoader = null; } } }
//收集预加载资源 public static void CollectDynamicResource(UIData data, ResLoader loader, params object[] args) { if (data == null || data.panelClassType == null) { return; } //TimeDebugger timer = new TimeDebugger("PrepareDynamicResource"); //timer.Begin("P1"); var methodInfo = data.panelClassType.GetMethod("PrepareDynamicResource", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); //timer.End(); if (methodInfo == null) { //timer.Dump(-1); return; } object[] paramWrap = new object[1]; paramWrap[0] = args; //timer.Begin("P2"); object result = null; try { result = methodInfo.Invoke(null, paramWrap); } catch (Exception e) { result = null; Log.e(e); } if (result == null) { return; } if (result is List <string> ) { loader.Add2Load((List <string>)result); } else if (result is string) { loader.Add2Load((string)result); } //timer.End(); //timer.Dump(-1); }
public void LoadPageResAsync(int uiID, Transform parent, bool singleton, Action <AbstractPage> listener) { UIData data = UIDataTable.Get(uiID); if (data == null) { Log.e("Failed to load UI, Not Find UIData For:" + uiID); return; } if (singleton) { if (m_PageWrapList == null) { m_PageWrapList = new List <PageWrap>(); } PageWrap wrap = FindPageWrap(uiID); if (wrap != null) { wrap.AddListener(listener); return; } else { wrap = new PageWrap(uiID); wrap.AddListener(listener); m_PageWrapList.Add(wrap); } } if (m_ResLoader == null) { m_ResLoader = ResLoader.Allocate("PanelInfo"); } CollectDynamicResource(data, m_ResLoader); m_ResLoader.Add2Load(data.fullPath, (state, res) => { if (!state) { return; } OnPageResLoadSuccess(uiID, parent, (GameObject)res.asset, singleton, listener); }); m_ResLoader.LoadSync(); }
private bool AddSceneAB2Loader(string sceneName, ResLoader loader) { string abName = GetSceneAssetBundleName(sceneName); if (string.IsNullOrEmpty(abName)) { return(false); } loader.Add2Load(abName); return(true); }
public void PrepareTransition() { if (m_ResLoader == null) { m_ResLoader = ResLoader.Allocate("FadeInOutAnim"); } else { m_ResLoader.ReleaseAllRes(); } m_ResLoader.Add2Load("SwitchAnimShaderAnim", OnResLoadFinish); m_ResLoader.LoadAsync(); }
private void CleanPreRes() { if (m_ResLoader != null) { m_ResLoader.Recycle2Cache(); m_ResLoader = null; } if (m_TimerID > 0) { Timer.S.Cancel(m_TimerID); m_TimerID = 0; return; } }
public void SetAudio(GameObject root, string name, bool loop, bool isEnable) { if (string.IsNullOrEmpty(name)) { return; } if (m_Name == name) { return; } if (m_Source == null) { m_Source = root.AddComponent <AudioSource>(); if (!isEnable) { m_Source.enabled = isEnable; } } //防止卸载后立马加载的情况 ResLoader preLoader = m_Loader; m_Loader = null; CleanResources(); RegisterActiveAudioUnit(this); m_Loader = ResLoader.Allocate("AudioUnit"); m_IsLoop = loop; m_Name = name; m_Loader.Add2Load(name, OnResLoadFinish); if (preLoader != null) { preLoader.Recycle2Cache(); preLoader = null; } if (m_Loader != null) { m_Loader.LoadAsync(); } }
protected void OnMeshLoadResult(bool result, IRes res) { if (result) { MeshHolder holder = res.asset as MeshHolder; if (holder != null) { mesh = holder.Find(m_MeshName); } } if (m_PreLoader != null) { m_PreLoader.Recycle2Cache(); m_PreLoader = null; } }
private void CleanResources() { if (m_OnStopListener != null) { m_OnStopListener(m_ID); } UnRegisterActiveAudioUnit(this); m_Name = null; m_PlayCount = 0; m_IsPause = false; m_OnFinishListener = null; m_OnStopListener = null; m_LeftDelayTime = -1; m_CustomEventID = -1; if (m_TimeItemID > 0) { Timer.S.Cancel(m_TimeItemID); m_TimeItemID = -1; } if (m_Source != null) { if (m_Source.clip == m_AudioClip) { if (m_Source.enabled) { m_Source.Stop(); } m_Source.clip = null; } m_Source.volume = 1.0f; m_Source.pitch = 1.0f; } m_AudioClip = null; if (m_Loader != null) { m_Loader.Recycle2Cache(); m_Loader = null; } }
public void LoadPanelResAsync() { if (m_PanelState != ePanelState.UnInit) { return; } m_PanelState = ePanelState.Loading; UIData data = UIDataTable.Get(m_UIID); if (data == null) { return; } OpenParam info = GetOpenInfo(m_NextMaster); object[] args = null; if (info != null) { args = info.Args; } if (m_ResLoader == null) { m_ResLoader = ResLoader.Allocate("PanelInfo"); } CollectDynamicResource(data, m_ResLoader, args); m_ResLoader.Add2Load(data.fullPath, (state, res) => { if (!state) { return; } OnPanelResLoadSuccess((GameObject)res.asset); }); m_ResLoader.LoadSync(); }
protected override void OnClose() { if (m_Action != null) { m_Action.OnTransitionDestroy(); } m_OpenParam = null; m_Action = null; m_NextPanel = null; if (m_NextPanelResLoader != null) { m_NextPanelResLoader.Recycle2Cache(); m_NextPanelResLoader = null; } }
public void Load(string sprite) { if (m_SpriteRenderer == null) { return; } if (string.IsNullOrEmpty(sprite)) { return; } if (m_Loader != null) { m_Loader.ReleaseAllRes(); } else { m_Loader = ResLoader.Allocate("AsyncSpriteRenderer"); } m_SpriteName = sprite; m_Loader.Add2Load(sprite, (result, res) => { if (result) { m_SpriteRenderer.sprite = res.asset as Sprite; } }); if (m_IsAsync) { m_Loader.LoadAsync(); } else { m_Loader.LoadSync(); } }
public Sprite FindSprite(string spriteName, bool global = false) { Sprite result = null; if (m_SpritesData == null || m_SpritesData.Length == 0) { } else { if (m_SpritesHandler == null) { m_SpritesHandler = new SpritesHandler(); m_SpritesHandler.SetData(m_SpritesData); } result = m_SpritesHandler.FindSprite(spriteName); } if (result == null) { result = FindSpriteFromParent(spriteName, global); } if (result == null && global) { if (m_GlobalResLoader == null) { m_GlobalResLoader = ResLoader.Allocate("AbstractPage"); } result = m_GlobalResLoader.LoadSync(spriteName) as Sprite; } if (result == null) { Log.w("Not Find Sprite:" + spriteName); } return(result); }
private void InnerStartUpdate(List <ABUnit> updateList) { if (updateList == null || updateList.Count == 0) { return; } if (m_Loader != null) { Log.w("Package Handler is Working."); return; } m_Loader = ResLoader.Allocate("ResPackageHolder"); if (m_UpdateUnitMap == null) { m_UpdateUnitMap = new Dictionary <string, ABUnit>(); } else { m_UpdateUnitMap.Clear(); } for (int i = 0; i < updateList.Count; ++i) { string resName = AssetName2ResName(updateList[i].abName); m_UpdateUnitMap.Add(resName, updateList[i]); m_Loader.Add2Load(resName, OnResUpdateFinish); HotUpdateRes res = ResMgr.S.GetRes <HotUpdateRes>(resName); string relativePath = m_Package.GetABLocalRelativePath(updateList[i].abName); string fullPath = FilePath.persistentDataPath4Res + relativePath; res.SetUpdateInfo(fullPath, m_Package.GetAssetUrl(relativePath), updateList[i].fileSize, null); } m_Loader.LoadAsync(OnPackageUpdateFinish); }
public bool LoadBuildInSceneSync(string sceneName, LoadSceneMode mode = LoadSceneMode.Single) { if (m_CurrentLoader != null) { m_CurrentLoader.ReleaseAllRes(); m_CurrentLoader.Recycle2Cache(); m_CurrentLoader = null; } try { SceneManager.LoadScene(sceneName, mode); } catch (Exception e) { Log.e("SceneManager LoadBuildInSceneSysn Failed! SceneName:" + sceneName); Log.e(e); return(false); } return(true); }
private void UpdateSprites() { CleanPreRes(); if (targetImage == null || m_SpritesNames == null || m_SpritesNames.Length == 0) { return; } m_ResLoader = ResLoader.Allocate(); m_ResLoader.Add2Load(m_SpritesNames); m_ResLoader.LoadSync(); m_SpritesArray = new Sprite[m_SpritesNames.Length]; for (int i = 0; i < m_SpritesNames.Length; ++i) { m_SpritesArray[i] = ResMgr.S.GetAsset <Sprite>(m_SpritesNames[i]); } OnTimeReach(0); m_TimerID = Timer.S.Post2Scale(OnTimeReach, m_Duration, -1); }
public bool LoadABSceneFromSync(string sceneName, LoadSceneMode mode = LoadSceneMode.Single) { ResLoader nextLoader = ResLoader.Allocate("SceneMgr"); //提前加入可以起到缓存已经加载的资源的作用,防止释放后又加载的重复动作 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); }
public void OnCacheReset() { m_Panel = null; m_NextMaster = -1; m_PanelID = -1; m_UIID = -1; m_SortIndex = -1; m_PanelState = ePanelState.UnInit; m_OpenListeners = null; m_CustomVisibleFlag = true; m_ResLoader.Recycle2Cache(); m_ResLoader = null; if (m_PageWrapList != null) { m_PageWrapList.Clear(); } if (m_OpenInfoList != null) { m_OpenInfoList.Clear(); } }
public void SetMaterial(string materialName) { ResLoader loader = ResLoader.Allocate("Temp"); m_Render.material = loader.LoadSync(materialName) as Material; }
public override void OnSingletonInit() { m_Loader = ResLoader.Allocate("ResHolder"); }