Exemple #1
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;
        }
    }
    public static GameObject AddChildToGameObj(GameObject kGoParent, string strPrefabPath)
    {
        GameObject obj = null;

        if (string.IsNullOrEmpty(strPrefabPath) == false)
        {
            Object resObj = GameKernel.Get <IDataCenter>().GetDataType <IVLResLoad>().Load(strPrefabPath);
            if (resObj != null)
            {
                obj = Object.Instantiate(resObj) as GameObject;

                if (kGoParent != null)
                {
                    obj.transform.parent        = kGoParent.transform;
                    obj.transform.localPosition = new Vector3(0f, 0f, 0f);
                    obj.transform.localRotation = Quaternion.identity;
                    obj.transform.localScale    = Vector3.one;
                }

                UIAnchor[] m_Anchors = obj.GetComponentsInChildren <UIAnchor>();
                obj.SetActive(true);

                foreach (UIAnchor a in m_Anchors)
                {
                    a.uiCamera = kGoParent.GetComponent <Camera>();
                }
            }
        }

        return(obj);
    }
    static void CreateInstance()
    {
        ReleaseObject();

        IResourceMgr resourceMgr = GameKernel.Get <IResourceMgr>();
        Object       resObj      = resourceMgr.LoadNormalObjSync(new AssetBundleParams(mResPath, typeof(GameObject)));

        if (resObj != null)
        {
            GameObject obj = Object.Instantiate(resObj) as GameObject;

            if (Parent != null)
            {
                obj.transform.parent        = Parent.transform;
                obj.transform.localPosition = new Vector3(0f, 0f, 0f);
                obj.transform.localRotation = Quaternion.identity;
                obj.transform.localScale    = Vector3.one;
                RefreshPanelDepth(obj);
            }

            UIAnchor[] m_Anchors = obj.GetComponentsInChildren <UIAnchor>();
            obj.SetActive(false);

            foreach (UIAnchor a in m_Anchors)
            {
                a.uiCamera = UICamera;
                a.gameObject.SetActive(true);
            }

            T component = obj.GetComponent <T>();
            mInstance.Target             = component;
            mInstance.Target.ReleaseType = mCurReleaseType;
            IUIComponentContainer container = Container;
            if (container != null)
            {
                container.SetUIComponent <T>(component);
            }
        }
    }
Exemple #4
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;
        }
    }
        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();
        }