AlphaTextureManifest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using System;
  4. namespace XGame.Framework.Asset
  5. {
  6. public class AlphaTextureManifest : ScriptableObject, IDisposable
  7. {
  8. [SerializeField]
  9. private AtlasAlphaTextureInfo[] alphaTextureInfos;
  10. /// <summary>
  11. /// key:spriteName
  12. /// value:alphaTextureName
  13. /// </summary>
  14. private Dictionary<string, string> spriteMap;
  15. public void Init()
  16. {
  17. if (alphaTextureInfos != null)
  18. {
  19. spriteMap = new Dictionary<string, string>();
  20. foreach(var info in alphaTextureInfos)
  21. {
  22. if (info.sprites != null)
  23. {
  24. foreach(var spr in info.sprites)
  25. {
  26. if (!spriteMap.ContainsKey(spr))
  27. {
  28. spriteMap.Add(spr, info.textureName);
  29. }
  30. else
  31. {
  32. AssetsLog.Error($"Atlas Alpha Manifest Error. Sprite repeat. name:{spr} tex:{info.textureName}");
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }
  39. public bool TryGetAlphaTextureName(string spriteName, out string textureName)
  40. {
  41. if (spriteMap != null && spriteMap.TryGetValue(spriteName, out textureName))
  42. {
  43. return true;
  44. }
  45. textureName = string.Empty;
  46. return false;
  47. }
  48. void IDisposable.Dispose()
  49. {
  50. if (spriteMap != null)
  51. {
  52. spriteMap.Clear();
  53. spriteMap = null;
  54. }
  55. }
  56. }
  57. }