AddressableAssetEntry.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace XGame.Editor.Asset.Addressable
  5. {
  6. public abstract class AddressableAssetEntry : IComparable
  7. {
  8. public enum EntryType
  9. {
  10. None = 0,
  11. Fold,
  12. File
  13. }
  14. /// <summary>
  15. /// 路径
  16. /// </summary>
  17. public string Path { private set; get; }
  18. /// <summary>
  19. /// 显示的名字
  20. /// </summary>
  21. public string ShowName { private set; get; }
  22. /// <summary>
  23. /// 文件夹开启标志
  24. /// </summary>
  25. public bool IsFoldout { set; get; }
  26. public virtual EntryType EnType => EntryType.None;
  27. private AddressableAssetEntry parent;
  28. public AddressableAssetEntry Parent
  29. {
  30. set
  31. {
  32. parent = value;
  33. OnSetParent();
  34. }
  35. get => parent;
  36. }
  37. protected AddressableAssetEntry(string path)
  38. {
  39. Path = path;
  40. ShowName = System.IO.Path.GetFileNameWithoutExtension(path);
  41. }
  42. public void GUI()
  43. {
  44. bool hasParent = parent != null;
  45. if (hasParent)
  46. {
  47. EditorGUILayout.BeginHorizontal();
  48. GUILayout.Space(10);
  49. }
  50. OnGUI();
  51. if (hasParent)
  52. {
  53. EditorGUILayout.EndHorizontal();
  54. }
  55. }
  56. public void Clear()
  57. {
  58. OnClear();
  59. }
  60. protected abstract void OnSetParent();
  61. protected abstract void OnGUI();
  62. protected abstract void OnClear();
  63. public int CompareTo(object obj)
  64. {
  65. int result = 0;
  66. if (obj is AddressableAssetEntry compare)
  67. {
  68. result = EnType - compare.EnType;
  69. if (result == 0)
  70. {
  71. result = string.Compare(ShowName, compare.ShowName, StringComparison.OrdinalIgnoreCase);
  72. }
  73. }
  74. return result;
  75. }
  76. }
  77. }