自定义Hierarchy中的对象排序——BaseHierarchySort

作者:追风剑情 发布于:2017-12-29 13:58 分类:Unity3d

开启Hierarchy排序(Edit->preferences->General)

勾上Enable Alpha Numeric Sorting

3333333.png

示例(必须放在Editor文件夹下)

using UnityEngine;
using UnityEditor;
using System.Collections;
/// <summary>
/// 自定义Hierarchy中的对象排序
/// </summary>
public class MyAlphaNumericSort : BaseHierarchySort
{
    private const string kDefaultSorting = "AlphabeticalSorting";
    private GUIContent m_Content = new GUIContent(EditorGUIUtility.FindTexture("AlphabeticalSorting"), "Alphabetical Order");

    public override GUIContent content
    {
        get {
            return this.m_Content;
        }
    }

    public override int Compare(GameObject lhs, GameObject rhs)
    {
        if (lhs == rhs) return 0;
        if (lhs == null) return -1;
        if (rhs == null) return 1;
        return EditorUtility.NaturalCompare(lhs.name, rhs.name);
    }
}

说明

AlphabeticalSort、TransformSort为Unity内置排序规则。MyAlphaNumericSort为自定义的排序规则

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号