不影响Inspector布局拓展类
DecoratorEditor.cs
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine; /// <summary>
/// A base class for creating editors that decorate Unity's built-in editor types.
/// </summary>
public abstract class DecoratorEditor : Editor
{
// empty array for invoking methods using reflection
private static readonly object[] EMPTY_ARRAY = new object[]; #region Editor Fields /// <summary>
/// Type object for the internally used (decorated) editor.
/// </summary>
private System.Type decoratedEditorType; /// <summary>
/// Type object for the object that is edited by this editor.
/// </summary>
private System.Type editedObjectType; private Editor editorInstance; #endregion private Dictionary<string, MethodInfo> decoratedMethods = new Dictionary<string, MethodInfo>(); private static Assembly editorAssembly = Assembly.GetAssembly(typeof(Editor)); protected Editor EditorInstance
{
get
{
if (editorInstance == null && targets != null && targets.Length > )
{
editorInstance = Editor.CreateEditor(targets, decoratedEditorType);
} if (editorInstance == null)
{
Debug.LogError("Could not create editor !");
} return editorInstance;
}
} public DecoratorEditor (string editorTypeName)
{
this.decoratedEditorType = editorAssembly.GetTypes().Where(t => t.Name == editorTypeName).FirstOrDefault(); /*System.Type[] types = editorAssembly.GetTypes();
for (int i=0; i<types.Length; i++)
{
string name=types[i].Name;
if(name.IndexOf("Collider")>-1)Debug.Log(name);
}*/ Init (); // Check CustomEditor types.
/*var originalEditedType = GetCustomEditorType(decoratedEditorType);
Debug.Log(originalEditedType);
if (originalEditedType != editedObjectType)
{
throw new System.ArgumentException(
string.Format("Type {0} does not match the editor {1} type {2}",
editedObjectType, editorTypeName, originalEditedType));
}*/
} private System.Type GetCustomEditorType(System.Type type)
{
var flags = BindingFlags.NonPublic | BindingFlags.Instance; var attributes = type.GetCustomAttributes(typeof(CustomEditor), true) as CustomEditor[];
var field = attributes.Select(editor => editor.GetType().GetField("m_InspectedType", flags)).First(); return field.GetValue(attributes[]) as System.Type;
} private void Init()
{
var flags = BindingFlags.NonPublic | BindingFlags.Instance; var attributes = this.GetType().GetCustomAttributes(typeof(CustomEditor), true) as CustomEditor[];
var field = attributes.Select(editor => editor.GetType().GetField("m_InspectedType", flags)).First(); editedObjectType = field.GetValue(attributes[]) as System.Type;
} void OnDisable()
{
if (editorInstance != null)
{
DestroyImmediate(editorInstance);
}
} /// <summary>
/// Delegates a method call with the given name to the decorated editor instance.
/// </summary>
protected void CallInspectorMethod(string methodName)
{
MethodInfo method = null; // Add MethodInfo to cache
if (!decoratedMethods.ContainsKey(methodName))
{
var flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public; method = decoratedEditorType.GetMethod(methodName, flags); if (method != null)
{
decoratedMethods[methodName] = method;
}
else
{
Debug.LogError(string.Format("Could not find method {0}", method));
}
}
else
{
method = decoratedMethods[methodName];
} if (method != null)
{
method.Invoke(EditorInstance, EMPTY_ARRAY);
}
} public void OnSceneGUI()
{
CallInspectorMethod("OnSceneGUI");
} protected override void OnHeaderGUI ()
{
CallInspectorMethod("OnHeaderGUI");
} public override void OnInspectorGUI ()
{
EditorInstance.OnInspectorGUI();
} public override void DrawPreview (Rect previewArea)
{
EditorInstance.DrawPreview (previewArea);
} public override string GetInfoString ()
{
return EditorInstance.GetInfoString ();
} public override GUIContent GetPreviewTitle ()
{
return EditorInstance.GetPreviewTitle();
} public override bool HasPreviewGUI ()
{
return EditorInstance.HasPreviewGUI ();
} public override void OnInteractivePreviewGUI (Rect r, GUIStyle background)
{
EditorInstance.OnInteractivePreviewGUI (r, background);
} public override void OnPreviewGUI (Rect r, GUIStyle background)
{
EditorInstance.OnPreviewGUI (r, background);
} public override void OnPreviewSettings ()
{
EditorInstance.OnPreviewSettings ();
} //5.x才有以下方法
/*public override void ReloadPreviewInstances ()
{
EditorInstance.ReloadPreviewInstances ();
}*/ public override Texture2D RenderStaticPreview (string assetPath, Object[] subAssets, int width, int height)
{
return EditorInstance.RenderStaticPreview (assetPath, subAssets, width, height);
} public override bool RequiresConstantRepaint ()
{
return EditorInstance.RequiresConstantRepaint ();
} public override bool UseDefaultMargins ()
{
return EditorInstance.UseDefaultMargins ();
}
}
不影响Inspector布局拓展类的更多相关文章
- Unity3D研究院编辑器之不影响原有布局拓展Inspector
今天无意间发现了一篇好文章,也让我解决了一个很久都没解决的难题.问题是这样的,假如我想去拓展Unity自带的inspector但是并不想影响原有布局. 比如下面这段代码: 1 2 3 4 5 ...
- spring源码分析系列 (5) spring BeanFactoryPostProcessor拓展类PropertyPlaceholderConfigurer、PropertySourcesPlaceholderConfigurer解析
更多文章点击--spring源码分析系列 主要分析内容: 1.拓展类简述: 拓展类使用demo和自定义替换符号 2.继承图UML解析和源码分析 (源码基于spring 5.1.3.RELEASE分析) ...
- three.js入门系列之导入拓展类
先来看一下three.js包的目录结构: 我们使用的时候,可以一次性import所有的功能,也可以按需引入,全依赖three.module.js这个文件对three.js的功能作了模块化处理: 但是, ...
- 一个CookieContainer的拓展类
最近项目中需要频繁用到服务器返回的Cookie,由于项目采用的是HttpClient,并且用CookieContainer自动托管Cookie,在获取Cookie的时候不太方便.所以就写了个拓展类. ...
- CSS-弹性布局-伪类选择器-复杂选择器
1.定位 1.堆叠顺序 一旦将元素变为已定位元素的话,元素们则有可能出现堆叠的效果. 如何改变堆叠顺序? 属性:z-index 取值:无单位的数字,数字越大越靠上. 注意: 1.父子元素间,z-ind ...
- css3 flex流动自适应响应式布局样式类
1.再说css3 flex 一旦一个容器赋予了display:flex属性,将会有以下特点: 项目无法设置浮动. 列表的样式会被清除. 无法使用vertical-align设置垂直对齐方式. 目前互联 ...
- IOS不用AutoLayout也能实现自己主动布局的类(3)----MyRelativeLayout横空出世
对于IOS开发人员来说,在自己主动布局出现前仅仅能通过计算和设置frame的值来处理.这样设置位置时就会出现非常多硬编码,同一时候在屏幕旋转和不同屏幕之间适配时须要编码又一次调整位置和尺寸,我们也能够 ...
- Android之布局Application类
转载:https://blog.csdn.net/pi9nc/article/details/11200969 一 Application源码描述 * Base class for maintaini ...
- Flutter 容器Container类和布局Layout类
1.布局和容器 [布局]是把[容器]按照不同的方式排列起来. Scaffold包含的主要部门:appBar,body,bottomNavigator 其中body可以是一个布局组件,也可以是一个容器组 ...
随机推荐
- JavaScript模块化-RequireJs实现AMD规范的简单例子
AMD规范简介 AMD(异步模块定义),是实现JavaScript模块化规范之一,它采用异步方式加载模块,模块的加载不影响后面语句的运行.require.js和curl.js都是实现AMD规范的优秀加 ...
- BASIC-1_蓝桥杯_闰年判断
正确代码: #include <stdio.h> int main(void){ int year = 0 ; scanf("%d",&year); if (y ...
- [转] oracle 数据库 SQL plus 连接方法
http://hi.baidu.com/zzy382/item/a5b197f97a38e01ba7298832 之前电脑上安装了一个 Oracle 有一段时间没用,就把密码给忘了,按上面链接里的操 ...
- 用linux的iconv函数 转换编码
inux shell 配置文件中默认的字符集编码为UTF-8 .UTF-8是unicode的一种表达方式,gb2312是和unicode都是字符的编码方式,所以说gb2312跟utf-8的概念应该不是 ...
- Python软件开发规范
bin 整个程序的执行路口 start.py conf 配置文件 setting.py lib 库 模块与包 common.py sql.py core 核心逻辑 ...
- php trim() 函数实例讲解
php trim() 函数移除字符串两侧的空白字符或其他预定义字符,本文章向码农介绍php trim() 函数的使用方法和实例,感兴趣的码农可以参考一下. 定义和用法 trim() 函数移除字符串两侧 ...
- 发送短信验证码及调用短信接口与C# 后台 post 发送
#region 调用短信接口 public ActionResult Mobile(string Tel)//调用接口 { Random rm = new Random(); int i; strin ...
- python pip使用报错:Fatal error in launcher: Unable to create process using '"'
在一个系统中共存Python2.python3的时候,pip.pip2.pip3使用的时候会报错: c:\Python35\Scripts>pip3Fatal error in launcher ...
- 序列化模块json--pickle--shelve
什么是序列化? 将一组或多组数据结构转化成一个字符串的过程就叫做序列化 它的目的: 序列化的结构是字符串,准确的说是bytes类型,方便存储 方便于网络传输, 既然序列化是从数据类型到字符串的过程,那 ...
- DevExpress 数据与展示的不同
有时候我们需要详细展示数据源的含义,这时候就需要用到 RepositoryItemLookUpEdit 展示: 代码详情: ColumnData = new DevExpress.XtraGrid.C ...