File Path Attribute特性:用于字符串字段,并為目錄路徑提供接口。
【FolderPath】 默認情況下,FolderPath提供了一個相對于Unity項目的路徑。
// 默認情況下,FolderPath提供了一個相對于Unity項目的路徑。
[FolderPath]
public string UnityProjectPath;
【ParentFolder】可以提供自定義父路徑。父路徑可以是相對于Unity項目的,也可以是絕對的。
// 可以提供自定義父路徑。父路徑可以是相對于Unity項目的,也可以是絕對的。
[FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]
public string RelativeToParentPath;
【ParentFolder】使用父路徑,FolderPath還可以提供相對于resources文件夾的路徑。
// 使用父路徑,FolderPath還可以提供相對于resources文件夾的路徑。
[FolderPath(ParentFolder = "Assets/Resources")]
public string ResourcePath;
【AbsolutePath】通過將AbsolutePath設置為true, FolderPath將提供一個絕對路徑。
// 通過將AbsolutePath設置為true, FolderPath將提供一個絕對路徑。
[FolderPath(AbsolutePath = true)]
[BoxGroup("Conditions")]
public string AbsolutePath;
【RequireExistingPath】如果提供的路徑無效,還可以將FolderPath配置為顯示錯誤。
// 如果提供的路徑無效,還可以將FolderPath配置為顯示錯誤。
[FolderPath(RequireExistingPath = true)]
[BoxGroup("Conditions")]
public string ExistingPath;
【UseBackslashes】默認情況下,FolderPath將強制使用前斜杠。還可以將其配置為使用反斜杠。
// 默認情況下,FolderPath將強制使用前斜杠。還可以將其配置為使用反斜杠。
[FolderPath(UseBackslashes = true)]
[BoxGroup("Conditions")]
public string Backslashes;
FolderPath還支持使用$符號的成員引用和屬性表達式。
// FolderPath還支持使用$符號的成員引用和屬性表達式。
[FolderPath(ParentFolder = "$DynamicParent")]
[BoxGroup("Member referencing")]
public string DynamicFolderPath;
[BoxGroup("Member referencing")]
public string DynamicParent = "Assets/Plugins/Sirenix";
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;
}