【Unity】Hierarchy面板排序

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

命名空间的引用:

using UnityEngine;
using UnityEditor;

放在Editor文件夹下即可

【Unity】Hierarchy面板排序_第1张图片

按字母升序排列
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);

    }

}

按字母降序排列
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( "升序"); }

    }

}

你可能感兴趣的:(Unity3D,Unity,小技巧)