internal UnityEngine.Object GetSharedResource(string res, EResType ResGroup, Action <UnityEngine.Object[]> func = null) { UnityEngine.Object obj = null; string abName = string.Empty; string resName = string.Empty; UnityEngine.Object retObj = null; if (string.IsNullOrEmpty(res)) { return(obj); } if (kLoadedPrefabs.ContainsKey(res)) { retObj = kLoadedPrefabs[res]; } else { string ResName = ResDefine.GetResourceType(ResGroup); string ResFolderName = ResName + "/"; string abPath = string.Empty; if (AppConst.PublishMode) { abName = string.Empty; abPath = Path.GetDirectoryName(res); if (string.IsNullOrEmpty(abPath)) { abName = ResFolderName + ResName + ResDefine.ExtName; } else { abPath = abPath.Replace("/", "_"); abName = ResFolderName + abPath + ResDefine.ExtName; } resName = Path.GetFileName(res); obj = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset <UnityEngine.Object>(abName, resName); } if (obj == null) { abPath = ResFolderName + res; obj = Resources.Load(abPath); } if (obj != null) { retObj = UnityEngine.Object.Instantiate(obj); kLoadedPrefabs.Add(res, retObj); AssetsLoaderManager assetLoader = AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader); if (assetLoader != null) { assetLoader.UnloadSyncAssetBundle(abName); } } else { UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName); UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName); } } return(retObj); }
static void HandleResourceBundle(EResType eResType) { EResType kResGroup = eResType; string path = ResDefine.GetResPath(kResGroup); if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) { return; } string ResName = ResDefine.GetResourceType(kResGroup); string ResFolderName = ResName + "/"; string Dirpath = ""; List <string> kExtList = new List <string>(); ResDefine.GetResTypeFileExtList(kResGroup, ref kExtList); string[] dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories); for (int j = 0; j < dirs.Length; j++) { string fPath = path; if (target == BuildTarget.iOS) { fPath = path + "/"; } string name = dirs[j].Replace(fPath, string.Empty).TrimStart(new char[] { '\\' }); name = name.Replace('\\', '_').Replace('/', '_'); name = name.ToLower() + ResDefine.ExtName; Dirpath = "Assets" + dirs[j].Replace(Application.dataPath, ""); AddBuildMap(ResFolderName + name, kExtList, Dirpath); } if (kResGroup != EResType.eResScene) //资源根目录打包 { string DirName = Path.GetFileName(path); AddBuildMap(ResFolderName + DirName + ResDefine.ExtName, kExtList, "Assets" + path.Replace(Application.dataPath, "")); } }
void loadSenenBundle(string name) { if (AppConst.PublishMode) { string bundleName = string.Empty; if (!name.Contains("loading") && !name.Contains("Login") && !name.Contains("SelectActorScence"))//排除loading login等几个场景 { string ResName = ResDefine.GetResourceType(EResType.eResScene); ResName += "/"; if (name.Contains("_")) { int i = name.LastIndexOf('_'); bundleName = name.Substring(0, i); } else { bundleName = name; } // bundle = AppFacade.Instance.GetManager<AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAssetBundle(ResName + bundleName); } } }
internal void NewObject(string res, EResType resType, float timeToRecycle, float timeToDestory, Action <UnityEngine.Object> func = null) { UnityEngine.Object obj = null; UnityEngine.Object retObj = null; string abName = string.Empty; string resName = string.Empty; if (kLoadedPrefabs.ContainsKey(res) && kLoadedPrefabs[res] != null) { obj = kLoadedPrefabs[res]; if (obj != null) { retObj = NewObject(res, obj, timeToRecycle, timeToDestory); if (func != null) { func(retObj); } } } else { string ResName = ResDefine.GetResourceType(resType); string ResFolderName = ResName + "/"; string abPath = string.Empty; if (AppConst.PublishMode && resType != EResType.eSceneLoadRes) { abName = string.Empty; abPath = Path.GetDirectoryName(res); if (string.IsNullOrEmpty(abPath)) { abName = ResFolderName + ResName + ResDefine.ExtName; } else { abPath = abPath.Replace("/", "_"); abName = ResFolderName + abPath + ResDefine.ExtName; } resName = Path.GetFileName(res); AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadAsset(abName, resName, delegate(UnityEngine.Object[] uObj) { if (uObj == null || uObj[0] == null) { UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName); UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName); } else { retObj = NewObject(res, uObj[0], timeToRecycle, timeToDestory); if (func != null) { func(retObj); } if (!kLoadedPrefabs.ContainsKey(res)) { kLoadedPrefabs.Add(res, retObj); } } } ); } else { if (obj == null) { abPath = ResFolderName + res; // obj = Resources.Load(abPath); AppFacade.Instance.GetManager <AssetsLoaderManager>(ManagerName.AssetsLoader).LoadRes(abPath, delegate(UnityEngine.Object uObj) { if (uObj == null) { UnityEngine.Debug.LogWarning("LoadAsset failed abpath:" + abName); UnityEngine.Debug.LogWarning("LoadAsset failed abName:" + resName); } retObj = NewObject(res, uObj, timeToRecycle, timeToDestory); if (func != null) { func(retObj); } if (!kLoadedPrefabs.ContainsKey(res)) { kLoadedPrefabs.Add(res, retObj); } }); } } } }