mod:修改帮助类的功能,并进行详细注释
parent
662f80a092
commit
0a31a3a65d
|
@ -8,6 +8,11 @@ namespace ZXL.Helper
|
||||||
{
|
{
|
||||||
public static class CommonHelper
|
public static class CommonHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 遍历更改所有子物体的layer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="self"></param>
|
||||||
|
/// <param name="layer"></param>
|
||||||
public static void SetWithChildLayer(this Transform self, LayerMask layer)
|
public static void SetWithChildLayer(this Transform self, LayerMask layer)
|
||||||
{
|
{
|
||||||
List<Transform> findDeep = new List<Transform>();
|
List<Transform> findDeep = new List<Transform>();
|
||||||
|
@ -23,7 +28,13 @@ namespace ZXL.Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 遍历查找并返回名字对应的物体
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="self"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public static T FindChildDeep<T>(this Transform self, string name) where T : Object
|
public static T FindChildDeep<T>(this Transform self, string name) where T : Object
|
||||||
{
|
{
|
||||||
Transform findDeep = null;
|
Transform findDeep = null;
|
||||||
|
@ -93,6 +104,14 @@ namespace ZXL.Helper
|
||||||
return rendererIsInsideBox;
|
return rendererIsInsideBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 调用win的消息弹窗
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="title"></param>
|
||||||
|
/// <param name="content"></param>
|
||||||
|
/// <param name="okAction"></param>
|
||||||
|
/// <param name="cancelAction"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
public static void MessageBox(string title, string content, Action okAction, Action cancelAction,
|
public static void MessageBox(string title, string content, Action okAction, Action cancelAction,
|
||||||
MessageBoxType type = MessageBoxType.确定取消)
|
MessageBoxType type = MessageBoxType.确定取消)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,38 +8,22 @@ namespace ZXL.Helper
|
||||||
{
|
{
|
||||||
public static class FileHelper
|
public static class FileHelper
|
||||||
{
|
{
|
||||||
/// <summary>
|
#region File
|
||||||
/// 不存在文件夹就创建
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="srcRootPath"></param>
|
|
||||||
public static void CreateDirectory(string srcRootPath)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(srcRootPath))
|
|
||||||
Directory.CreateDirectory(srcRootPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除文件夹(递归删除所有子文件)
|
/// 创建文件,并写入内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="srcRootPath"></param>
|
/// <param name="srcFilePath"></param>
|
||||||
public static void DeleteFolder(string srcRootPath)
|
/// <param name="bytes"></param>
|
||||||
|
public static void CreateFile(string srcFilePath, byte[] bytes)
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(srcRootPath))
|
FileInfo file = new FileInfo(srcFilePath);
|
||||||
return;
|
if (file.Directory != null) file.Directory.Create();
|
||||||
|
Stream sw;
|
||||||
DirectoryInfo dir = new DirectoryInfo(srcRootPath);
|
sw = file.Create();
|
||||||
dir.Delete(true);
|
sw.Write(bytes, 0, bytes.Length);
|
||||||
}
|
sw.Close();
|
||||||
|
sw.Dispose();
|
||||||
/// <summary>
|
|
||||||
/// 移动文件夹到指定位置(包括所有子文件)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="srcRootPath"></param>
|
|
||||||
/// <param name="destRootPath"></param>
|
|
||||||
public static void MoveFolderWithFiles(string srcRootPath, string destRootPath)
|
|
||||||
{
|
|
||||||
CopyFolderWithFiles(srcRootPath, destRootPath);
|
|
||||||
DeleteFolder(srcRootPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -59,18 +43,12 @@ namespace ZXL.Helper
|
||||||
return newPath;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RenameFolder(string srcFilePath, string newName)
|
/// <summary>
|
||||||
{
|
/// 弃用
|
||||||
if (string.IsNullOrEmpty(newName))
|
/// </summary>
|
||||||
return null;
|
/// <param name="srcFilePath"></param>
|
||||||
|
/// <param name="newName"></param>
|
||||||
var directoryInfo = new DirectoryInfo(srcFilePath);
|
[Obsolete("弃用,不允许重名")]
|
||||||
var newPath = Path.Combine(directoryInfo.Parent.FullName, newName);
|
|
||||||
Debug.Log(newPath);
|
|
||||||
directoryInfo.MoveTo(newPath);
|
|
||||||
return newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RenameFiles(string srcFilePath, string newName)
|
public static void RenameFiles(string srcFilePath, string newName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(newName))
|
if (string.IsNullOrEmpty(newName))
|
||||||
|
@ -83,6 +61,10 @@ namespace ZXL.Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 准确说这个应该叫拷贝,因为这个是复制在同一个文件夹下
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcFilePath"></param>
|
||||||
public static void CopyFile(string srcFilePath)
|
public static void CopyFile(string srcFilePath)
|
||||||
{
|
{
|
||||||
var info = new FileInfo(srcFilePath);
|
var info = new FileInfo(srcFilePath);
|
||||||
|
@ -91,6 +73,83 @@ namespace ZXL.Helper
|
||||||
File.Copy(srcFilePath, newFilePath, true);
|
File.Copy(srcFilePath, newFilePath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移动文件到指定位置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcFilePath"></param>
|
||||||
|
/// <param name="newFilePath"></param>
|
||||||
|
public static void MoveFile(string srcFilePath, string newFilePath)
|
||||||
|
{
|
||||||
|
var info = new FileInfo(srcFilePath);
|
||||||
|
info.MoveTo(newFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除文件(不可逆,慎用)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcFilePath"></param>
|
||||||
|
public static void DeleteFile(string srcFilePath)
|
||||||
|
{
|
||||||
|
FileInfo file = new FileInfo(srcFilePath);
|
||||||
|
file.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Directory
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 不存在文件夹就创建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcRootPath"></param>
|
||||||
|
public static void CreateDirectory(string srcRootPath)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(srcRootPath))
|
||||||
|
Directory.CreateDirectory(srcRootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除文件夹(递归删除所有子文件)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcRootPath"></param>
|
||||||
|
public static void DeleteDirectory(string srcRootPath)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(srcRootPath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DirectoryInfo dir = new DirectoryInfo(srcRootPath);
|
||||||
|
dir.Delete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移动文件夹到指定位置(包括所有子文件)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcRootPath"></param>
|
||||||
|
/// <param name="destRootPath"></param>
|
||||||
|
public static void MoveDirectoryWithFiles(string srcRootPath, string destRootPath)
|
||||||
|
{
|
||||||
|
CopyFolderWithFiles(srcRootPath, destRootPath);
|
||||||
|
DeleteDirectory(srcRootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重命名文件夹
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="srcFilePath"></param>
|
||||||
|
/// <param name="newName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 复制文件夹到指定位置(包括所有子文件)
|
/// 复制文件夹到指定位置(包括所有子文件)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -152,5 +211,7 @@ namespace ZXL.Helper
|
||||||
CopyFolderWithFiles(srcDirectoryFullName, Path.Combine(destRootPath, srcDirectoryBaseRootPath));
|
CopyFolderWithFiles(srcDirectoryFullName, Path.Combine(destRootPath, srcDirectoryBaseRootPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,11 @@ namespace ZXL.Helper
|
||||||
{
|
{
|
||||||
public static class TextureHelper
|
public static class TextureHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 精灵图片转纹理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sprite"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Texture2D TextureToSprite(Sprite sprite)
|
public static Texture2D TextureToSprite(Sprite sprite)
|
||||||
{
|
{
|
||||||
// 获取 Sprite 的纹理
|
// 获取 Sprite 的纹理
|
||||||
|
@ -23,6 +28,11 @@ namespace ZXL.Helper
|
||||||
return texture2D;
|
return texture2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 纹理转精灵图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Sprite TextureToSprite(Texture2D texture)
|
public static Sprite TextureToSprite(Texture2D texture)
|
||||||
{
|
{
|
||||||
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
|
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
|
||||||
|
@ -30,6 +40,11 @@ namespace ZXL.Helper
|
||||||
return sprite;
|
return sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 截取相机画面内容并返回()
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="camera"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Texture2D SaveCameraToTexture(Camera camera)
|
public static Texture2D SaveCameraToTexture(Camera camera)
|
||||||
{
|
{
|
||||||
Texture2D capturedImage;
|
Texture2D capturedImage;
|
||||||
|
|
|
@ -333,7 +333,7 @@ namespace ZXL.Manager
|
||||||
|
|
||||||
public void MoveAsset(string oldPath, string newPath)
|
public void MoveAsset(string oldPath, string newPath)
|
||||||
{
|
{
|
||||||
FileHelper.MoveFolderWithFiles(oldPath, newPath);
|
FileHelper.MoveDirectoryWithFiles(oldPath, newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in New Issue