当前位置:网站首页>Unity3D——自定义类的Inspector面板的修改
Unity3D——自定义类的Inspector面板的修改
2022-08-11 08:04:00 【索利亚噶通】
Unity3D——自定义类的Inspector面板的修改
- 预期目标: 对自定义类的Inspector面板进行修改,达到如下效果

- 步骤
(1)创建自己的脚本(例如Help.cs),置于Assets / Scripts目录(非必须)下
(2)创建与其对应的脚本(HelpInspector.cs), 置于 Assets / Editor 目录(没有可自行创建)下
(3)在SudentInspector.cs中
- 引用UnityEditor命名空间
- 添加特性[CutomEditor(typeof(Help))]
- 继承Editor类
- 重写OnInspectorGUI类
注意:这里重写OnInspectorGUI方法时,编译器自带调用父类中的OnInspectorGUI,这里如果不想要Help类中的不需要的public变量出现在Inspector面板上,就将base.OnInspectorGUI()注释掉
代码
// SudentInspector.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Help))]
public class HelpInspector : Editor
{
public override void OnInspectorGUI()
{
Help myHelp = (Help)target; // target就是Help Inspector的实例
GUILayout.BeginVertical();
GUILayout.Label("Help Here");
GUILayout.Label("Version: 1.0.0");
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Test Input", GUILayout.Width(60));
myHelp.helpId = EditorGUILayout.IntField( myHelp.helpId,GUILayout.Width(150));
GUILayout.EndHorizontal();
GUILayout.BeginVertical();
myHelp.helpName = EditorGUILayout.TextField(myHelp.helpName, GUILayout.Width(150));
GUILayout.EndVertical();
}
}
// Help.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Help : MonoBehaviour
{
public bool helpHere;
public int helpId;
public string helpName;
}
功能
- 注意
- 这里的target就是指Help创建出来的Help实例(面板),如果想要控制Help中的变量,不能再创建新的实例,因为我们是去操控面板上这个已经创建出来的实例,也就是target
边栏推荐
- 兼容并蓄广纳百川,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang复合容器类型的声明和使用EP04
- 1036 Programming with Obama (15 points)
- 数据库无法启动,报无法分配内存,怎么处理
- redis operation
- Kaldi语音识别工具编译问题记录(踩坑记录)
- 1.2 - error sources
- 【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
- 2022-08-10 mysql/stonedb-slow SQL-Q16-time-consuming tracking
- 麒麟V10系统打包Qt免安装包程序
- 机器学习(二)线性回归
猜你喜欢
初级软件测试工程师笔试试题,你知道答案吗?

项目2-年收入判断

如何通过 IDEA 数据库管理工具连接 TDengine?

tf.cast(), reduce_min(), reduce_max()
1.1-回归

分布式锁-Redission - 缓存一致性解决

Creo9.0 特征的成组

About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display

matrix multiplication in tf

研发了 5 年的时序数据库,到底要解决什么问题?
随机推荐
matrix multiplication in tf
Do you know the basic process and use case design method of interface testing?
高德能力API
IQUNIX A80 exploring TTC金粉 初体验
囍楽cloud task source code
分布式锁-Redission - 缓存一致性解决
leetcode: 69. Square root of x
oracle19c does not support real-time synchronization parameters, do you guys have any good solutions?
1106 2019 Sequence (15 points)
leetcode:69. x 的平方根
C Primer Plus(6) 中文版 第1章 初识C语言 1.6 语言标准
测试用例很难?有手就行
Swagger简单使用
go-grpc TSL authentication solution transport: authentication handshake failed: x509 certificate relies on ... ...
3.1-分类-概率生成模型
【415. 字符串相加】
欧拉函数(用欧拉筛法求欧拉函数)
老干妈创始人陶华碧现身直播间,70岁“国民女神”拥抱直播电商
场地预订系统,帮助场馆提高坪效
AcWing 272. 最长公共上升子序列