当前位置:网站首页>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:69. x 的平方根
Keep track of your monthly income and expenses through bookkeeping
TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
关于#sql#的问题:怎么将下面的数据按逗号分隔成多行,以列的形式展示出来
2022 China Soft Drink Market Insights
Unity3D——自定义类的Inspector面板的修改
1.1-Regression
对比学习系列(三)-----SimCLR
美术2.4 UV原理基础
tf.reduce_mean() and tf.reduce_sum()
随机推荐
IQUNIX A80 exploring TTC金粉 初体验
【LeetCode】链表题解汇总
《剑指offer》题解——week3(持续更新)
kali渗透测试环境搭建
Kotlin算法入门求回文数数算法优化二数字生成规则
Mysql JSON对象和JSON数组查询
go sqlx 包
基于微信小程序的租房小程序
迷你图书馆系统(对象+数组)
Getting Started with Kotlin Algorithms Calculating Prime Factors
如何通过 IDEA 数据库管理工具连接 TDengine?
1106 2019 Sequence (15 points)
pyqt5实现仪表盘
【BM87 合并两个有序的数组】
JUC Concurrent Programming
借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
数据库无法启动,报无法分配内存,怎么处理
一根网线两台电脑传输文件
Alibaba Sentinel - Slot chain解析
场地预订系统,帮助场馆提高坪效