【Unity】Hierarchy面板排序

百般思念 提交于 2019-12-03 15:57:03

文章转载至:http://www.seven-fire.cn/archives/179

命名空间的引用:

using UnityEngine;
using UnityEditor;

放在Editor文件夹下即可


<span style="font-family:宋体;"><span style="color:#696969;">按字母</span>升序排列
public class AscendingSort : BaseHierarchySort {

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

    }

}</span>

按字母降序排列
public class DescendingSort : BaseHierarchySort {

    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( rhs.name , lhs.name);

    }

}
public class 升序排列 : BaseHierarchySort

{

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

    }

    public override GUIContent content {

        get { return new GUIContent( "升序"); }

    }

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!