unity编辑器扩展界面使用 List


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();


        }
    }

    /// 
    /// 修改图片
    /// 
    public void SetSprsite()
    {
        //修改图片逻辑

       
    }

    public void SetMedia()
    {
       //修改视频逻辑
           
       
    }
}

unity编辑器扩展界面使用 List_第1张图片

参考资料
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

你可能感兴趣的:(Unity,编辑器扩展,unity,编辑器,游戏引擎)