扩展Unity Inspector】的更多相关文章

Unity Editor下,可以在不改变原有布局的情况下扩展Inspect的界面. 在继承了Editor的类中,有两种实现方式: using UnityEditor; [CustomEditor(typeof(CustomClass))] public class CustomClassEditor : Editor { public override void OnInspectorGUI() { // 自定义代码 base.OnInspectorGUI(); // 自定义代码 } } 和 u…
在扩展Unity的时候,往往会用到一些属性,这里将常用的列一下. 1.属性只读: #if UNITY_EDITOR using UnityEditor; #endif using UnityEngine; public class ReadOnlyAttribute : PropertyAttribute { } #if UNITY_EDITOR [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] public class ReadOnlyDraw…
写更少代码的需求 当我们重复写一些繁杂的代码,或C#的一些方法,我们就想能不能有更便捷的方法呢?当然在unity中,我们对它进行扩展. 对unity的类或C#的类进行扩展有以下两点要注意: 1.这个类必须声明为static,扩展的方法也必须要声明为static 2.在使用时,就可以直接调用扩展的方法 扩展Unity的属性 Demo using UnityEngine; using System.Collections; //It is common to create a class to co…
在Unity开发游戏的时候,为了有一个更快更方便的工作流,我们往往会在Editor下开发一些方便实用的工具.在工具中,用到最多,最关键的就是按钮,它是工具的首席执行官.下面就用最简单的代码来演示添加一个自定义按钮到Inspector当中. 案例:指定坐标后克隆新物体到场景.  1.  在Unity Assets下创建”ObjectBuilderScript”脚本,添加代码: using UnityEngine; public class ObjectBuilderScript : MonoBeh…
inspector中实现列表框: public override void OnInspectorGUI(){ bool isDoubleClick=false;        Event e = Event.current;        if (e.type == EventType.mouseDown && Event.current.button == 0) {//left button down            if(e.clickCount==2){//double cl…
通过声明的变量名称,主动关联引用. 使用这个关联引用两种方式1.  给你组件继承  MonoAutoQuote 点击组件inspector 按钮执行2.  给你组件类添加[AAutoQuote] 特性  通过Plateface/SetSelectGameRef 执行 [AAutoQuote] public class MonoAutoQuote : MonoBehaviour ,IAutoQuote{} public interface IAutoQuote { } public class A…
以前经常因为脚本中private变量不在inspector界面中显示,不方便观察其值的变化,所以本该用private的用了public. 今天发现,原来inspector有个选项,如图,平常勾选的是Normal,则inspector界面只显示public变量,如果改为勾选Debug,则private变量也会以灰字显示出来.…
在使用unity的过程中,经常遇到这样的问题:每次都需要手动为序列化属性拖拽赋值.像这样: 试着找了找,真的找到了一份代码,但是缺少自动装载Prefab的功能.之后我花了点时间添加这个功能. 使用方法: 1 [Autohook] 2 public Button SendBtn; 3 [Autohook] 4 public Button StartBtn; 5 [Autohook] 6 public Button LeaveBtn; 7 [Autohook] 8 public Text RoomD…
项目进入上线阶段了, 有一些地方需要总结和优化.  我发现UI一改变,我就要拖很久的UI. UI结构发生改变我还必须给一些变量设置好引用,后来我去看别人预设的时候组件拖放的变量至少10个以上, 它们一旦丢失了引用了, 作为一个外人就很难把他们关联起来.  预设就定义了m_xxx名字必须和GameObject名字一样, 这样就方便其他人帮你修复预设的引用啦. 今天就突然想起写一个辅助用具, 一键把一些简单的引用帮我赋值上去. 就再也不用手动拖啦. 代码如下: using UnityEngine;…
2个月前还在忙碌的找实习工作,看见招聘信息上面有一条熟悉扩展Unity编辑器,配合美工编程. 自己动手写完这个代码时候,发现写代码就像弹钢琴多么神奇. TestEdit类: using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor(typeof(Test))] public class TestEditor : Editor { void OnSceneGUI() { Test test = (Te…