Sin descripción
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridPalettes.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.Tilemaps
  5. {
  6. internal class GridPalettes : ScriptableSingleton<GridPalettes>
  7. {
  8. private static bool s_RefreshCache;
  9. [SerializeField] private List<GameObject> m_PalettesCache;
  10. public static List<GameObject> palettes
  11. {
  12. get
  13. {
  14. if (instance.m_PalettesCache == null || s_RefreshCache)
  15. {
  16. instance.RefreshPalettesCache();
  17. s_RefreshCache = false;
  18. }
  19. return instance.m_PalettesCache;
  20. }
  21. }
  22. private void RefreshPalettesCache()
  23. {
  24. if (instance.m_PalettesCache == null)
  25. instance.m_PalettesCache = new List<GameObject>();
  26. string[] guids = AssetDatabase.FindAssets("t:GridPalette");
  27. foreach (string guid in guids)
  28. {
  29. string path = AssetDatabase.GUIDToAssetPath(guid);
  30. GridPalette paletteAsset = AssetDatabase.LoadAssetAtPath(path, typeof(GridPalette)) as GridPalette;
  31. if (paletteAsset != null)
  32. {
  33. string assetPath = AssetDatabase.GetAssetPath(paletteAsset);
  34. GameObject palette = AssetDatabase.LoadMainAssetAtPath(assetPath) as GameObject;
  35. if (palette != null)
  36. {
  37. m_PalettesCache.Add(palette);
  38. }
  39. }
  40. }
  41. m_PalettesCache.Sort((x, y) => String.Compare(x.name, y.name, StringComparison.OrdinalIgnoreCase));
  42. }
  43. public class AssetProcessor : AssetPostprocessor
  44. {
  45. public override int GetPostprocessOrder()
  46. {
  47. return 1;
  48. }
  49. private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath)
  50. {
  51. if (!GridPaintingState.savingPalette)
  52. CleanCache();
  53. }
  54. }
  55. internal static void CleanCache()
  56. {
  57. instance.m_PalettesCache = null;
  58. }
  59. }
  60. }