博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Odin Inspector 系列教程 --- Folder Path Attribute
阅读量:4147 次
发布时间:2019-05-25

本文共 2888 字,大约阅读时间需要 9 分钟。

File Path Attribute特性:用于字符串字段,并为目录路径提供接口。

7643202-f2cd7786c712a715.gif
【FolderPath】 默认情况下,FolderPath提供了一个相对于Unity项目的路径。
7643202-a9b4c1d608fed29e.gif
// 默认情况下,FolderPath提供了一个相对于Unity项目的路径。    [FolderPath]    public string UnityProjectPath;
【ParentFolder】可以提供自定义父路径。父路径可以是相对于Unity项目的,也可以是绝对的。
7643202-5c5a7a790be66cfe.gif
// 可以提供自定义父路径。父路径可以是相对于Unity项目的,也可以是绝对的。    [FolderPath(ParentFolder = "Assets/Plugins/Sirenix")]    public string RelativeToParentPath;
【ParentFolder】使用父路径,FolderPath还可以提供相对于resources文件夹的路径。
7643202-f1a5e462ea7d40a4.gif
// 使用父路径,FolderPath还可以提供相对于resources文件夹的路径。    [FolderPath(ParentFolder = "Assets/Resources")]    public string ResourcePath;
【AbsolutePath】通过将AbsolutePath设置为true, FolderPath将提供一个绝对路径。
7643202-20368ad633015dbc.gif
// 通过将AbsolutePath设置为true, FolderPath将提供一个绝对路径。    [FolderPath(AbsolutePath = true)]    [BoxGroup("Conditions")]    public string AbsolutePath;
【RequireExistingPath】如果提供的路径无效,还可以将FolderPath配置为显示错误。
7643202-42ce7e9a7db869d5.gif
// 如果提供的路径无效,还可以将FolderPath配置为显示错误。    [FolderPath(RequireExistingPath = true)]    [BoxGroup("Conditions")]    public string ExistingPath;
【UseBackslashes】默认情况下,FolderPath将强制使用前斜杠。还可以将其配置为使用反斜杠。
7643202-867795769453b6da.gif
// 默认情况下,FolderPath将强制使用前斜杠。还可以将其配置为使用反斜杠。    [FolderPath(UseBackslashes = true)]    [BoxGroup("Conditions")]    public string Backslashes;
FolderPath还支持使用$符号的成员引用和属性表达式。
7643202-9a50c00f1c4fa89b.gif
// FolderPath还支持使用$符号的成员引用和属性表达式。    [FolderPath(ParentFolder = "$DynamicParent")]    [BoxGroup("Member referencing")]    public string DynamicFolderPath;    [BoxGroup("Member referencing")]    public string DynamicParent = "Assets/Plugins/Sirenix";
FolderPath还支持列表和数组。
7643202-f8390619acc25a5e.gif
// 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;}

更多教程内容详见:

转载地址:http://jijti.baihongyu.com/

你可能感兴趣的文章
一篇搞懂Java反射机制
查看>>
Single Number II --出现一次的数(重)
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
对话周鸿袆:从程序员创业谈起
查看>>
Mysql中下划线问题
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>
初始化VUE项目报错
查看>>
vue项目使用安装sass
查看>>