当前位置:网站首页>Unity3D - modification of the Inspector panel of the custom class
Unity3D - modification of the Inspector panel of the custom class
2022-08-11 08:13:00 【Solia Katong】
Unity3D——自定义类的InspectorModification of the panel
- 预期目标: for custom classesInspector面板进行修改,达到如下效果

- 步骤
(1)Create your own script(例如Help.cs),置于Assets / Scripts目录(非必须)下
(2)Create a script corresponding to it(HelpInspector.cs), 置于 Assets / Editor 目录(没有可自行创建)下
(3)在SudentInspector.cs中
- 引用UnityEditor命名空间
- 添加特性[CutomEditor(typeof(Help))]
- 继承Editor类
- 重写OnInspectorGUI类
注意:这里重写OnInspectorGUI方法时,The compiler comes with calls in the parent classOnInspectorGUI,Here if you don't want toHelpUnwanted in the classpublic变量出现在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中的变量,No more new instances can be created,Because we are going to control the instance that has been created on the panel,也就是target
边栏推荐
- 【LeetCode】Summary of linked list problems
- 零基础SQL教程: 基础查询 05
- 2022 China Soft Drink Market Insights
- JRS303-Data Verification
- Break pad source code compilation--refer to the summary of the big blogger
- magical_spider远程采集方案
- 【实战系列】OpenApi设计规范
- Project 1 - PM2.5 Forecast
- 【BM87 合并两个有序的数组】
- 4.1 - Support Vector Machines
猜你喜欢

excel 透视表 值显示内容 不显示计数

Write a resume like this, easy to get the interviewer

1096 big beautiful numbers (15 points)
3.1-Classification-probabilistic generative model

【LeetCode】链表题解汇总

如何通过开源数据库管理工具 DBeaver 连接 TDengine

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

C Primer Plus(6) 中文版 第1章 初识C语言 1.7 使用C语言的7个步骤

tf.reduce_mean() and tf.reduce_sum()

3.2 - classification - Logistic regression
随机推荐
Four operations in TF
Notable NFT development trends in 2022
Conditional statements in TF; where()
Linux,Redis中IOException: 远程主机强迫关闭了一个现有的连接。解决方法
C Primer Plus(6) 中文版 第1章 初识C语言 1.1 C语言的起源 1.2 选择C语言的理由 1.3 C语言的应用范围
经典论文-MobileNet V1论文及实践
TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
IDEA的初步使用
Essential C# scripting skills for Unity developers
3.1-Classification-probabilistic generative model
go 操作MySQL之mysql包
为什么会没有内存了呢
法律顾问成了律所鸡肋产品了吗?
2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
LoRa芯片的特征
JUC并发编程
初级软件测试工程师笔试试题,你知道答案吗?
一根网线两台电脑传输文件
2022-08-10 mysql/stonedb-slow SQL-Q16-time-consuming tracking
1.2 - error sources