ABGroupInfoItem.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using XGame.Editor.Reorderable;
  5. namespace XGame.Editor.Build.AssetBundles
  6. {
  7. public class ABGroupInfoItem : IReorderableItem, System.IDisposable, IReorderableItemData<ABGroupInfo>
  8. {
  9. private ABGroupInfo _data;
  10. public float Height { get; private set; }
  11. public ABGroupInfo Data
  12. {
  13. get
  14. {
  15. var assetGuids = _assetList.GetItemDatas();
  16. _data.guidList.Clear();
  17. foreach(var guid in assetGuids)
  18. {
  19. if (!string.IsNullOrEmpty(guid) && !_data.guidList.Contains(guid))
  20. {
  21. _data.guidList.Add(guid);
  22. }
  23. }
  24. return _data;
  25. }
  26. }
  27. private readonly GUIContent assetContent = new GUIContent("GroupName", "资源或者文件夹,只能选择Assets/Res/Addressable目录下的资源");
  28. private ABPackerReorderableList<ABAssetItem, string> _assetList;
  29. public ABGroupInfoItem(ABGroupInfo data)
  30. {
  31. if (data.guidList == null)
  32. {
  33. data.guidList = new List<string>();
  34. }
  35. _data = data;
  36. var toolTip = "资源或者文件夹,只能选择Assets/Res/Addressable目录下的资源";
  37. _assetList = new ABPackerReorderableList<ABAssetItem, string>(data.guidList, "资源列表", toolTip);
  38. }
  39. void IReorderableItem.OnGUI(Rect rect)
  40. {
  41. Height = 0;
  42. var lineH = EditorGUIUtility.singleLineHeight;
  43. var tempRect = rect;
  44. tempRect.x += 14;
  45. tempRect.width -= 14;
  46. tempRect.height = lineH;
  47. _data.groupName = EditorGUI.TextField(tempRect, assetContent, _data.groupName);
  48. tempRect.y += lineH;
  49. Height += lineH;
  50. _assetList.OnGUI(tempRect);
  51. var listHeight = _assetList.TotalHeight;
  52. tempRect.y += listHeight;
  53. Height += listHeight;
  54. }
  55. void System.IDisposable.Dispose()
  56. {
  57. (_assetList as System.IDisposable)?.Dispose();
  58. _assetList = null;
  59. _data = null;
  60. }
  61. }
  62. }