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

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

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

勾上Enable Alpha Numeric Sorting

3333333.png

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

  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. /// <summary>
  5. /// 自定义Hierarchy中的对象排序
  6. /// </summary>
  7. public class MyAlphaNumericSort : BaseHierarchySort
  8. {
  9. private const string kDefaultSorting = "AlphabeticalSorting";
  10. private GUIContent m_Content = new GUIContent(EditorGUIUtility.FindTexture("AlphabeticalSorting"), "Alphabetical Order");
  11.  
  12. public override GUIContent content
  13. {
  14. get {
  15. return this.m_Content;
  16. }
  17. }
  18.  
  19. public override int Compare(GameObject lhs, GameObject rhs)
  20. {
  21. if (lhs == rhs) return 0;
  22. if (lhs == null) return -1;
  23. if (rhs == null) return 1;
  24. return EditorUtility.NaturalCompare(lhs.name, rhs.name);
  25. }
  26. }

说明

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

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号