当前位置:网站首页>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
边栏推荐
猜你喜欢
软件测试常用工具的用途及优缺点比较(详细)
2022-08-10:为了给刷题的同学一些奖励,力扣团队引入了一个弹簧游戏机, 游戏机由 N 个特殊弹簧排成一排,编号为 0 到 N-1, 初始有一个小球在编号 0 的弹簧处。若小球在编号为 i 的弹
1106 2019 Sequence (15 points)
oracle数据库中列转行,列会有变化
1.1-Regression
Conditional statements in TF; where()
XXL-JOB 分布式任务调度中心搭建
tf.reduce_mean() and tf.reduce_sum()
One-hot in TF
囍楽cloud task source code
随机推荐
4.1ROS运行管理/launch文件
Kotlin算法入门计算水仙花数
链式编程注解
TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
One-hot in TF
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
如何通过开源数据库管理工具 DBeaver 连接 TDengine
1076 Wifi Password (15 points)
【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
Kotlin算法入门求回文数算法优化一
The easiest trick to support quick renaming of various files
magical_spider远程采集方案
1003 I want to pass (20 points)
软件测试常用工具的用途及优缺点比较(详细)
Kotlin算法入门求完全数
2021-08-11 For loop combined with multi-threaded asynchronous query and collect results
2022 China Soft Drink Market Insights
1106 2019 Sequence (15 points)
零基础SQL教程: 主键、外键和索引 04
【实战系列】OpenApi设计规范