AlphaTextureManifestExt.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using XGame.Framework.Asset;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using UnityEditor;
  7. namespace XGame.Editor.Asset
  8. {
  9. public static class AlphaTextureManifestExt
  10. {
  11. /// <summary>
  12. /// 编辑器扩展方法
  13. /// </summary>
  14. /// <param name="manifest"></param>
  15. /// <returns></returns>
  16. public static List<AtlasAlphaTextureInfo> GetAlphaTextureInfos(this AlphaTextureManifest manifest)
  17. {
  18. if (manifest != null)
  19. {
  20. var field = manifest.GetType().GetField("alphaTextureInfos", BindingFlags.NonPublic | BindingFlags.Instance);
  21. if (field != null)
  22. {
  23. var infos = (AtlasAlphaTextureInfo[])field.GetValue(manifest);
  24. if (infos != null)
  25. {
  26. return infos.Distinct().ToList();
  27. }
  28. }
  29. }
  30. return new List<AtlasAlphaTextureInfo>();
  31. }
  32. /// <summary>
  33. /// 编辑器扩展方法
  34. /// </summary>
  35. /// <param name="manifest"></param>
  36. /// <param name="alphaTextureInfos"></param>
  37. public static void SetAlphaTextureInfos(this AlphaTextureManifest manifest, AtlasAlphaTextureInfo[] alphaTextureInfos)
  38. {
  39. if (manifest == null) return;
  40. if (alphaTextureInfos != null)
  41. {
  42. alphaTextureInfos = alphaTextureInfos.Distinct().ToArray();
  43. Array.Sort(alphaTextureInfos);
  44. }
  45. var field = manifest.GetType().GetField("alphaTextureInfos", BindingFlags.NonPublic | BindingFlags.Instance);
  46. field?.SetValue(manifest, alphaTextureInfos);
  47. EditorUtility.SetDirty(manifest);
  48. AssetDatabase.SaveAssets();
  49. AssetDatabase.Refresh();
  50. }
  51. }
  52. }