【Unity】Hierarchy面板排序

发表于2017-08-28
评论0 2.5k浏览

层级(Hierarchy)面板包括所有在当前游戏场景的GameObject,但有些人可能对Hierarchy面板排序可能不了解,为此下面就给大家详细介绍下。


命名空间的引用:

using UnityEngine;
using UnityEditor;

放在Editor文件夹下即可


  1. <span style=< span="">"font-family:宋体;"><span style=< span="">"color:#696969;">按字母升序排列  </span style=<></span style=<>
  2. public class AscendingSort : BaseHierarchySort {  
  3.   
  4.     public override int Compare( GameObject lhs , GameObject rhs) {  
  5.   
  6.         if (lhs == rhs) { return 0; }  
  7.   
  8.         if (lhs == null) { return -1; }  
  9.   
  10.         if (rhs == null) { return 1; }  
  11.   
  12.         return EditorUtility .NaturalCompare( lhs.name , rhs.name);  
  13.   
  14.     }  
  15.   
  16. }  

  1. 按字母降序排列  
  2. public class DescendingSort : BaseHierarchySort {  
  3.   
  4.     public override int Compare( GameObject lhs , GameObject rhs) {  
  5.   
  6.         if (lhs == rhs) { return 0; }  
  7.   
  8.         if (lhs == null) { return 1; }  
  9.   
  10.         if (rhs == null) { return -1; }  
  11.   
  12.         return EditorUtility .NaturalCompare( rhs.name , lhs.name);  
  13.   
  14.     }  
  15.   
  16. }   copy
  1. public class 升序排列 : BaseHierarchySort  
  2.   
  3. {  
  4.   
  5.     public override int Compare( GameObject lhs , GameObject rhs)  
  6.   
  7.     {  
  8.   
  9.         if (lhs == rhs) { return 0; }  
  10.   
  11.         if (lhs == null) { return -1; }  
  12.   
  13.         if (rhs == null) { return 1; }  
  14.   
  15.         return EditorUtility .NaturalCompare( lhs.name , rhs.name);  
  16.   
  17.     }  
  18.   
  19.     public override GUIContent content {  
  20.   
  21.         get { return new GUIContent( "升序"); }  
  22.   
  23.     }  
  24.   
  25. }  

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

标签: