Version 3.3.0.1

Odin has a dedicated attribute overview with examples

FilePathAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class FilePathAttribute : Attribute, _Attribute

FilePath is used on string properties, and provides an interface for file paths.

Inheritance
  • System.Object
  • System.Attribute
  • FilePathAttribute
Example

The following example demonstrates how FilePath is used.

public class FilePathExamples : MonoBehaviour
{
	// By default, FilePath provides a path relative to the Unity project.
	[FilePath]
	public string UnityProjectPath;

	// It is possible to provide custom parent path. Parent paths can be relative to the Unity project, or absolute.
	[FilePath(ParentFolder = "Assets/Plugins/Sirenix")]
	public string RelativeToParentPath;

	// Using parent path, FilePath can also provide a path relative to a resources folder.
	[FilePath(ParentFolder = "Assets/Resources")]
	public string ResourcePath;

	// Provide a comma seperated list of allowed extensions. Dots are optional.
	[FilePath(Extensions = "cs")]
	public string ScriptFiles;

	// By setting AbsolutePath to true, the FilePath will provide an absolute path instead.
	[FilePath(AbsolutePath = true)]
	[BoxGroup("Conditions")]
	public string AbsolutePath;

	// FilePath can also be configured to show an error, if the provided path is invalid.
	[FilePath(RequireValidPath = true)]
	public string ValidPath;

	// By default, FilePath will enforce the use of forward slashes. It can also be configured to use backslashes instead.
	[FilePath(UseBackslashes = true)]
	public string Backslashes;

	// FilePath also supports member references with the $ symbol.
	[FilePath(ParentFolder = "$DynamicParent", Extensions = "$DynamicExtensions")]
	public string DynamicFilePath;

	public string DynamicParent = "Assets/Plugin/Sirenix";

	public string DynamicExtensions = "cs, unity, jpg";
}

Constructors

FilePathAttribute()
public FilePathAttribute()

Fields

AbsolutePath
If true the FilePath will provide an absolute path, instead of a relative one.
public bool AbsolutePath
Extensions
Comma separated list of allowed file extensions. Dots are optional. Supports member referencing with $.
public string Extensions
IncludeFileExtension
If true the file path will include the file's extension.
public bool IncludeFileExtension
ParentFolder
ParentFolder provides an override for where the path is relative to. ParentFolder can be relative to the Unity project, or an absolute path. Supports member referencing with $.
public string ParentFolder
RequireExistingPath
If true an error will be displayed for non-existing paths.
public bool RequireExistingPath
UseBackslashes
By default FilePath enforces forward slashes. Set UseBackslashes to true if you want backslashes instead.
public bool UseBackslashes