diff --git a/Assets/ZXL/Scripts/Helper/CommonHelper.cs b/Assets/ZXL/Scripts/Helper/CommonHelper.cs index 899a2bc..60967d6 100644 --- a/Assets/ZXL/Scripts/Helper/CommonHelper.cs +++ b/Assets/ZXL/Scripts/Helper/CommonHelper.cs @@ -8,6 +8,11 @@ namespace ZXL.Helper { public static class CommonHelper { + /// + /// 遍历更改所有子物体的layer + /// + /// + /// public static void SetWithChildLayer(this Transform self, LayerMask layer) { List findDeep = new List(); @@ -23,7 +28,13 @@ namespace ZXL.Helper } } - + /// + /// 遍历查找并返回名字对应的物体 + /// + /// + /// + /// + /// public static T FindChildDeep(this Transform self, string name) where T : Object { Transform findDeep = null; @@ -93,6 +104,14 @@ namespace ZXL.Helper return rendererIsInsideBox; } + /// + /// 调用win的消息弹窗 + /// + /// + /// + /// + /// + /// public static void MessageBox(string title, string content, Action okAction, Action cancelAction, MessageBoxType type = MessageBoxType.确定取消) { diff --git a/Assets/ZXL/Scripts/Helper/FileHelper.cs b/Assets/ZXL/Scripts/Helper/FileHelper.cs index 65adac8..54b254d 100644 --- a/Assets/ZXL/Scripts/Helper/FileHelper.cs +++ b/Assets/ZXL/Scripts/Helper/FileHelper.cs @@ -8,38 +8,22 @@ namespace ZXL.Helper { public static class FileHelper { - /// - /// 不存在文件夹就创建 - /// - /// - public static void CreateDirectory(string srcRootPath) - { - if (!Directory.Exists(srcRootPath)) - Directory.CreateDirectory(srcRootPath); - } + #region File /// - /// 删除文件夹(递归删除所有子文件) + /// 创建文件,并写入内容 /// - /// - public static void DeleteFolder(string srcRootPath) + /// + /// + public static void CreateFile(string srcFilePath, byte[] bytes) { - if (!Directory.Exists(srcRootPath)) - return; - - DirectoryInfo dir = new DirectoryInfo(srcRootPath); - dir.Delete(true); - } - - /// - /// 移动文件夹到指定位置(包括所有子文件) - /// - /// - /// - public static void MoveFolderWithFiles(string srcRootPath, string destRootPath) - { - CopyFolderWithFiles(srcRootPath, destRootPath); - DeleteFolder(srcRootPath); + FileInfo file = new FileInfo(srcFilePath); + if (file.Directory != null) file.Directory.Create(); + Stream sw; + sw = file.Create(); + sw.Write(bytes, 0, bytes.Length); + sw.Close(); + sw.Dispose(); } /// @@ -59,18 +43,12 @@ namespace ZXL.Helper return newPath; } - public static string RenameFolder(string srcFilePath, string newName) - { - if (string.IsNullOrEmpty(newName)) - return null; - - var directoryInfo = new DirectoryInfo(srcFilePath); - var newPath = Path.Combine(directoryInfo.Parent.FullName, newName); - Debug.Log(newPath); - directoryInfo.MoveTo(newPath); - return newPath; - } - + /// + /// 弃用 + /// + /// + /// + [Obsolete("弃用,不允许重名")] public static void RenameFiles(string srcFilePath, string newName) { if (string.IsNullOrEmpty(newName)) @@ -83,6 +61,10 @@ namespace ZXL.Helper } } + /// + /// 准确说这个应该叫拷贝,因为这个是复制在同一个文件夹下 + /// + /// public static void CopyFile(string srcFilePath) { var info = new FileInfo(srcFilePath); @@ -91,6 +73,83 @@ namespace ZXL.Helper File.Copy(srcFilePath, newFilePath, true); } + /// + /// 移动文件到指定位置 + /// + /// + /// + public static void MoveFile(string srcFilePath, string newFilePath) + { + var info = new FileInfo(srcFilePath); + info.MoveTo(newFilePath); + } + + /// + /// 删除文件(不可逆,慎用) + /// + /// + public static void DeleteFile(string srcFilePath) + { + FileInfo file = new FileInfo(srcFilePath); + file.Delete(); + } + + #endregion + + #region Directory + + /// + /// 不存在文件夹就创建 + /// + /// + public static void CreateDirectory(string srcRootPath) + { + if (!Directory.Exists(srcRootPath)) + Directory.CreateDirectory(srcRootPath); + } + + /// + /// 删除文件夹(递归删除所有子文件) + /// + /// + public static void DeleteDirectory(string srcRootPath) + { + if (!Directory.Exists(srcRootPath)) + return; + + DirectoryInfo dir = new DirectoryInfo(srcRootPath); + dir.Delete(true); + } + + /// + /// 移动文件夹到指定位置(包括所有子文件) + /// + /// + /// + public static void MoveDirectoryWithFiles(string srcRootPath, string destRootPath) + { + CopyFolderWithFiles(srcRootPath, destRootPath); + DeleteDirectory(srcRootPath); + } + + /// + /// 重命名文件夹 + /// + /// + /// + /// + public static string RenameDirectory(string srcFilePath, string newName) + { + if (string.IsNullOrEmpty(newName)) + return null; + + var directoryInfo = new DirectoryInfo(srcFilePath); + var newPath = Path.Combine(directoryInfo.Parent.FullName, newName); + Debug.Log(newPath); + directoryInfo.MoveTo(newPath); + return newPath; + } + /// /// 复制文件夹到指定位置(包括所有子文件) /// @@ -152,5 +211,7 @@ namespace ZXL.Helper CopyFolderWithFiles(srcDirectoryFullName, Path.Combine(destRootPath, srcDirectoryBaseRootPath)); } } + + #endregion } } \ No newline at end of file diff --git a/Assets/ZXL/Scripts/Helper/TextureHelper.cs b/Assets/ZXL/Scripts/Helper/TextureHelper.cs index 68f9014..5a91254 100644 --- a/Assets/ZXL/Scripts/Helper/TextureHelper.cs +++ b/Assets/ZXL/Scripts/Helper/TextureHelper.cs @@ -4,6 +4,11 @@ namespace ZXL.Helper { public static class TextureHelper { + /// + /// 精灵图片转纹理 + /// + /// + /// public static Texture2D TextureToSprite(Sprite sprite) { // 获取 Sprite 的纹理 @@ -23,6 +28,11 @@ namespace ZXL.Helper return texture2D; } + /// + /// 纹理转精灵图片 + /// + /// + /// public static Sprite TextureToSprite(Texture2D texture) { Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), @@ -30,6 +40,11 @@ namespace ZXL.Helper return sprite; } + /// + /// 截取相机画面内容并返回() + /// + /// + /// public static Texture2D SaveCameraToTexture(Camera camera) { Texture2D capturedImage; diff --git a/Assets/ZXL/Scripts/Manager/AssetManager.cs b/Assets/ZXL/Scripts/Manager/AssetManager.cs index 7e83aba..ad30dde 100644 --- a/Assets/ZXL/Scripts/Manager/AssetManager.cs +++ b/Assets/ZXL/Scripts/Manager/AssetManager.cs @@ -333,7 +333,7 @@ namespace ZXL.Manager public void MoveAsset(string oldPath, string newPath) { - FileHelper.MoveFolderWithFiles(oldPath, newPath); + FileHelper.MoveDirectoryWithFiles(oldPath, newPath); } #endregion