/// <summary> /// 查找所有 *.unity 的场景 /// </summary> /// <param name="isShowAll">是否显示所有</param> /// <returns></returns> public static Dictionary <string, string> FindAllUnityScene(bool isShowAll = false) { string[] untiyFileFullPaths = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories); Dictionary <string, string> nameK_AssetPathV = new Dictionary <string, string>(); foreach (string fullPath in untiyFileFullPaths) { if (!isShowAll) { if (fullPath.Contains("\\_AssetBundleResources") || fullPath.Contains("\\Plugins")) // 不包含需要打包出去的 AssetBundle 包中的场景 { continue; } } string name = MyAssetUtil.GetFileNameByFullNameNoSuffix(fullPath); string assetPath = MyAssetUtil.GetAssetsBackPath(fullPath); if (nameK_AssetPathV.ContainsKey(name)) { MyLog.Red("有相同名字的场景,修改一下"); } else { nameK_AssetPathV.Add(name, assetPath); } } return(nameK_AssetPathV); }
private void SaveTu() // 保存图片 { foreach (string path in pathK_ImageV.Keys) { string resPath = Application.dataPath + "/GameAssets/Sprite/" + MyAssetUtil.GetFileNameByFullName(path); // 将图片复制 "/GameAssets/Sprite/" 文件夹下 MyIO.FileCopy(path, resPath); string assetPath = MyAssetUtil.GetAssetsBackPath(resPath); AssetDatabase.Refresh(); // 转化成 Sprite Texture2DChangeSprite(assetPath); ; Sprite sp = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath); pathK_ImageV[path].sprite = sp; } pathK_ImageV.Clear(); }
/// <summary> /// 返回当前项目中的所有场景配置 /// </summary> public static List <SMSceneConfigurationBase> FindConfigurations() { List <SMSceneConfigurationBase> allConfigurations = new List <SMSceneConfigurationBase>(); string[] assetFullPaths = Directory.GetFiles(Application.dataPath, "*.asset", SearchOption.AllDirectories); foreach (string fullPath in assetFullPaths) { string assetPath = MyAssetUtil.GetAssetsBackPath(fullPath); SMSceneConfigurationBase configuration = AssetDatabase.LoadAssetAtPath(assetPath, typeof(SMSceneConfigurationBase)) as SMSceneConfigurationBase; if (configuration != null) { allConfigurations.Add(configuration); } } return(allConfigurations); }
/// <summary> /// 在 _EditorUtil 文件夹下找图片或者GUISkin /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fileName">文件名 如:</param> /// <returns></returns> public static T FindTextureOrGUISkin <T>(string fileName) where T : Object { if (null == m_EidtorUtilPaths) { m_EidtorUtilPaths = Directory.GetDirectories(Application.dataPath, EditorUtil, SearchOption.AllDirectories); } if (m_EidtorUtilPaths.Length == 0) // 还是为空的情况 { MyLog.Red("没有找到 _EditorUtil 的文件夹"); return(null); } string fileFullPath = ""; foreach (string editorUtilPath in m_EidtorUtilPaths) { string[] fileFullPaths = Directory.GetFiles(editorUtilPath, fileName, SearchOption.AllDirectories); if (fileFullPaths.Length == 1) { fileFullPath = fileFullPaths[0]; break; } if (fileFullPaths.Length > 1) { MyLog.Yellow("有多个相同名字的文件 —— " + fileName); } } if (string.IsNullOrEmpty(fileFullPath)) { MyLog.Red("没有找到这个文件 —— " + fileName); return(null); } string assetPath = MyAssetUtil.GetAssetsBackPath(fileFullPath); return(AssetDatabase.LoadMainAssetAtPath(assetPath) as T); }
private void AddTu() { l_Sprites.Clear(); // 一般的动画图片都是放在一起,而且还是前缀相同的 Sprite sp = Target.sprite; if (null == Target || null == sp) { MyLog.Red("先添加一个图片在 Image 上啊"); return; } // 图片名:abc_01,abc_02,abc_03 int lastIndex = sp.name.LastIndexOf("_", StringComparison.Ordinal); // 找到 abc_ string sameName = sp.name.Substring(0, lastIndex+1); // Assets/GameAssets/_Sprite/Holo Atlas.png string aasetpath = AssetDatabase.GetAssetPath(sp); // 这个是加载图集中的 Object[] objs = AssetDatabase.LoadAllAssetsAtPath(aasetpath); foreach (Object o in objs) { if (o.name.Contains(sameName)) { Sprite spo = o as Sprite; if (null != spo) { l_Sprites.Add(spo); } } } if (l_Sprites.Count > 1) { return; } l_Sprites.Clear(); // 表示还没有找到,那就在它的文件夹下面找 lastIndex = aasetpath.LastIndexOf("/", StringComparison.Ordinal); string directionPath = aasetpath.Substring(0, lastIndex); string[] files = Directory.GetFiles(directionPath); foreach (string fileFullPath in files) { string fileName = MyAssetUtil.GetFileNameByFullName(fileFullPath); if (fileName.Contains(sameName) && !fileName.Contains(".meta")) { string assetPath = MyAssetUtil.GetAssetsBackPath(fileFullPath); Sprite objSp = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath); l_Sprites.Add(objSp); } } /* // 找到这个图片的 Asset 路径 // 找到目录路径 Object[] objs = AssetDatabase.LoadAllAssetsAtPath(directionPath+"/"); foreach (Object o in objs) { MyLog.Red(o.name); }*/ }