Odin Attributes 为Unity开发者提供了更多的自定义选项,使得开发过程更加高效和愉悦。通过使用这些特性,开发者可以创建更加专业和用户友好的编辑器界面,从而提升整个开发团队的工作效率。
Folder Path 特性用于字符串属性,并为目录路径提供接口。
1.【FolderPath】 默认情况下,FolderPath提供了一个相对于Unity项目的路径。
// 默认情况下,FolderPath提供了一个相对于Unity项目的路径。
[FolderPath]
public string UnityProjectPath;
2.【ParentFolder】可以提供自定义父路径。父路径可以是相对于Unity项目的,也可以是绝对的。
// 可以提供自定义父路径。父路径可以是相对于Unity项目的,也可以是绝对的。
[FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]
public string RelativeToParentPath;
3.【ParentFolder】使用父路径,FolderPath还可以提供相对于resources文件夹的路径。
// 使用父路径,FolderPath还可以提供相对于resources文件夹的路径。
[FolderPath(ParentFolder = "Assets/Resources")]
public string ResourcePath;
4.【AbsolutePath】通过将AbsolutePath设置为true, FolderPath将提供一个绝对路径。
// 通过将AbsolutePath设置为true, FolderPath将提供一个绝对路径。
[FolderPath(AbsolutePath = true)]
[BoxGroup("Conditions")]
public string AbsolutePath;
5.【RequireExistingPath】如果提供的路径无效,还可以将FolderPath配置为显示错误。
// 如果提供的路径无效,还可以将FolderPath配置为显示错误。
[FolderPath(RequireExistingPath = true)]
[BoxGroup("Conditions")]
public string ExistingPath;
6.【UseBackslashes】默认情况下,FolderPath将强制使用前斜杠。还可以将其配置为使用反斜杠。
// 默认情况下,FolderPath将强制使用前斜杠。还可以将其配置为使用反斜杠。
[FolderPath(UseBackslashes = true)]
[BoxGroup("Conditions")]
public string Backslashes;
7.FolderPath还支持使用$符号的成员引用和属性表达式。
// FolderPath还支持使用$符号的成员引用和属性表达式。
[FolderPath(ParentFolder = "$DynamicParent")]
[BoxGroup("Member referencing")]
public string DynamicFolderPath;
[BoxGroup("Member referencing")]
public string DynamicParent = "Assets/Plugins/Sirenix";
8.FolderPath还支持列表和数组。
// FolderPath还支持列表和数组。
[FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]
[BoxGroup("Lists")]
public string[] ListOfFolders;
完整示例脚本
using Sirenix.OdinInspector;
using UnityEngine;
public class FolderPathAttributeExample : MonoBehaviour
{
// 默认情况下,FolderPath提供了一个相对于Unity项目的路径。
[FolderPath]
public string UnityProjectPath;
// 可以提供自定义父路径。父路径可以是相对于Unity项目的,也可以是绝对的。
[FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]
public string RelativeToParentPath;
// 使用父路径,FolderPath还可以提供相对于resources文件夹的路径。
[FolderPath(ParentFolder = "Assets/Resources")]
public string ResourcePath;
// 通过将AbsolutePath设置为true, FolderPath将提供一个绝对路径。
[FolderPath(AbsolutePath = true)]
[BoxGroup("Conditions")]
public string AbsolutePath;
// 如果提供的路径无效,还可以将FolderPath配置为显示错误。
[FolderPath(RequireExistingPath = true)]
[BoxGroup("Conditions")]
public string ExistingPath;
// 默认情况下,FolderPath将强制使用前斜杠。还可以将其配置为使用反斜杠。
[FolderPath(UseBackslashes = true)]
[BoxGroup("Conditions")]
public string Backslashes;
// FolderPath还支持使用$符号的成员引用和属性表达式。
[FolderPath(ParentFolder = "$DynamicParent")]
[BoxGroup("Member referencing")]
public string DynamicFolderPath;
[BoxGroup("Member referencing")]
public string DynamicParent = "Assets/Plugins/Sirenix";
// FolderPath还支持列表和数组。
[FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]
[BoxGroup("Lists")]
public string[] ListOfFolders;
}