private static void CreateTextureConfigs(List <string> files) { string texDir = "res_models"; ResConfig resConfig = null; var databaseFile = "database_models_texture.txt"; resConfig = new ResConfig() { items = new List <ResItem>() }; foreach (var file in files) { var refPath = Path.GetFullPath(file).Replace(Application.dataPath + "/", "").ToLower(); var item = CreateConfigItem(Path.GetFullPath(file).ToLower(), Path.GetFileName(file), refPath); string destFile = Path.Combine(texDir, refPath); if (!Directory.Exists(Path.GetDirectoryName(destFile))) { Directory.CreateDirectory(Path.GetDirectoryName(destFile)); } File.Copy(Path.GetFullPath(file), destFile, true); if (resConfig.items.FirstOrDefault(s => s.name == item.name) != null) { EditorUtility.DisplayDialog("生成出错", "不可以存在相同的名称" + item.name, "确定"); } resConfig.items.Add(item); } File.WriteAllText(databaseFile, JsonUtility.ToJson(resConfig, true)); EditorUtility.DisplayDialog("生成所有Texture配置", "完成", "确定"); }
/// <summary> /// 获取已加载的资源 /// </summary> public GameObject GetPrefab(ResType type, string abName) { GameObject obj = null; string abPath = ResConfig.GetABPath(type, abName); AssetBundleData assetBundle = GetAssetBundle(abPath); if (assetBundle == null) { LoadAssetBundle(abPath); LogUtil.LogError("资源获取失败------abName:" + abPath); return(null); } else { dicAssetBundle.TryGetValue(abPath, out assetBundle); if (assetBundle != null) { obj = assetBundle.ab.LoadAsset(abName, typeof(GameObject)) as GameObject; } } if (obj == null) { LogUtil.LogError("资源获取失败------abName:" + abName); return(null); } return(UnityEngine.Object.Instantiate <GameObject>(obj)); }
public static void CopyPatchResources(ResConfig config) { var path = EditorUtility.SaveFolderPanel("选择补丁路径:", GetPatchResourcesRoot(), ""); if (string.IsNullOrEmpty(path) || !path.Contains("patch_")) { return; } var pathName = Path.GetFileNameWithoutExtension(path); var isMatch = Regex.IsMatch(pathName, @"^patch_\d+_" + config.Version); if (!isMatch) { var goOn = EditorUtility.DisplayDialog("版本号不符合", "当前AssetBundleBuilder的版本号和上传资源版本号不符,确认无误可以继续!", "确认", "取消"); if (!goOn) { throw new Exception("主动取消上传补丁资源!"); } } foreach (var folder in GetRemotePlatformFolderList()) { var remotePath = GetGameResourcesFullPath(RemoteUpdateResPath + "/" + folder); FileHelper.CreateDirectory(Path.GetDirectoryName(remotePath)); FileHelper.DeleteDirectory(remotePath, true); FileUtil.CopyFileOrDirectory(path, remotePath); } }
// config as resource, dont parse now void parseRes(ZipArchiveEntry entry, Type type) { ResConfig cfg = Activator.CreateInstance(type) as ResConfig; cfg.key = entry.FullName; ConfigManager.Instance.AddRes(cfg); }
private static void GenerateInfoFile(int categoryId, string dir) { DirectoryInfo dirInfo = new DirectoryInfo(Application.streamingAssetsPath + "/" + dir + "/category_" + categoryId); var fileInfos = dirInfo.GetFiles("*", SearchOption.AllDirectories).Where(s => !s.Name.ToLower().EndsWith(".meta") && !s.Name.EndsWith(".DS_Store")); ResConfig resConfig = new ResConfig(); int counter = 0; foreach (FileInfo fileInfo in fileInfos) { ResConfigItem configItem = new ResConfigItem(); configItem.index = counter++; configItem.name = Path.GetFullPath(fileInfo.FullName).Replace(Application.streamingAssetsPath + "/" + dir + "/", ""); configItem.size = fileInfo.Length.ToString(); byte[] platformFileBytes = GetFileBytes(Path.GetFullPath(fileInfo.FullName)); configItem.md5 = GetMD5(platformFileBytes); resConfig.Items.Add(configItem); } string jsonContent = JsonUtility.ToJson(resConfig, true); File.WriteAllText(Application.streamingAssetsPath + "/" + dir + "/category_" + categoryId + "/config.json", jsonContent); }
public void AddRes(ResConfig _config) { var key = _config.GetType(); if (!resConfigDatas.ContainsKey(key)) { var cfgs = new Dictionary <string, ResConfig>(); cfgs.Add(_config.key, _config); resConfigDatas.Add(key, cfgs); } else { var cfgs = resConfigDatas[key]; if (cfgs.ContainsKey(_config.key)) { Debug.LogWarning($"replace config : {key} {_config.key}"); cfgs[_config.key] = _config; } else { //Debug.Log("add config : " + key); cfgs.Add(_config.key, _config); } } }
/// <summary> /// 获取对应category的config 文件。每次都要先获取该文件 /// </summary> /// <param name="categoryId">Category identifier.</param> private void GetResConfig(int categoryId) { UpdateState(DownloadState.ResConfig); mUpdateResConfig = null; mLocalResConfig = null; string url = GetResConfigUrl(false, categoryId); WWWLoadRes(url, www => { mUpdateResConfig = JsonUtility.FromJson <ResConfig>(www.text); //local resconfig.json url = GetResConfigUrl(true, categoryId); if (!url.Contains("://")) { mLocalResConfig = JsonUtility.FromJson <ResConfig>(File.ReadAllText(url)); UpdateState(DownloadState.ResConfigFinish); } else { WWWLoadRes(url, www2 => { mLocalResConfig = JsonUtility.FromJson <ResConfig>(www.text); UpdateState(DownloadState.ResConfigFinish); }); } }); }
public static void UploadVersionResourcesPatch(ResConfig config) { ReloadConfig(); CopyPatchResources(config); CopyResConfig(config); Debug.Log("UploadVersionResourcesPatch Finished"); }
public void UnLoadAssetBundle(ResType type, string abName) { //这里可以过滤一下公共资源 //卸载资源 string abPath = ResConfig.GetABPath(type, abName); UnloadAssetBundleInternal(abPath); UnloadDependencies(abPath); }
private ResConfig checkAutoDestory() { ResConfig config = mGameObject.GetComponent <ResConfig>(); if (config != null && config.AutoDestory) { config.OnDestroyHandler += Destroy; } return(config); }
public static void CopyResConfig(ResConfig config) { foreach (var folder in GetRemotePlatformFolderList()) { var remotePath = GetStaticResConfigFullPath(RemoteUpdateVerPath + "/" + folder, config); FileHelper.CreateDirectory(Path.GetDirectoryName(remotePath)); FileUtil.DeleteFileOrDirectory(remotePath); var jzPath = GetResConfigRoot(config); FileUtil.CopyFileOrDirectory(jzPath, remotePath); } }
private void Setup() { Instance = this; _foldoutDic = new Dictionary <ResGroup, bool>(); var resGroups = Enum.GetValues(typeof(ResGroup)); foreach (ResGroup flag in resGroups) { _foldoutDic.Add(flag, EditorPrefs.GetBool("ABFoldOut_" + flag, false)); } _bundleNameGroups = new Dictionary <ResGroup, List <string> >(); var resGroupEnums = Enum.GetValues(typeof(ResGroup)); foreach (ResGroup resGroup in resGroupEnums) { _bundleNameGroups.Add(resGroup, new List <string>()); } string configPath = GetPoolConfigPath(); if (FileHelper.IsExist(configPath)) { _poolConfig = FileHelper.ReadJsonFile <PrefabPoolConfig>(GetPoolConfigPath()); } if (_poolConfig == null) { _poolConfig = new PrefabPoolConfig(); } var allBundleNames = AssetDatabase.GetAllAssetBundleNames(); //筛选出符合的BundleName加入列表中 foreach (string bundleName in allBundleNames) { var resGroup = ResConfig.GetResGroupFromBundleName(bundleName); if (resGroup == ResGroup.Audio || resGroup == ResGroup.Effect || resGroup == ResGroup.UIPrefab) { _bundleNameGroups[resGroup].Add(bundleName); } else if (resGroup == ResGroup.Model) { if (!bundleName.StartsWith("anim_") && !bundleName.EndsWith("_mat")) { _bundleNameGroups[resGroup].Add(bundleName); } } } _bundleNameGroups[ResGroup.None].Add("Default"); }
/// <summary> /// 加载图片 /// </summary> public void LoadConfig(ResType type, string abName, string assetName = "", Action <AssetBundleData> loadComplete = null) { AssetBundleLoadOperation operation = null; string abPath = ResConfig.GetABPath(type, abName); AssetBundleData loadedAssetBundle = GetAssetBundle(abPath); if (loadedAssetBundle == null) { LoadAssetBundle(abPath); } operation = new AssetBundleLoadAssetOperation(abPath, assetName, typeof(TextAsset), loadComplete); listProgressOperations.Add(operation); }
public void UnloadRes(ResConfig res) { if (!res.isinit) { return; } var type = res.GetType(); var key = res.key; if (resConfigDatas.ContainsKey(type)) { var cfgs = resConfigDatas[type]; if (cfgs.ContainsKey(key)) { cfgs.Remove(key); } } }
private void setAutoDestory() { if (_destoryTime <= 0) { return; } if (mGameObject == null) { return; } ResConfig config = mGameObject.GetComponent <ResConfig>(); if (config == null) { config = mGameObject.AddComponent <ResConfig>(); } config.AutoDestory = true; config.LifeTime = _destoryTime; config.enabled = true; checkAutoDestory(); }
internal bool CanRelease(bool onLevel) { if (!Asset) { return(true); } if (!gotConfig) { if (Asset is GameObject) { if ((Asset as GameObject).activeSelf) { config = (Asset as GameObject).GetComponent <ResConfig>(); } else { ResConfig[] configs = (Asset as GameObject).GetComponentsInChildren <ResConfig>(true); if (configs.Length > 0) { config = configs[0]; } } } gotConfig = true; } if (Asset is Font) { return(false); } /* if (onLevel) * { * return (config == null || config.ReleaseOnLevelLoaded); * } * else * {*/ return(HasNoReference); //} }
public static string GetStaticResConfigFullPath(string path, ResConfig reconfig) { return(path + "/staticRes/" + GameResPath.RESCONFIG_ROOT + "/" + reconfig.ToRemoteName()); }
private static void ChangeFormat(List <string> fbxFiles) { ResConfig resConfig = null; var databaseFile = "database_models_gltf.txt"; if (!File.Exists(databaseFile)) { resConfig = new ResConfig() { items = new List <ResItem>() }; } else { var content = File.ReadAllText(databaseFile); resConfig = JsonUtility.FromJson <ResConfig>(content); } bool hasError = false; StringBuilder errorMsg = new StringBuilder(); string destDir = "res_models"; int totalCount = fbxFiles.Count; int counter = 0; foreach (var fbxFile in fbxFiles) { string input = Path.GetFullPath(fbxFile); string refPath = Path.GetFullPath(fbxFile).Replace(dataPath + Path.DirectorySeparatorChar, "").ToLower(); string outputDir = Path.Combine(destDir, refPath); outputDir = Path.GetDirectoryName(outputDir) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(fbxFile); outputDir = outputDir.ToLower(); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } var glftFileName = Path.GetFileNameWithoutExtension(fbxFile) + ".gltf"; var gltfFilePath = Path.Combine(Environment.CurrentDirectory, Path.Combine(outputDir, glftFileName).ToLower()); string arguments = input + " -o " + gltfFilePath; RunCommand(arguments); EditorUtility.DisplayProgressBar(title, "请稍后", counter / totalCount * 1.0f); counter++; var prefix = outputDir.Replace("res_models/", string.Empty); var bufferFilePath = prefix + "/buffer.bin"; var gltfRefPath = prefix + "/" + glftFileName; var realPath = outputDir + "/buffer.bin"; var gltfRealPath = outputDir + "/" + glftFileName; var gltfItems = resConfig.items.Where(s => s.path == gltfRefPath); var bufferItems = resConfig.items.Where(s => s.path == bufferFilePath); for (int i = 0; i < gltfItems.Count(); i++) { resConfig.items.Remove(gltfItems.ElementAt(i)); } for (int i = 0; i < bufferItems.Count(); i++) { resConfig.items.Remove(bufferItems.ElementAt(i)); } var gltfItem = CreateConfigItem(gltfRealPath, glftFileName, gltfRefPath); var bufferItem = CreateConfigItem(realPath, Path.GetFileNameWithoutExtension(fbxFile) + "/buffer.bin", bufferFilePath); resConfig.items.Add(gltfItem); resConfig.items.Add(bufferItem); } EditorUtility.ClearProgressBar(); if (hasError) { Debug.LogError(errorMsg.ToString()); } File.WriteAllText(databaseFile, JsonUtility.ToJson(resConfig, true)); EditorUtility.DisplayDialog(title, hasError?errorMsg.ToString():"转换完成", "确定"); }
protected override void RegResource() { base.RegResource(); ResConfig.AddResCfg(RES_ID.RES_REG); }
/// <summary> /// 收集UI上的图、字体、动画等资源信息,生成新的Prefab /// </summary> /// <param name="file"></param> /// <param name="genPath"></param> private void GenerateUIPrefab(string file, string genPath) { string hash, md5File; if (!ShouldGenerateAsset(file, genPath, out hash, out md5File)) { return; } Object asset = AssetDatabase.LoadMainAssetAtPath(file); if (!asset) { Debug.LogError("Cannot load asset:" + file); } GameObject obj = Object.Instantiate(asset) as GameObject; obj.SetActive(false); UnityEngine.UI.Image[] textures = obj.GetComponentsInChildren <UnityEngine.UI.Image>(true); Dictionary <UnityEngine.UI.Image, string> replaceNeeded = new Dictionary <UnityEngine.UI.Image, string>(); foreach (var i in textures) { if (i is GOGUI.AnimatedImage) { GOGUI.AnimatedImage anim = (GOGUI.AnimatedImage)i; if (anim.Sprites != null && anim.Sprites.Length > 0) { GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.AnimatedImageNames = new string[anim.Sprites.Length]; li.AnimatedImage = anim; for (int j = 0; j < anim.Sprites.Length; j++) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(anim.Sprites[j])); if (path == "unity_builtin_extra") { continue; } li.AnimatedImageNames[j] = path; anim.Sprites[j] = null; } anim.sprite = null; } } else { if (i.sprite) { string ap = AssetDatabase.GetAssetPath(i.sprite); TextureImporter ti = AssetImporter.GetAtPath(ap) as TextureImporter; bool isBigTextureSprite = false; if (ti != null && string.IsNullOrEmpty(ti.spritePackingTag)) { isBigTextureSprite = true; } string path = isBigTextureSprite ? System.IO.Path.GetFileNameWithoutExtension(ap) : System.IO.Path.GetFileName(ap); if (path == "unity_builtin_extra") { continue; } replaceNeeded[i] = path; } else if (i.sprite != null) { i.sprite = null; } } } SpriteRenderer[] srs = obj.GetComponentsInChildren <SpriteRenderer>(true); foreach (var i in srs) { if (i.sprite) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.sprite)); if (path == "unity_builtin_extra") { continue; } GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.SpriteName = path; li.SpriteRenderer = i; i.sprite = null; } else if (i.sprite != null) { i.sprite = null; } } UnityEngine.UI.Button[] btns = obj.GetComponentsInChildren <UnityEngine.UI.Button>(true); foreach (var i in btns) { if (i.spriteState.pressedSprite) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.spriteState.pressedSprite)); if (path == "unity_builtin_extra") { continue; } GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.ButtonPressedName = path; li.Button = i; var state = i.spriteState; state.pressedSprite = null; state.disabledSprite = null; i.spriteState = state; } } UnityEngine.UI.RawImage[] imgs = obj.GetComponentsInChildren <UnityEngine.UI.RawImage>(true); foreach (var i in imgs) { if (i.texture) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.texture)); if (path == "unity_builtin_extra") { continue; } GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.RawImageName = path; li.RawImage = i; i.texture = null; } } GOGUI.AdvancedText[] texts = obj.GetComponentsInChildren <GOGUI.AdvancedText>(true); foreach (var i in texts) { if (i.ImageFont) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.ImageFont)); if (path == "unity_builtin_extra") { continue; } GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.ImageFontName = path; li.AdvancedText = i; i.ImageFont = null; } if (i.font) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.font)); if (path == "unity default resources") { continue; } GameObject go = i.gameObject; GOGUI.LazyImageLoader li = GetLazyLoader(go); li.FontName = path; li.Text = i; i.font = null; } } Dictionary <UnityEngine.UI.Text, string> txtReplaceNeeded = new Dictionary <UnityEngine.UI.Text, string>(); UnityEngine.UI.Text[] texts2 = obj.GetComponentsInChildren <UnityEngine.UI.Text>(true); foreach (var i in texts2) { if (i is GOGUI.AdvancedText) { continue; } if (i.font) { string path = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(i.font)); if (path == "unity default resources") { continue; } txtReplaceNeeded[i] = path; //MakeLazyLoadText(i, path); } i.raycastTarget = false; } //Fix LazyLoadImage UnityEngine.UI.Toggle[] tgs = obj.GetComponentsInChildren <UnityEngine.UI.Toggle>(true); foreach (var i in tgs) { if (!i) { continue; } string path; UnityEngine.UI.Image img = i.targetGraphic as UnityEngine.UI.Image; if (img && replaceNeeded.TryGetValue(img, out path)) { i.targetGraphic = MakeLazyLoadImage(img, path); } img = i.graphic as UnityEngine.UI.Image; if (img && replaceNeeded.TryGetValue(img, out path)) { i.graphic = MakeLazyLoadImage(img, path); } } foreach (var i in replaceNeeded) { if (i.Key) { MakeLazyLoadImage(i.Key, i.Value); } } //Fix LazyLoadText UnityEngine.UI.InputField[] ifs = obj.GetComponentsInChildren <UnityEngine.UI.InputField>(true); foreach (var i in ifs) { if (!i) { continue; } string path; UnityEngine.UI.Text img = i.textComponent as UnityEngine.UI.Text; if (img && txtReplaceNeeded.TryGetValue(img, out path)) { i.textComponent = MakeLazyLoadText(img, path); } img = i.placeholder as UnityEngine.UI.Text; if (img && txtReplaceNeeded.TryGetValue(img, out path)) { i.placeholder = MakeLazyLoadText(img, path); } } foreach (var i in txtReplaceNeeded) { if (i.Key) { MakeLazyLoadText(i.Key, i.Value); } } Camera camera = obj.GetComponentInChildren <Camera>(); if (camera != null) { MonoBehaviour.DestroyImmediate(camera); } AudioListener lis = obj.GetComponentInChildren <AudioListener>(); if (lis != null) { MonoBehaviour.DestroyImmediate(lis); } ResConfig config = obj.AddComponent <ResConfig>(); config.ReleaseOnLevelLoaded = false; GameObject objPrefab = UnityEditor.PrefabUtility.CreatePrefab(genPath, obj); //objPrefab.name = obj.name + GOEPack.m_prefabExt; UnityEngine.Object.DestroyImmediate(obj); using (System.IO.StreamWriter sw = new StreamWriter(md5File, false, System.Text.Encoding.ASCII)) { sw.WriteLine(hash); sw.Flush(); } }
private void LoadConfig() { AssetManager.Instance.LoadConfig(ResType.Config, ResConfig.GetABPath(ResType.Config, ""), "", LoadComplete); }
public static string GetResConfigRoot(ResConfig config) { return(AssetBundleBuilder.GetResConfigRoot() + "/" + config.ToRemoteName()); }