更新了一下,支持数组和嵌套数据结构。

 using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Reflection; [CustomPropertyDrawer(typeof(ObjectToPathAttribute))]
public class ObjectToPathDrawer : PropertyDrawer
{ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Object target = property.serializedObject.targetObject;
ObjectToPathAttribute otpa = attribute as ObjectToPathAttribute;
System.Type objType = otpa._objType; string path = property.stringValue;
position.width = EditorGUIUtility.labelWidth * 2.0f / 3.0f; EditorGUI.LabelField(position, label);
position.x += EditorGUIUtility.labelWidth * 2.0f / 3.0f; Object _obj = null;
bool _foundObj = true;
if (!string.IsNullOrEmpty(path))
{
_obj = AssetDatabase.LoadMainAssetAtPath(path);
if (_obj == null)
{
_foundObj = false;
}
}
_obj = EditorGUI.ObjectField(position, _obj, objType, false);
if (_obj != null)
{
path = AssetDatabase.GetAssetPath(_obj);
}
else
{
if (_foundObj)
{
path = string.Empty;
}
}
position.x += EditorGUIUtility.labelWidth * 2.0f / 3.0f;
position.width = EditorGUIUtility.labelWidth;
property.stringValue = EditorGUI.TextField(position, path);
}
}

ObjectToPathDrawer

 using UnityEngine;
using System.Collections; public class ObjectToPathAttribute : PropertyAttribute
{
public System.Type _objType;
public ObjectToPathAttribute(System.Type t)
{
_objType = t;
}
}

ObjectToPathAttribute

 using UnityEngine;
using System.Collections; public class TestClass : MonoBehaviour
{
[ObjectToPath(typeof(GameObject))]
public string _prefabPath;
}

TestClass

使用上面的代码可以通过拖拽一个prefab的方式把相应的路径直接存储到public string _itemPerfabPath里,省去键盘输入步骤。不支持场景中的GameObject的拖入。

截图如下:

当prefab为空的时候的截图如下:

通过拖拽prefab来存储相应的路径的更多相关文章

  1. Dev GridView行拖拽

    http://blog.csdn.net/keyrainie/article/details/8513802 http://www.cnblogs.com/qq4004229/archive/2012 ...

  2. [Unity]背包效果-使用NGUI实现物品的拖拽效果Drag

    背包效果-使用NGUI实现物品的拖拽效果Drag 效果实现如图 对象层级关系图 PacketCell - Right 对象作为单元格背景 PacketContainer 对象作为单元格容器 Packe ...

  3. 快速开发 HTML5 WebGL 的 3D 斜面拖拽生成模型

    前言 3D 场景中的面不只有水平面这一个,空间是由无数个面组成的,所以我们有可能会在任意一个面上放置物体,而空间中的面如何确定呢?我们知道,空间中的面可以由一个点和一条法线组成.这个 Demo 左侧为 ...

  4. WPF拖拽文件(拖入拖出),监控拖拽到哪个位置,类似百度网盘拖拽

    1.往wpf中拖文件 // xaml <Grid x:Name="grid_11" DragOver="Grid_11_DragOver" Drop=&q ...

  5. HTML5 02. 多媒体控件、拖拽事件、历史记录、web存储、应用程序缓存、地理定位、网络状态

    多媒体 video:是行内块(text-align: center; 对行内块适用) <figure></figure>: 多媒体标签 : <figcaption> ...

  6. Web存储及文件拖拽

    存储 实现内容的永久保存(localStorage) 保存: localStorage.自定义键名="123"; 获取: //判断是否有内容 if(localStorage.自定义 ...

  7. 从零开始学 Web 之 HTML5(四)拖拽接口,Web存储,自定义播放器

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  8. Html5+NodeJS——拖拽多个文件上传到服务器

    实现多文件拖拽上传的简易Node项目,可以在github上下载,你可以先下载下来:https://github.com/Johnharvy/upLoadFiles/. 解开下载下的zip格式包,建议用 ...

  9. canvas 图片拖拽旋转之二——canvas状态保存(save和restore)

    引言 在上一篇日志“canvas 图片拖拽旋转之一”中,对坐标转换有了比较深入的了解,但是仅仅利用坐标转换实现的拖拽旋转,会改变canvas坐标系的状态,从而影响画布上其他元素的绘制.因此,这个时候需 ...

随机推荐

  1. flume 1.7 安装与使用

    Flume安装 系统要求: 需安装JDK 1.7及以上版本 1. 下载二进制包 下载页面:http://flume.apache.org/download.html 1.7.0下载地址:http:// ...

  2. [小问题笔记(十)] SQL Server 里 float 转 varchar等字符类型 不使用科学计数法

    需要转换两次, 试了一下 float 转 bigint 转 varchar 溢出了... 后来用  float 转 decimal(38,0) 转 varchar 就成功了~ ,)) )) 另吐槽一下 ...

  3. Svn Replacement For Git Stash

    svn 实现git stash类似的功能 % svn diff > WorkInProgress.txt % svn revert -R . <make changes> % svn ...

  4. 使用IDEA创建SpringBoot自定义注解

    创建SpringBoot项目 添加组织名 选择web 输入项目名称 创建后目录结构为 使用Spring的AOP先加入Maven依赖 <dependency> <groupId> ...

  5. 【转载】deque双向队列

    继vector和queue之后,又发现一个很好用的东西. 本篇转载自http://blog.csdn.net/morewindows/article/details/6946811 deque双向队列 ...

  6. 新旧版ubuntu镜像免费下载

    链接:https://pan.baidu.com/s/1hUNfiyA_Npj9QQ0vNLJ_Xw 密码:6k6i

  7. ansible入门六(roles)

    一.什么场景下会用roles? 假如我们现在有3个被管理主机,第一个要配置成httpd,第二个要配置成php服务器,第三个要配置成MySQL服务器.我们如何来定义playbook? 第一个play用到 ...

  8. scale的空白问题

    使用scale对表格进行缩放 出现大片空白问题 一直没有很好地重视这个问题,导致这次不得不面对,经过各种搜索,各种尝试,终于解决了这个留白问题 思路 大小盒子,小盒子进行缩放,大盒子依据缩放来进行动态 ...

  9. C# 设计模式巩固笔记 - 适配器模式

    前言 多读书.多学习 介绍-适配器模式 定义:适配器模式(Adapter Pattern)是作为两个不兼容的接口之间的桥梁.这种类型的设计模式属于结构型模式,它结合了两个独立接口的功能. 实现 这里有 ...

  10. web版源码管理软件SCM-Manager安装配置

    背景 一直使用 “VisualSvn Server” 作为源码管理工具,使用一段时间之后,使用场景遇到以下问题 添加用户必需登录到服务器. 一台服务器,只能安装一个 “VisualSvn Server ...