public static GameObject InstantiateObjectSync(ObjLoadInfo objLoadInfo) { //从对象池拿取对象 ResObject resObject = ResManager.Instance.GetObjectFromPool(objLoadInfo.mCRC); //对象池没有 if (resObject == null) { //ResManager提供加载方法 resObject = ResourceLoader.Instance.LoadResSyncForObj(objLoadInfo); if (resObject.mObj != null) { if (objLoadInfo.ObjParentTrans == null) { resObject.mCloneObj = GameObject.Instantiate(resObject.mObj) as GameObject; } else { resObject.mCloneObj = GameObject.Instantiate(resObject.mObj, objLoadInfo.ObjParentTrans) as GameObject; } ResManager.Instance.CacheResObj(resObject); } } else { resObject.mCloneObj.transform.SetParent(objLoadInfo.ObjParentTrans); ResManager.Instance.CacheResObj(resObject); } return(resObject.mCloneObj); }
public GameObject PreLoadObj(ObjLoadInfo objLoadInfo) { objLoadInfo.ObjParentTrans = recycleTrs; GameObject obj = ObjectLoader.InstantiateObjectSync(objLoadInfo); ReleaseObj(obj, -1, objLoadInfo.mClear, recycleTrs); return(obj); }
public static ResObject Allocate(ObjLoadInfo objLoadInfo) { ResObject resObject = SafeObjectPool <ResObject> .Instance.Allocate(); resObject.mCrc = objLoadInfo.mCRC; resObject.mClear = objLoadInfo.mClear; resObject.mResPath = objLoadInfo.mResPath; resObject.IsRecyclePool = false; return(resObject); }
public static ResLoadInfo Allocate(ObjLoadInfo objLoadInfo) { ResLoadInfo resLoadInfo = SafeObjectPool <ResLoadInfo> .Instance.Allocate(); resLoadInfo.mResPath = objLoadInfo.mResPath; resLoadInfo.mResFromType = objLoadInfo.mResFromType; resLoadInfo.mIsSprite = false; resLoadInfo.mListener = objLoadInfo.loadResCall; resLoadInfo.mCRC = Crc32.GetCrc32(objLoadInfo.mResPath); resLoadInfo.DestroyCache = objLoadInfo.mClear; return(resLoadInfo); }
/// <summary> /// 预加载 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="resType"></param> /// <param name="assetPath"></param> /// <param name="count"></param> /// <param name="clear"></param> public void PreLoadObj <T>(ResFromType resType, string assetPath, int count = 1, bool clear = false) where T : Object { if (CheckNoCanLoad()) { AFLogger.e("此Loader已经被释放,请注意!"); return; } for (int i = 0; i < count; i++) { ObjLoadInfo objLoadInfo = ObjLoadInfo.Allocate(resType, assetPath, null, false); ResManager.Instance.PreLoadObj(objLoadInfo); objLoadInfo.Recycle2Cache(); } }
public static ObjLoadInfo Allocate(ResFromType resType, string assetPath, Transform ObjParentTrans, bool mclear = false, LoadResPriority loadResPriority = LoadResPriority.RES_NUM, Action <bool, ResInfo> loadResCall = null, Action <bool, ResObject> loadObjCall = null) { ObjLoadInfo objLoadInfo = SafeObjectPool <ObjLoadInfo> .Instance.Allocate(); objLoadInfo.mCRC = Crc32.GetCrc32(assetPath); objLoadInfo.mResFromType = resType; objLoadInfo.ObjParentTrans = ObjParentTrans; objLoadInfo.mClear = mclear; objLoadInfo.mResPath = assetPath; objLoadInfo.loadResPriority = loadResPriority; objLoadInfo.loadResCall = loadResCall; objLoadInfo.loadObjCall = loadObjCall; return(objLoadInfo); }
/// <summary> /// 同步加载Prefab,返回其实例化的GameObject /// </summary> /// <param name="resType"></param> /// <param name="assetPath"></param> /// <param name="parTrans"></param> /// <param name="bClear"></param> /// <returns></returns> public GameObject InstantiateObjectSync(ResFromType resType, string assetPath, Transform parTrans = null, bool bClear = true) { if (CheckNoCanLoad()) { AFLogger.e("此Loader已经被释放,请注意!"); return(null); } ObjLoadInfo objLoadInfo = ObjLoadInfo.Allocate(resType, assetPath, parTrans, bClear); GameObject objAsset = ResManager.Instance.InstantiateObjectSync(objLoadInfo); if (objAsset != null) { //加载完成后添加到加载资源列表中 mObjList.AddValue(objAsset.GetInstanceID()); } objLoadInfo.Recycle2Cache(); return(objAsset); }
/// <summary> /// 异步加载Object /// </summary> /// <param name="objLoadInfo"></param> public static void InstantiateObjectASync(ObjLoadInfo objLoadInfo) { //从对象池拿取对象 ResObject resObject = ResManager.Instance.GetObjectFromPool(objLoadInfo.mCRC); if (resObject == null) { //ResourceLoader加载资源 ResourceLoader.Instance.LoadResAsyncForObj(objLoadInfo); } else { if (objLoadInfo.ObjParentTrans != null) { resObject.mCloneObj.transform.SetParent(objLoadInfo.ObjParentTrans); } objLoadInfo.loadObjCall(true, resObject); objLoadInfo.Recycle2Cache(); } }
public void LoadResAsyncForObj(ObjLoadInfo objLoadInfo) { ResInfo resInfo = ResManager.Instance.GetRes(objLoadInfo.mCRC); if (resInfo == null) { ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(objLoadInfo); //资源没有加载 LoadAsync(resLoadInfo); resLoadInfo.Recycle2Cache(); } else if (resInfo.State != ResState.Ready) { //资源正在加载,是其他loader的异步加载 resInfo.RegisterListen(objLoadInfo.loadResCall); } else { //资源已经加载完成,开始回调 objLoadInfo.loadResCall(true, resInfo); } }
/// <summary> /// 异步加载Prefab /// </summary> /// <param name="resType"></param> /// <param name="assetPath"></param> /// <param name="parTrans"></param> /// <param name="loadObjFinish"></param> /// <param name="loadResPriority"></param> /// <param name="bClear"></param> public void InstantiateObjectASync(ResFromType resType, string assetPath, System.Action <bool, ResObject> loadObjFinish, Transform parTrans = null, LoadResPriority loadResPriority = LoadResPriority.RES_NUM, bool bClear = true) { if (CheckNoCanLoad()) { AFLogger.e("此Loader已经被释放,请注意!"); return; } ObjLoadInfo objLoadInfo = ObjLoadInfo.Allocate(resType, assetPath, parTrans, bClear, loadResPriority, AsyncObjCallBack, loadObjFinish); if (mAsyncLoadingObjDic.ContainsKey(assetPath)) { mAsyncLoadingObjDic[assetPath].Add(objLoadInfo); } else { AsyncCount += 1; mAsyncLoadingObjDic.AddValue(assetPath, objLoadInfo); ResManager.Instance.InstantiateObjectASync(objLoadInfo); } }
public ResObject LoadResSyncForObj(ObjLoadInfo objLoadInfo) { ResObject resObject = ResObject.Allocate(objLoadInfo); ResInfo resInfo = ResManager.Instance.GetRes(objLoadInfo.mCRC); //之前就未加载 if (resInfo == null) { ResLoadInfo resLoadInfo = ResLoadInfo.Allocate(objLoadInfo); resObject.mObj = LoadSync(resLoadInfo); resLoadInfo.Recycle2Cache(); } //之前就加载完成 else if (resInfo.State == ResState.Ready) { resInfo.Retain(); resObject.mObj = resInfo.ResObject; } else { AFLogger.e("同步遇到异步正在或者等待加载的资源 : " + resInfo.ResPath + ",请检查调用代码!"); } return(resObject); }
public void InstantiateObjectASync(ObjLoadInfo objLoadInfo) { ObjectLoader.InstantiateObjectASync(objLoadInfo); }
public GameObject InstantiateObjectSync(ObjLoadInfo objLoadInfo) { return(ObjectLoader.InstantiateObjectSync(objLoadInfo)); }