Ejemplo n.º 1
0
    public void PreloadSyncAndAsyncAssets(uint sceneId, ref PreloadResult preloadResult)
    {
        preloadSyncAndAsyncAssetsResult = preloadResult;
        IResBinData iResBinData = GameKernel.GetDataCenter().GetResBinData();

        //预加载场景资源
    }
Ejemplo n.º 2
0
    //场景资源预加载
    public void PreloadSceneAsset(string sceneName, ref PreloadResult preloadResult)
    {
        this.preloadSceneResult = preloadResult;

        //获取预加载的场景数据(现在木有,先不处理)
        List <string> preLoadGOList = null;

        if (preLoadGOList != null && preLoadGOList.Count > 0)
        {
            this.preloadSceneResult.TotalCount += preLoadGOList.Count;
        }

        if (this.preloadSceneResult.TotalCount > 0)
        {
            //资源加载并生成相应预设
            if (preLoadGOList != null)
            {
                IResourceMgr resMgr = GameKernel.Get <IResourceMgr>();
                foreach (string item in preLoadGOList)
                {
                    AssetBundleParams abp = new AssetBundleParams(item, typeof(GameObject));
                    resMgr.LoadNormalObjAsync(abp);
                }
            }
        }
        else
        {
            this.preloadSceneResult = null;
        }
    }
Ejemplo n.º 3
0
    //预加载普通资源
    public void PreloadAsyncAssets(uint sceneId, ref PreloadResult preloadResult)
    {
        //初始化系统
        preloadAsyncAssetsResult = preloadResult;

        IResBinData iResBinData = GameKernel.GetDataCenter().GetResBinData();

        //预加载及预热资源
        List <string> preLoadObjList          = null;
        List <string> PreloadAndPrehotObjList = null;

        if (preLoadObjList != null && preLoadObjList.Count > 0)
        {
            preloadAsyncAssetsResult.TotalCount += preLoadObjList.Count;
        }
        if (PreloadAndPrehotObjList != null && PreloadAndPrehotObjList.Count > 0)
        {
            preloadAsyncAssetsResult.TotalCount += PreloadAndPrehotObjList.Count;
        }

        if (preloadAsyncAssetsResult.TotalCount > 0)
        {
            IResourceMgr resMgr = GameKernel.Get <IResourceMgr>();

            /*if (preLoadObjList != null)
             * {
             *  foreach (string item in preLoadObjList)
             *  {
             *      AssetBundleParams abp =
             *          AssetBundleParamFactory.Create(item);
             *      resMgr.LoadSceneResidentMemoryObjAsync(abp, preloadObjCallBack);
             *  }
             * }
             * if (PreloadAndPrehotObjList != null)
             * {
             *  foreach (string item in PreloadAndPrehotObjList)
             *  {
             *      AssetBundleParams abp = AssetBundleParamFactory.Create(item);
             *      abp.IsPreloadMainAsset = true;
             *
             *      ResLogger.Log("Prelaod " + abp.path + " " + abp.type);
             *
             *      resMgr.LoadSceneResidentMemoryObjAsync(abp, preloadObjCallBack);
             *  }
             * }
             *
             * for (int i = 0; i < diffPreloads.Count; i++)
             * {
             *  if (!string.IsNullOrEmpty(diffPreloads[i]))
             *  {
             *      AssetBundleParams abp = AssetBundleParamFactory.Create(diffPreloads[i]);
             *      abp.IsPreloadMainAsset = true;
             *
             *      ResLogger.Log("Diff Prelaod " + abp.path + " " + abp.type);
             *
             *      resMgr.LoadResidentMemoryObjAsync(abp, preloadObjCallBack);
             *  }
             * }*/
        }
        else
        {
            preloadAsyncAssetsResult = null;
        }
    }
Ejemplo n.º 4
0
        void initAsset()
        {
            preloadResult = null;
            preloadResult = new PreloadResult();

            GameKernel.CreateForInitData();
            IResourceMgr resourceMgr = GameKernel.Get <IResourceMgr>();
            ResBinData   iResBinData = NewResBinDataForPreLoad();

            //预加载资源,不需要提前获取mainAsset
            List <string> residentGoList        = iResBinData.GetImmortalAssetList(1);
            List <string> residentACList        = iResBinData.GetImmortalAssetList(3);
            List <string> residentTexture2DList = iResBinData.GetImmortalAssetList(5);
            List <string> residentAudioClipList = iResBinData.GetImmortalAssetList(7);
            List <string> residentAnimClipList  = iResBinData.GetImmortalAssetList(9);

            //预加载资源,需要提前获取mainAsset
            List <string> residentPreloadGoList        = iResBinData.GetImmortalAssetList(2);
            List <string> residentPreloadACList        = iResBinData.GetImmortalAssetList(4);
            List <string> residentPreloadTexture2DList = iResBinData.GetImmortalAssetList(6);
            List <string> residentPreloadAudioClipList = iResBinData.GetImmortalAssetList(8);
            List <string> residentPreloadAnimClipList  = iResBinData.GetImmortalAssetList(10);


            if (residentGoList != null && residentGoList.Count > 0)
            {
                this.preloadResult.TotalCount += residentGoList.Count;
            }
            if (residentPreloadGoList != null && residentPreloadGoList.Count > 0)
            {
                this.preloadResult.TotalCount += residentPreloadGoList.Count;
            }
            if (residentACList != null && residentACList.Count > 0)
            {
                this.preloadResult.TotalCount += residentACList.Count;
            }
            if (residentPreloadACList != null && residentPreloadACList.Count > 0)
            {
                this.preloadResult.TotalCount += residentPreloadACList.Count;
            }
            if (residentTexture2DList != null && residentTexture2DList.Count > 0)
            {
                this.preloadResult.TotalCount += residentTexture2DList.Count;
            }
            if (residentPreloadTexture2DList != null && residentPreloadTexture2DList.Count > 0)
            {
                this.preloadResult.TotalCount += residentPreloadTexture2DList.Count;
            }
            if (residentAudioClipList != null && residentAudioClipList.Count > 0)
            {
                this.preloadResult.TotalCount += residentAudioClipList.Count;
            }
            if (residentPreloadAudioClipList != null && residentPreloadAudioClipList.Count > 0)
            {
                this.preloadResult.TotalCount += residentPreloadAudioClipList.Count;
            }
            if (residentAnimClipList != null && residentAnimClipList.Count > 0)
            {
                this.preloadResult.TotalCount += residentAnimClipList.Count;
            }
            if (residentPreloadAnimClipList != null && residentPreloadAnimClipList.Count > 0)
            {
                this.preloadResult.TotalCount += residentPreloadAnimClipList.Count;
            }

            if (residentGoList != null)
            {
                for (int i = 0; i < residentGoList.Count; i++)
                {
                    abp = new AssetBundleParams(residentGoList[i], typeof(GameObject));
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentPreloadGoList != null)
            {
                for (int i = 0; i < residentPreloadGoList.Count; i++)
                {
                    abp = new AssetBundleParams(residentPreloadGoList[i], typeof(GameObject));
                    abp.IsPreloadMainAsset = true;
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentACList != null)
            {
                for (int i = 0; i < residentACList.Count; i++)
                {
                    abp = new AssetBundleParams(residentACList[i], typeof(RuntimeAnimatorController));
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentPreloadACList != null)
            {
                for (int i = 0; i < residentPreloadACList.Count; i++)
                {
                    abp = new AssetBundleParams(residentPreloadACList[i], typeof(RuntimeAnimatorController));
                    abp.IsPreloadMainAsset = true;
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentTexture2DList != null)
            {
                for (int i = 0; i < residentTexture2DList.Count; i++)
                {
                    abp = new AssetBundleParams(residentTexture2DList[i], typeof(Texture2D));
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentPreloadTexture2DList != null)
            {
                for (int i = 0; i < residentPreloadTexture2DList.Count; i++)
                {
                    abp = new AssetBundleParams(residentPreloadTexture2DList[i], typeof(Texture2D));
                    abp.IsPreloadMainAsset = true;
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentAudioClipList != null)
            {
                for (int i = 0; i < residentAudioClipList.Count; i++)
                {
                    abp = new AssetBundleParams(residentAudioClipList[i], typeof(AudioClip));
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentPreloadAudioClipList != null)
            {
                for (int i = 0; i < residentPreloadAudioClipList.Count; i++)
                {
                    abp = new AssetBundleParams(residentPreloadAudioClipList[i], typeof(AudioClip));
                    abp.IsPreloadMainAsset = true;
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentAnimClipList != null)
            {
                for (int i = 0; i < residentAnimClipList.Count; i++)
                {
                    abp = new AssetBundleParams(residentAnimClipList[i], typeof(AnimationClip));
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }
            if (residentPreloadAnimClipList != null)
            {
                for (int i = 0; i < residentPreloadAnimClipList.Count; i++)
                {
                    abp = new AssetBundleParams(residentPreloadAnimClipList[i], typeof(AnimationClip));
                    abp.IsPreloadMainAsset = true;
                    resourceMgr.LoadResidentMemoryObjAsync(abp);
                }
            }

            ReleaseNewResBinData();
        }
Ejemplo n.º 5
0
        private IEnumerator StartLoadingCor()
        {
            XYHY.IResourceMgr resMgr = Framework.GameKernel.GetResourceMgr();
            int displayProgress = 0;
            int toProgress = 0;
            int sceneLoadPercent = 20;
            int processSpeed = 4;
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreLoad);
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreloadScene);

            int sceneAssetLoadPercent = 30;
            PreloadResult preloadSceneResult = new PreloadResult();
            PreloadManager.Instance.PreloadSceneAsset(SceneMgr.Instance.CurrentScene, ref preloadSceneResult);
            if (preloadSceneResult != null && preloadSceneResult.TotalCount > 0)
            {
                while (true)
                {
                    toProgress = (int)(preloadSceneResult.PreloadPercent * sceneLoadPercent);
                    while (displayProgress < toProgress)
                    {
                        displayProgress += processSpeed;
                        setLoadingPercentage(displayProgress);
                        yield return new WaitForEndOfFrame();
                    }
                    if (preloadSceneResult.PreloadPercent >= 1 && toProgress == sceneLoadPercent)
                    {
                        break;
                    }
                    yield return null;
                }
            }
            preloadSceneResult = null;

            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreloadScene,false);

            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreUnloadScn);
            //卸载场景物件
            resMgr.UnloadLastSceneAsset(SceneMgr.Instance.CurrentScene);
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreUnloadScn, false);

            //预加载异步资源
            PreloadResult preloadAsyncAssetResult = new PreloadResult();
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreloadAsset);

            PreloadManager.Instance.PreloadAsyncAssets(SceneMgr.Instance.SceneId, ref preloadAsyncAssetResult);
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreloadAsset,false);

            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreLoadAssetAsy);

            if (preloadAsyncAssetResult != null && preloadAsyncAssetResult.TotalCount > 0)
            {
                while (true)
                {
                    toProgress = sceneLoadPercent + (int)(preloadAsyncAssetResult.PreloadPercent * sceneAssetLoadPercent);

                    while (displayProgress < toProgress)
                    {
                        displayProgress += processSpeed;
                        setLoadingPercentage(displayProgress);
                        yield return new WaitForEndOfFrame();
                    }
                    if (preloadAsyncAssetResult.PreloadPercent >= 1 && toProgress == (sceneLoadPercent + sceneAssetLoadPercent))
                    {
                        preloadAsyncAssetResult = null;
                        break;
                    }
                    yield return null;
                }
            }
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreLoadAssetAsy,false);

            //预加载同时有同步和异步的资源
            PreloadResult preloadSyncAndAsyncAssetsResult = new PreloadResult();
            PreloadManager.Instance.PreloadSyncAndAsyncAssets(SceneMgr.Instance.SceneId, ref preloadSyncAndAsyncAssetsResult);

            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreLoadSycAndAsy);
            if (preloadSyncAndAsyncAssetsResult != null && preloadSyncAndAsyncAssetsResult.TotalCount > 0)
            {
                while (true)
                {
                    toProgress = sceneLoadPercent + sceneAssetLoadPercent + (int)(preloadSyncAndAsyncAssetsResult.PreloadPercent * (100 - sceneLoadPercent - sceneAssetLoadPercent));

                    while (displayProgress < toProgress)
                    {
                        displayProgress += processSpeed;
                        setLoadingPercentage(displayProgress);
                        yield return new WaitForEndOfFrame();
                    }
                    if (preloadSyncAndAsyncAssetsResult.PreloadPercent >= 1 && toProgress == 100)
                    {
                        preloadSyncAndAsyncAssetsResult = null;
                        break;
                    }
                    yield return null;
                }
            }
            TimeCostLog.Instance.WriteLog(SceneMgr.Instance.SceneId, eTimeCost.ePreLoadSycAndAsy,false);
            
            toProgress = 100;
            while (displayProgress < toProgress)
            {
                displayProgress += processSpeed;
                setLoadingPercentage(displayProgress);
                yield return null;
            }
        }