예제 #1
0
파일: SceneMgr.cs 프로젝트: moto2002/Hunter
        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));
        }
예제 #2
0
 private void OnDestroy()
 {
     if (!MonoSingleton.isApplicationQuit)
     {
         if (m_ResLoader != null)
         {
             m_ResLoader.Recycle2Cache();
             m_ResLoader = null;
         }
     }
 }
예제 #3
0
파일: UIMgr.cs 프로젝트: moto2002/Hunter
//收集预加载资源
        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);
        }
예제 #4
0
            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();
            }
예제 #5
0
파일: SceneMgr.cs 프로젝트: moto2002/Hunter
        private bool AddSceneAB2Loader(string sceneName, ResLoader loader)
        {
            string abName = GetSceneAssetBundleName(sceneName);

            if (string.IsNullOrEmpty(abName))
            {
                return(false);
            }

            loader.Add2Load(abName);

            return(true);
        }
예제 #6
0
        public void PrepareTransition()
        {
            if (m_ResLoader == null)
            {
                m_ResLoader = ResLoader.Allocate("FadeInOutAnim");
            }
            else
            {
                m_ResLoader.ReleaseAllRes();
            }

            m_ResLoader.Add2Load("SwitchAnimShaderAnim", OnResLoadFinish);

            m_ResLoader.LoadAsync();
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
            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();
                }
            }
예제 #9
0
        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;
            }
        }
예제 #10
0
            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;
                }
            }
예제 #11
0
            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();
            }
예제 #12
0
        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;
            }
        }
예제 #13
0
        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();
            }
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
파일: SceneMgr.cs 프로젝트: moto2002/Hunter
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
파일: SceneMgr.cs 프로젝트: moto2002/Hunter
        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);
        }
예제 #19
0
            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();
                }
            }
예제 #20
0
        public void SetMaterial(string materialName)
        {
            ResLoader loader = ResLoader.Allocate("Temp");

            m_Render.material = loader.LoadSync(materialName) as Material;
        }
예제 #21
0
 public override void OnSingletonInit()
 {
     m_Loader = ResLoader.Allocate("ResHolder");
 }