当前位置:网站首页>unity编辑器扩展界面使用 List
unity编辑器扩展界面使用 List
2022-08-10 00:41:00 【王源骏】
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(TeachTool))]
public class TeachTool : EditorWindow
{
[MenuItem("ConfigTool/添加图片或者视频")]
public static void ConfigTool()
{
//创建面板
EditorWindow.GetWindow(typeof(TeachTool));
}
public UnityEngine.Object setting;
[SerializeField]
public List<Sprite> spriteLiset=new List<Sprite>();//图片的List
//序列化对象
protected SerializedObject _serializedObject;
protected SerializedObject _serializedObject2;
//序列化属性
protected SerializedProperty _assetLstProperty;
protected SerializedProperty _assetLstProperty2;
[SerializeField]
public List<UnityEngine.Object> MediaLiset = new List<UnityEngine.Object>();
public string tempFiled = "";
private void OnEnable()
{
}
private void OnGUI()
{
GUILayout.Label("面板", EditorStyles.boldLabel);
//配置文件 这个可以忽略 因为我写的这个工具是修改自己工程内配置文件的
setting = EditorGUILayout.ObjectField(setting, typeof(TeachPointSetting), true);
//输入框
tempFiled = EditorGUILayout.TextField("名字:", tempFiled);
//设置间距
EditorGUILayout.Space(20);
//初始化
_serializedObject = new SerializedObject(this);
//获取当前类中可序列化的属性
_assetLstProperty = _serializedObject.FindProperty("spriteLiset");
//更新
_serializedObject.Update();
//开始检查是否有修改
EditorGUI.BeginChangeCheck();
//显示属性,第二个参数必须为true 否者无法显示子节点即List内容
EditorGUILayout.PropertyField(_assetLstProperty, true);
//结束检查是否有修改
if (EditorGUI.EndChangeCheck())
{
_serializedObject.ApplyModifiedProperties();
}
//设置间距
EditorGUILayout.Space(10);
//添加按钮
if(GUILayout.Button("确认添加图片"))
{
SetSprsite();
}
//设置间距
EditorGUILayout.Space(20);
_serializedObject2 = new SerializedObject(this);
_assetLstProperty2 = _serializedObject2.FindProperty("MediaLiset");
//更新
_serializedObject2.Update();
//开始检查是否有修改
EditorGUI.BeginChangeCheck();
//显示属性,第二个参数必须为true 否者无法显示子节点即List内容
EditorGUILayout.PropertyField(_assetLstProperty2, true);
//结束检查是否有修改
if (EditorGUI.EndChangeCheck())
{
_serializedObject2.ApplyModifiedProperties();
}
//设置间距
EditorGUILayout.Space(10);
//添加按钮
if (GUILayout.Button("确认添加视频"))
{
SetMedia();
}
}
/// <summary>
/// 修改图片
/// </summary>
public void SetSprsite()
{
//修改图片逻辑
}
public void SetMedia()
{
//修改视频逻辑
}
}
参考资料
https://blog.csdn.net/w_mumu_q/article/details/107240127
https://blog.csdn.net/puppet_master/article/details/51012298
https://blog.csdn.net/qq_35361471/article/details/84713382
边栏推荐
- 这一次,话筒给你:向自由软件之父 Richard M. Stallman 提问啦!
- PEG derivative Biotin-PEG1-OH (cas: 95611-10-2, 2-biotinaminoethanol) advantage description
- -向量点积-
- 温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
- 商业模式及其 SubDAO 深入研究
- assert利用蚁剑登录
- DHCP——动态主机配置协议
- How to activate the payment function on WeChat official account?
- Biotin-Cy2 Conjugate, Biotin-Cy2 Conjugate_Cy2 Biotin Conjugate
- 20220809-PotPlayer如何设置默认字体色-设置默认字体色的方法
猜你喜欢
XSS详解及复现gallerycms字符长度限制短域名绕过
西安生物素-四聚乙二醇-酰胺-4苯酚 浅黄色半固态
03|流程控制
为什么字符串一旦创建就不可以改变?
【kali-密码攻击】(5.2.1)密码分析:Hash Identifier(哈希识别)
365天挑战LeetCode1000题——Day 052 逐步求和得到正数的最小值 贪心
小程序实现搜索功能续
ASEMI整流桥GBJ1010参数,GBJ1010规格,GBJ1010封装
Docker interview question 2--get the number of database connections and docker-compose
Pagoda measurement - building LightPicture open source map bed system
随机推荐
DALL·E-2是如何工作的以及部署自己的DALL·E模型
什么是持续测试?
有PEG-Biotin参与的(CAS:1778736-18-7)Biotin-PEG4-OH广泛用于分子靶点检测
防勒索病毒现状分析
-Chess game-
Solidity最强对手:MOVE语言及新公链崛起
Prometeus 2.31.0 新特性
即时通讯开发如何撸一个WebSocket服务器
3438. 数制转换
-red and black-
【毕业设计】 基于Stm32的家庭智能监控系统 - 单片机 图像识别 人体检测 AI
【ROS2原理10】Interface数据的规定
【CAS:41994-02-9 |Biotinyl tyramide】Biotinyl tyramide price
@PostConsturct注解作用及特点
Docker interview question 2--get the number of database connections and docker-compose
微信公众号如何开通支付功能?
CMake 编译运行dpdk项目程序
移动终端数据业务高安全通信方案研究
-Pickling peanuts-
头脑风暴:单词拆分