Unity-Reorderable-List 项目教程

Unity-Reorderable-List 项目教程

Unity-Reorderable-ListExtended version of the Reorderable List in Unity项目地址:https://gitcode.com/gh_mirrors/un/Unity-Reorderable-List

1. 项目的目录结构及介绍

Unity-Reorderable-List 项目的目录结构如下:

Unity-Reorderable-List/
├── Assets/
│   ├── Editor/
│   │   ├── ReorderableList.cs
│   │   └── ReorderableListEditor.cs
│   └── Sample/
│       ├── Sample.cs
│       └── SampleInspector.cs
├── README.md
└── LICENSE

目录结构介绍

  • Assets/: 包含项目的主要资源文件。
    • Editor/: 包含用于编辑器扩展的脚本。
      • ReorderableList.cs: 实现可重排序列表的核心功能。
      • ReorderableListEditor.cs: 用于自定义编辑器界面。
    • Sample/: 包含示例脚本。
      • Sample.cs: 示例脚本,展示如何在 MonoBehaviour 中使用可重排序列表。
      • SampleInspector.cs: 自定义 Inspector 界面,用于展示可重排序列表。
  • README.md: 项目说明文档。
  • LICENSE: 项目许可证文件。

2. 项目的启动文件介绍

项目的启动文件是 Sample.cs,它位于 Assets/Sample/ 目录下。

Sample.cs 文件介绍

using UnityEngine;

public class Sample : MonoBehaviour
{
    public string[] texts = new string[2];
}
  • Sample.cs: 这是一个简单的 MonoBehaviour 脚本,包含一个字符串数组 texts。这个数组将在 Inspector 界面中使用可重排序列表进行展示。

3. 项目的配置文件介绍

项目的配置文件主要是 ReorderableList.csReorderableListEditor.cs,它们位于 Assets/Editor/ 目录下。

ReorderableList.cs 文件介绍

using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

public class ReorderableList
{
    // 实现可重排序列表的核心功能
}
  • ReorderableList.cs: 这个文件包含了实现可重排序列表的核心功能。它使用 UnityEditorInternal 命名空间中的类来实现列表元素的拖拽和重新排序。

ReorderableListEditor.cs 文件介绍

using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Sample))]
public class SampleInspector : Editor
{
    private ReorderableList list = null;

    public override void OnInspectorGUI()
    {
        if (list == null)
        {
            list = new ReorderableList(serializedObject, serializedObject.FindProperty("texts"));
        }

        list.DoLayoutList();
    }
}
  • ReorderableListEditor.cs: 这个文件用于自定义 Inspector 界面。它定义了一个 SampleInspector 类,继承自 Editor,并在 OnInspectorGUI 方法中使用 ReorderableList 来展示 Sample 脚本中的 texts 数组。

通过以上介绍,您可以了解 Unity-Reorderable-List 项目的基本结构、启动文件和配置文件。希望这份教程对您有所帮助。

Unity-Reorderable-ListExtended version of the Reorderable List in Unity项目地址:https://gitcode.com/gh_mirrors/un/Unity-Reorderable-List

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伏佳励Sibyl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值