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

 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. codeforces 1A - math - ceil

    2017-08-24 15:42:30 writer: pprp 感觉自己好菜啊,这个题都没有做的很好 题意很简单,用a * a 的地砖,将 n * m 的地板铺满,问最少需要多少个地砖? 一开始打算 ...

  2. openstack dpdk

    # ovs-vsctl showeef7cd95-0677-486c-b119-5d6ac8531c56 Manager "ptcp:6640:127.0.0.1" is_conn ...

  3. 蓄水池抽样算法 Reservoir Sampling

    2018-03-05 14:06:40 问题描述:给出一个数据流,这个数据流的长度很大或者未知.并且对该数据流中数据只能访问一次.请写出一个随机选择算法,使得数据流中所有数据被选中的概率相等. 问题求 ...

  4. SSM框架WebSocket配置

    1.StartFilter.java package cn.xydata.pharmacy.websocket; import java.io.IOException; import javax.se ...

  5. nyoj——弃九法

    A*B Problem 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 设计一个程序求出A*B,然后将其结果每一位相加得到C,如果C的位数大于等于2,继续将C的各位数 ...

  6. grub2 windows版安装

    一.BIOS方式,grub2安装 查看磁盘情况 E:\grub-2.02-for-windows>wmic diskdrive list brief Caption DeviceID Model ...

  7. Ansible 开发调试 之【模块调试】

    本地调试 需要安装jinja2 库 yum -y install python-jinja2 使用官方提供的测试脚本调试 git clone git://github.com/ansible/ansi ...

  8. 清华大学 pip 源

    pypi 镜像使用帮助 pypi 镜像每 5 分钟同步一次. 临时使用 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-pac ...

  9. js获取显示器、页面等高度 (转)

    网页可见区域宽:document.body.clientWidth网页可见区域高:document.body.clientHeight网页可见区域宽:document.body.offsetWidth ...

  10. bzoj1704

    题解: 贪心 枚举k 然后判断一下是否可行 代码: #include<bits/stdc++.h> using namespace std; ; int n,a[N],b[N],sum,c ...