跳到主要内容
版本:2.3.x

Class EditorTools

编辑器工具类

Assembly: YooAsset.Editor.dll
Declaration
public static class EditorTools

Methods

GetAssignableTypes(Type)

获取带继承关系的所有类的类型

Declaration
public static List<Type> GetAssignableTypes(Type parentType)
Returns

System.Collections.Generic.List<System.Type>

Parameters
TypeName
System.TypeparentType

GetTypesWithAttribute(Type)

获取带有指定属性的所有类的类型

Declaration
public static List<Type> GetTypesWithAttribute(Type attrType)
Returns

System.Collections.Generic.List<System.Type>

Parameters
TypeName
System.TypeattrType

InvokeNonPublicStaticMethod(Type, string, params object[])

调用私有的静态方法

Declaration
public static object InvokeNonPublicStaticMethod(Type type, string method, params object[] parameters)
Returns

System.Object

Parameters
TypeNameDescription
System.Typetype类的类型
System.Stringmethod类里要调用的方法名
System.Object[]parameters调用方法传入的参数

InvokePublicStaticMethod(Type, string, params object[])

调用公开的静态方法

Declaration
public static object InvokePublicStaticMethod(Type type, string method, params object[] parameters)
Returns

System.Object

Parameters
TypeNameDescription
System.Typetype类的类型
System.Stringmethod类里要调用的方法名
System.Object[]parameters调用方法传入的参数

GetPackageManagerYooVersion()

Declaration
public static string GetPackageManagerYooVersion()
Returns

System.String

FindAssets(EAssetSearchType, string[])

搜集资源

Declaration
public static string[] FindAssets(EAssetSearchType searchType, string[] searchInFolders)
Returns

System.String[]: 返回搜集到的资源路径列表

Parameters
TypeNameDescription
YooAsset.Editor.EAssetSearchTypesearchType搜集的资源类型
System.String[]searchInFolders指定搜索的文件夹列表

FindAssets(EAssetSearchType, string)

搜集资源

Declaration
public static string[] FindAssets(EAssetSearchType searchType, string searchInFolder)
Returns

System.String[]: 返回搜集到的资源路径列表

Parameters
TypeNameDescription
YooAsset.Editor.EAssetSearchTypesearchType搜集的资源类型
System.StringsearchInFolder指定搜索的文件夹

OpenFolderPanel(string, string, string)

打开搜索面板

Declaration
public static string OpenFolderPanel(string title, string defaultPath, string defaultName = "")
Returns

System.String: 返回选择的文件夹绝对路径,如果无效返回NULL

Parameters
TypeNameDescription
System.Stringtitle标题名称
System.StringdefaultPath默认搜索路径
System.StringdefaultName

OpenFilePath(string, string, string)

打开搜索面板

Declaration
public static string OpenFilePath(string title, string defaultPath, string extension = "")
Returns

System.String: 返回选择的文件绝对路径,如果无效返回NULL

Parameters
TypeNameDescription
System.Stringtitle标题名称
System.StringdefaultPath默认搜索路径
System.Stringextension

DisplayProgressBar(string, int, int)

显示进度框

Declaration
public static void DisplayProgressBar(string tips, int progressValue, int totalValue)
Parameters
TypeName
System.Stringtips
System.Int32progressValue
System.Int32totalValue

ClearProgressBar()

隐藏进度框

Declaration
public static void ClearProgressBar()

FocusUnitySceneWindow()

Declaration
public static void FocusUnitySceneWindow()

CloseUnityGameWindow()

Declaration
public static void CloseUnityGameWindow()

FocusUnityGameWindow()

Declaration
public static void FocusUnityGameWindow()

FocueUnityProjectWindow()

Declaration
public static void FocueUnityProjectWindow()

FocusUnityHierarchyWindow()

Declaration
public static void FocusUnityHierarchyWindow()

FocusUnityInspectorWindow()

Declaration
public static void FocusUnityInspectorWindow()

FocusUnityConsoleWindow()

Declaration
public static void FocusUnityConsoleWindow()

ClearUnityConsole()

清空控制台

Declaration
public static void ClearUnityConsole()

HasDirtyScenes()

Declaration
public static bool HasDirtyScenes()
Returns

System.Boolean

RemoveFirstChar(string)

Declaration
public static string RemoveFirstChar(string str)
Returns

System.String

Parameters
TypeName
System.Stringstr

RemoveLastChar(string)

Declaration
public static string RemoveLastChar(string str)
Returns

System.String

Parameters
TypeName
System.Stringstr

StringToStringList(string, char)

Declaration
public static List<string> StringToStringList(string str, char separator)
Returns

System.Collections.Generic.List<System.String>

Parameters
TypeName
System.Stringstr
System.Charseparator

NameToEnum<T>(string)

Declaration
public static T NameToEnum<T>(string name)
Returns

<T>

Parameters
TypeName
System.Stringname
Type Parameters
  • T

CreateFileDirectory(string)

创建文件所在的目录

Declaration
public static void CreateFileDirectory(string filePath)
Parameters
TypeNameDescription
System.StringfilePath文件路径

CreateDirectory(string)

创建文件夹

Declaration
public static bool CreateDirectory(string directory)
Returns

System.Boolean

Parameters
TypeName
System.Stringdirectory

DeleteDirectory(string)

删除文件夹及子目录

Declaration
public static bool DeleteDirectory(string directory)
Returns

System.Boolean

Parameters
TypeName
System.Stringdirectory

FileRename(string, string)

文件重命名

Declaration
public static void FileRename(string filePath, string newName)
Parameters
TypeName
System.StringfilePath
System.StringnewName

MoveFile(string, string)

移动文件

Declaration
public static void MoveFile(string filePath, string destPath)
Parameters
TypeName
System.StringfilePath
System.StringdestPath

CopyDirectory(string, string)

拷贝文件夹 注意:包括所有子目录的文件

Declaration
public static void CopyDirectory(string sourcePath, string destPath)
Parameters
TypeName
System.StringsourcePath
System.StringdestPath

CopyFile(string, string, bool)

拷贝文件

Declaration
public static void CopyFile(string sourcePath, string destPath, bool overwrite)
Parameters
TypeName
System.StringsourcePath
System.StringdestPath
System.Booleanoverwrite

ClearFolder(string)

清空文件夹

Declaration
public static void ClearFolder(string directoryPath)
Parameters
TypeName
System.StringdirectoryPath

GetFileSize(string)

获取文件字节大小

Declaration
public static long GetFileSize(string filePath)
Returns

System.Int64

Parameters
TypeName
System.StringfilePath

ReadFileAllText(string)

读取文件的所有文本内容

Declaration
public static string ReadFileAllText(string filePath)
Returns

System.String

Parameters
TypeName
System.StringfilePath

ReadFileAllLine(string)

读取文本的所有文本内容

Declaration
public static string[] ReadFileAllLine(string filePath)
Returns

System.String[]

Parameters
TypeName
System.StringfilePath

CheckBundleFileValid(byte[])

检测AssetBundle文件是否合法

Declaration
public static bool CheckBundleFileValid(byte[] fileData)
Returns

System.Boolean

Parameters
TypeName
System.Byte[]fileData

GetRegularPath(string)

获取规范的路径

Declaration
public static string GetRegularPath(string path)
Returns

System.String

Parameters
TypeName
System.Stringpath

RemoveExtension(string)

移除路径里的后缀名

Declaration
public static string RemoveExtension(string str)
Returns

System.String

Parameters
TypeName
System.Stringstr

GetProjectPath()

获取项目工程路径

Declaration
public static string GetProjectPath()
Returns

System.String

AbsolutePathToAssetPath(string)

转换文件的绝对路径为Unity资源路径 例如 D:\YourPorject\Assets\Works\file.txt 替换为 Assets/Works/file.txt

Declaration
public static string AbsolutePathToAssetPath(string absolutePath)
Returns

System.String

Parameters
TypeName
System.StringabsolutePath

AssetPathToAbsolutePath(string)

转换Unity资源路径为文件的绝对路径 例如:Assets/Works/file.txt 替换为 D:\YourPorject/Assets/Works/file.txt

Declaration
public static string AssetPathToAbsolutePath(string assetPath)
Returns

System.String

Parameters
TypeName
System.StringassetPath

FindFolder(string, string)

递归查找目标文件夹路径

Declaration
public static string FindFolder(string root, string folderName)
Returns

System.String: 返回找到的文件夹路径,如果没有找到返回空字符串

Parameters
TypeNameDescription
System.Stringroot搜索的根目录
System.StringfolderName目标文件夹名称

Substring(string, string, bool, bool)

截取字符串 获取匹配到的后面内容

Declaration
public static string Substring(string content, string key, bool includeKey, bool firstMatch = true)
Returns

System.String

Parameters
TypeNameDescription
System.Stringcontent内容
System.Stringkey关键字
System.BooleanincludeKey分割的结果里是否包含关键字
System.BooleanfirstMatch