static void InitEffect() { List <string> tmpPaths = EditorResHelper.GetAllResourcePath(Effect_Path, false); foreach (string path in tmpPaths) { string tmpPath = path.Replace('\\', '/'); GameObject tmpGo = AssetDatabase.LoadAssetAtPath <GameObject>(tmpPath); if (null == tmpGo) { continue; } EffectRecord tmpEffectRecord = tmpGo.GetComponent <EffectRecord>(); if (null == tmpEffectRecord) { tmpEffectRecord = tmpGo.AddComponent <EffectRecord>(); } tmpEffectRecord.Init(); EditorUtility.SetDirty(tmpGo); } AssetDatabase.Refresh(); }
// 这个目录下的prefab引用的图片不打图集 private static void SetNoAtlas(string dir) { List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { List <string> pathes = CollectDependencies(path); foreach (string pt in pathes) { string extension = Path.GetExtension(pt); if (extension == ".cs" || extension == ".dll") { continue; } if (pt.Contains("Resources")) { continue; } if (pt == path) { continue; } SetAtlas(pt, ""); } } }
private static void ClearPackingTagAndAssetBundle(string path) { List <string> tmpResList = EditorResHelper.GetAllResourcePath(path, true); foreach (string pt in tmpResList) { if (Path.GetExtension(pt).Equals(".cs")) { continue; } AssetImporter tmpImporter = AssetImporter.GetAtPath(pt); if (tmpImporter == null) { continue; } tmpImporter.assetBundleName = ""; if (tmpImporter is TextureImporter) { (tmpImporter as TextureImporter).spritePackingTag = ""; } } }
private static void ClearPackingTagAndAssetBundle() { List <string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/AssetBundles/", true); foreach (string bundlePath in bundlePaths) { AssetImporter importer = AssetImporter.GetAtPath(bundlePath); if (importer == null) { continue; } //Log.Info(bundlePath); importer.assetBundleName = ""; } //List<string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true); //foreach (string pt in paths) //{ // string extendName = Path.GetExtension(pt); // if (extendName == ".cs") // { // continue; // } // AssetImporter importer = AssetImporter.GetAtPath(pt); // if (importer == null) // { // continue; // } // //Log.Info(bundlePath); // importer.assetBundleName = ""; // SetAtlas(pt, ""); //} }
// 会将目录下的每个prefab引用的资源强制打成一个包,不分析共享资源 private static void SetIndependentBundleAndAtlas(string dir) { List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); AssetImporter importer = AssetImporter.GetAtPath(path1); if (importer == null || go == null) { Debug.LogError("error: " + path1); continue; } importer.assetBundleName = $"{go.name}.unity3d"; List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { if (pt == path1) { continue; } SetBundleAndAtlas(pt, go.name, true); } } }
// 目录下每个prefab打个包,分析共享资源,共享资源打个包 private void SetShareBundleAndAtlas(string dir) { this.dictionary.Clear(); List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name); List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { string extension = Path.GetExtension(pt); if (extension == ".cs" || extension == ".dll") { continue; } if (pt.Contains("Resources")) { continue; } if (pt == path1) { continue; } // 不存在则记录下来 if (!this.dictionary.ContainsKey(pt)) { Debug.Log($"{path1}----{pt}"); BundleInfo bundleInfo = new BundleInfo(); bundleInfo.ParentPaths.Add(path1); this.dictionary.Add(pt, bundleInfo); SetAtlas(pt, go.name); continue; } // 依赖的父亲不一样 BundleInfo info = this.dictionary[pt]; if (info.ParentPaths.Contains(path1)) { continue; } info.ParentPaths.Add(path1); //DirectoryInfo dirInfo = new DirectoryInfo(dir); //string dirName = dirInfo.Name; SetBundleAndAtlas(pt, $"{Path.GetFileNameWithoutExtension(pt)}_share"); } } }
private static void ClearPackingTagAndAssetBundle() { List <string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true); foreach (string path in paths) { SetBundleAndAtlas(path, string.Empty, true); } }
private static void SetBundleHumanTexture(string dir, bool subDir = true) { List <string> paths = EditorResHelper.GetAllResourcePath(dir, subDir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name, true); } }
private static void SetBundles(string dir) { List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name); } }
// 分析共享资源 private void SetShareBundleAndAtlas(string dir) { this.dictionary.Clear(); List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name); List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { if (pt == path1) { continue; } // 不存在则记录下来 if (!this.dictionary.ContainsKey(pt)) { // 如果已经设置了包 if (GetBundleName(pt) != "") { continue; } Debug.Log($"{path1}----{pt}"); BundleInfo bundleInfo = new BundleInfo(); bundleInfo.ParentPaths.Add(path1); this.dictionary.Add(pt, bundleInfo); SetAtlas(pt, go.name); continue; } // 依赖的父亲不一样 BundleInfo info = this.dictionary[pt]; if (info.ParentPaths.Contains(path1)) { continue; } info.ParentPaths.Add(path1); DirectoryInfo dirInfo = new DirectoryInfo(dir); string dirName = dirInfo.Name; SetBundleAndAtlas(pt, $"{dirName}-share", true); } } }
private static void SetShareBundleAndAtlas(string dir) { dictionary.Clear(); List <string> paths = EditorResHelper.GetPrefabAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name); List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { if (pt == path1) { continue; } if (!dictionary.ContainsKey(pt)) { if (GetBundleName(pt) != string.Empty) { continue; } Log.Info($"{path1}----{pt}"); BundleInfo bundleInfo = new BundleInfo(); bundleInfo.ParentsPaths.Add(path1); dictionary.Add(pt, bundleInfo); SetAtlas(pt, go.name); continue; } BundleInfo info = dictionary[pt]; if (info.ParentsPaths.Contains(path1)) { continue; } info.ParentsPaths.Add(path1); DirectoryInfo dirInfo = new DirectoryInfo(dir); string dirName = dirInfo.Name; SetBundleAndAtlas(pt, $"{dirName}-share", true); } } }
private static void SetNoAtlas(string dir) { List <string> paths = EditorResHelper.GetPrefabAndScenes(dir); foreach (string path in paths) { List <string> pathes = CollectDependencies(path); foreach (string pt in pathes) { if (pt == path) { continue; } SetAtlas(pt, string.Empty, true); } } }
private static void ClearPackingTagAndAssetBundle() { List <string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/Bundles/", true); foreach (string bundlePath in bundlePaths) { AssetImporter importer = AssetImporter.GetAtPath(bundlePath); if (importer == null) { continue; } //Log.Info(bundlePath); importer.assetBundleName = ""; } List <string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true); foreach (string path in paths) { string extendName = Path.GetExtension(path); if (extendName == ".cs") { continue; } AssetImporter importer = AssetImporter.GetAtPath(path); if (importer == null) { continue; } //Log.Info(path); importer.assetBundleName = ""; TextureImporter textureImporter = importer as TextureImporter; if (textureImporter != null) { textureImporter.spritePackingTag = ""; } } }
private static void ClearPackingTagAndAssetBundle() { List <string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/Bundles/", true); foreach (string bundlePath in bundlePaths) { SetBundle(bundlePath, "", true); List <string> pathes = CollectDependencies(bundlePath); foreach (string pt in pathes) { if (pt == bundlePath) { continue; } SetBundleAndAtlas(pt, "", true); } } }
// 会将目录下的每个prefab引用的资源强制打成一个包,不分析共享资源 private static void SetIndependentBundleAndAtlas(string dir) { List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); AssetImporter importer = AssetImporter.GetAtPath(path1); if (importer == null || go == null) { Debug.LogError("error: " + path1); continue; } importer.assetBundleName = $"{Path.GetDirectoryName(path1)}/{go.name}.unity3d"; List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { string extension = Path.GetExtension(pt); if (extension == ".cs" || extension == ".dll") { continue; } if (pt.Contains("Resources")) { continue; } if (pt == path1) { continue; } SetBundleAndAtlas(pt, go.name); } } }
static void InitEffectShader() { List <string> tmpPaths = EditorResHelper.GetAllResourcePath(Effect_Path, false); foreach (string path in tmpPaths) { string tmpPath = path.Replace('\\', '/'); GameObject tmpGo = AssetDatabase.LoadAssetAtPath <GameObject>(tmpPath); if (null == tmpGo) { continue; } Renderer[] tmpRenderers = tmpGo.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < tmpRenderers.Length; i++) { Material[] mats = tmpRenderers[i].sharedMaterials; for (int j = 0; j < mats.Length; j++) { Material mat = mats[j]; if (mat != null) { Shader shader = Shader.Find(mat.shader.name); if (shader != null) { mat.shader = shader; } } } } EditorUtility.SetDirty(tmpGo); } AssetDatabase.Refresh(); }
private static void ClearPackingTagAndAssetBundle() { //清空根目录Bundles文件夹下的所有资源标记名 List <string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/Bundles/", true); foreach (string bundlePath in bundlePaths) { AssetImporter importer = AssetImporter.GetAtPath(bundlePath); if (importer == null) { continue; } //Log.Info(bundlePath); importer.assetBundleName = ""; } //清空根目录Res文件夹下的所有资源标记名 List <string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true); foreach (string pt in paths) { string extendName = Path.GetExtension(pt); if (extendName == ".cs") { continue; } AssetImporter importer = AssetImporter.GetAtPath(pt); if (importer == null) { continue; } //Log.Info(bundlePath); importer.assetBundleName = ""; SetAtlas(pt, ""); } }
private static void SetBundleAndAtlasWithoutShare(string dir) { List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name, true); //List<string> pathes = CollectDependencies(path1); //foreach (string pt in pathes) //{ // if (pt == path1) // { // continue; // } // // SetBundleAndAtlas(pt, go.name); //} } }
private static void SetIndependentBundleAndAtlas(string dir) { List <string> paths = EditorResHelper.GetPrefabAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); SetBundle(path1, go.name); List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { if (pt == path1) { continue; } SetBundleAndAtlas(pt, go.name, true); } } }
private void SetOneDirPackingTagAndAssetBundle(string dir) { this.dictionary.Clear(); List <string> paths = EditorResHelper.GetPrefabsAndScenes(dir); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); Object go = AssetDatabase.LoadAssetAtPath <Object>(path1); AssetImporter importer = AssetImporter.GetAtPath(path1); if (importer == null || go == null) { Log.Error("error: " + path1); continue; } importer.assetBundleName = $"{go.name}.unity3d"; List <string> pathes = CollectDependencies(path1); foreach (string pt in pathes) { string extension = Path.GetExtension(pt); if (extension == ".cs" || extension == ".dll") { continue; } if (pt.Contains("Resources")) { continue; } if (pt == path1) { continue; } // 不存在则记录下来 if (!this.dictionary.ContainsKey(pt)) { Log.Info($"{path1}----{pt}"); BundleInfo bundleInfo = new BundleInfo(); bundleInfo.ParentPaths.Add(path1); this.dictionary.Add(pt, bundleInfo); AssetImporter importer3 = AssetImporter.GetAtPath(pt); TextureImporter textureImporter3 = importer3 as TextureImporter; if (textureImporter3 != null) { textureImporter3.spritePackingTag = go.name; } continue; } // 依赖的父亲不一样 BundleInfo info = this.dictionary[pt]; if (info.ParentPaths.Contains(path1)) { continue; } info.ParentPaths.Add(path1); AssetImporter importer2 = AssetImporter.GetAtPath(pt); if (importer2 == null) { continue; } if (importer2.assetBundleName != "") { continue; } DirectoryInfo dirInfo = new DirectoryInfo(dir); string dirName = dirInfo.Name; importer2.assetBundleName = $"{dirName}-share.unity3d"; Log.Warning($"{importer2.assetBundleName}: {pt} {info.ParentPaths.ListToString()}"); TextureImporter textureImporter = importer2 as TextureImporter; if (textureImporter != null) { textureImporter.spritePackingTag = $"{dirName}-share"; } } } }
/// <summary> /// 对一个目录进行打包设置 /// </summary> /// <param name="dirName"></param> private void SetOneDirPackingTagAndAssetBundle(string dirName) { this.dictionary.Clear(); //去当前目录的预设; List <string> paths = EditorResHelper.GetAllPath($"Assets/Bundles/{dirName}", true); foreach (string path in paths) { string path1 = path.Replace('\\', '/'); GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>(path1); AssetImporter importer = AssetImporter.GetAtPath(path1); importer.assetBundleName = $"{go.name}.unity3d"; UnityEngine.Object[] objects = EditorUtility.CollectDependencies(new UnityEngine.Object[] { go }); foreach (UnityEngine.Object o in objects) { string pt = AssetDatabase.GetAssetPath(o); string extension = Path.GetExtension(pt); if (extension == ".cs" || extension == ".dll") { continue; } if (pt.Contains("Resources")) { continue; } if (pt == path1) { continue; } // 不存在则记录下来 if (!this.dictionary.ContainsKey(pt)) { // Log.Info($"{path1}----{pt}"); BundleInfo bundleInfo = new BundleInfo(); bundleInfo.ParentPaths.Add(path1); this.dictionary.Add(pt, bundleInfo); AssetImporter importer3 = AssetImporter.GetAtPath(pt); TextureImporter textureImporter3 = importer3 as TextureImporter; if (textureImporter3 != null) { textureImporter3.spritePackingTag = go.name; } continue; } // 依赖的父亲不一样 BundleInfo info = this.dictionary[pt]; if (info.ParentPaths.Contains(path1)) { continue; } info.ParentPaths.Add(path1); AssetImporter importer2 = AssetImporter.GetAtPath(pt); if (importer2 == null) { continue; } if (importer2.assetBundleName != "") { continue; } importer2.assetBundleName = $"{dirName}share.unity3d"; // Log.Warning($"{importer2.assetBundleName}: {pt} {info.ParentPaths.ListToString()}"); TextureImporter textureImporter = importer2 as TextureImporter; if (textureImporter != null) { textureImporter.spritePackingTag = $"{dirName}share"; } } } }