当前位置:网站首页>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
边栏推荐
- Two startup methods and differences of Service
- 租房小程序
- 迷你图书馆系统(对象+数组)
- 机器学习(二)线性回归
- 选择收银系统主要看哪些方面?
- Redis source code-String: Redis String command, Redis String storage principle, three encoding types of Redis string, Redis String SDS source code analysis, Redis String application scenarios
- matrix multiplication in tf
- 项目1-PM2.5预测
- 2022 China Soft Drink Market Insights
- opengauss创建用户权限问题
猜你喜欢
支持各种文件快速重命名最简单的小技巧
机器学习(一)数据的预处理
小目标检测3_注意力机制_Self-Attention
3.1-Classification-probabilistic generative model
研发了 5 年的时序数据库,到底要解决什么问题?
关于Excel实现分组求和最全文档
My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
1101 How many times B is A (15 points)
1071 Small Gamble (15 points)
初级软件测试工程师笔试试题,你知道答案吗?
随机推荐
Creo9.0 特征的成组
查找最新人员工资和上上次人员工资的变动情况
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
1071 Small Gamble (15 points)
About # SQL problem: how to set the following data by commas into multiple lines, in the form of column display
opengauss创建用户权限问题
1081 Check Password (15 points)
欧拉函数(用欧拉筛法求欧拉函数)
Keep track of your monthly income and expenses through bookkeeping
进阶-指针
支持各种文件快速重命名最简单的小技巧
笔试题大疆08.07
流式结构化数据计算语言的进化与新选择
The most complete documentation on Excel's implementation of grouped summation
机器学习(一)数据的预处理
There may be fields that cannot be serialized in the abnormal object of cdc and sqlserver. Is there anyone who can understand it? Help me to answer
oracle数据库中列转行,列会有变化
研发了 5 年的时序数据库,到底要解决什么问题?
为什么会没有内存了呢
Mysql JSON对象和JSON数组查询