当前位置:网站首页>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
边栏推荐
- 囍楽cloud task source code
- 1046 punches (15 points)
- 【云原生】云原生在网络安全领域的应用
- 4.1 - Support Vector Machines
- AcWing 272. 最长公共上升子序列
- Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
- IQUNIX A80 exploring TTC金粉 初体验
- 1036 跟奥巴马一起编程 (15 分)
- 进阶-指针
- Four operations in TF
猜你喜欢
oracle数据库中列转行,列会有变化
2.1-梯度下降
Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
The easiest trick to support quick renaming of various files
[Recommender System]: Overview of Collaborative Filtering and Content-Based Filtering
9、Neural Sparse Voxel Fields
1046 划拳 (15 分)
Machine Learning Summary (2)
Project 1 - PM2.5 Forecast
关于#sql#的问题:怎么将下面的数据按逗号分隔成多行,以列的形式展示出来
随机推荐
8、Mip-NeRF
优炫数据库支持多列分区吗?
Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
少年成就黑客,需要这些技能
支持各种文件快速重命名最简单的小技巧
2.1-梯度下降
美术2.4 UV原理基础
Dynamic Agent Learning
场地预订系统,帮助场馆提高坪效
高德能力API
选择收银系统主要看哪些方面?
动态代理学习
Machine Learning Summary (2)
如何通过开源数据库管理工具 DBeaver 连接 TDengine
Write a resume like this, easy to get the interviewer
项目2-年收入判断
Serverless + domain name can also build a personal blog? Really, and soon
1002 Write the number (20 points)
Do you know the basic process and use case design method of interface testing?
The most complete documentation on Excel's implementation of grouped summation