===
有位熱心網友指出其實不用自己貼代碼
在Edit\preferences\General裡打勾Enable Alpha Numeric sorting
就可以自動照字母順序排列了
若您有逆向排序的需求 還是可以參考下面的做法
===
開一個c#的程式腳本貼入下面的代碼 或直接下載放到assets裡
"Copy and paste the code below into your new c# script
or put this file in the assets folder
===============================
using UnityEngine;
using UnityEditor;
public class A_to_Z : 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 Z_to_A : 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 );
}
}
你的階層圖就會多出一個星星按鈕
Then your Hierarchy will appear a new star button
可選擇A to Z順向排序或選擇Z to A 逆向排序物件
You can choose sorting objects by A to Z or Z to A
Editor Code,務必放在 Editor 資料夾,例如 Assets/Editor,以避免發布編譯錯誤
回覆刪除