Unity自定义Inspector属性面板

有时候,为了改善Unity的工作流程,我们会在Unity Editor下对界面进行二次开发或者做一些方便使用的扩展工具。今天讲的内容就是自定义Inspector属性面板。

在这里,我会通过最小单元的代码来实现自定义的Inspector。更高级的扩展需自行查阅。

 

实现自定义Inspector的流程

1、  继承命名空间UnityEditor下的Editor基类。

2、  添加[CustomEditor(typeof(XXX))]注解,告诉编辑器这个类是扩展哪个组件的Inspector。

3、  重写OnInspectorGUI方法,自定义重绘内容。

 

初始Inspector显示

代码:

using System.Collections; using System.Collections.Generic; using UnityEngine; public class LevelScript : MonoBehaviour { public int experience; public int Level { get { return experience / 750; } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyfzxj.html