Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CreateTileFromPaletteAttribute.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using UnityEngine;
  5. using UnityEngine.Tilemaps;
  6. namespace UnityEditor.Tilemaps
  7. {
  8. /// <summary>
  9. /// Use this attribute to add an option to customize how Tiles are created when dragging and dropping assets to the Tile Palette.
  10. /// </summary>
  11. /// <remarks>
  12. /// Append this attribute to a method that has a signature of "static TileBase CreateTile(Sprite sprite)".
  13. /// </remarks>
  14. /// <example>
  15. /// <code lang="cs"><![CDATA[
  16. /// using UnityEditor.Tilemaps;
  17. /// using UnityEngine;
  18. /// using UnityEngine.Tilemaps;
  19. ///
  20. /// public class CreateBlueTile
  21. /// {
  22. /// [CreateTileFromPalette]
  23. /// public static TileBase BlueTile(Sprite sprite)
  24. /// {
  25. /// var blueTile = ScriptableObject.CreateInstance<Tile>();
  26. /// blueTile.sprite = sprite;
  27. /// blueTile.name = sprite.name;
  28. /// blueTile.color = Color.blue;
  29. /// return blueTile;
  30. /// }
  31. /// }
  32. /// ]]></code>
  33. /// </example>
  34. [AttributeUsage(AttributeTargets.Method)]
  35. public class CreateTileFromPaletteAttribute : Attribute
  36. {
  37. private static List<MethodInfo> m_CreateTileFromPaletteMethods;
  38. internal static List<MethodInfo> createTileFromPaletteMethods
  39. {
  40. get
  41. {
  42. if (m_CreateTileFromPaletteMethods == null)
  43. GetCreateTileFromPaletteAttributeMethods();
  44. return m_CreateTileFromPaletteMethods;
  45. }
  46. }
  47. [RequiredSignature]
  48. private static TileBase CreateTile(Sprite sprite)
  49. {
  50. return null;
  51. }
  52. private static void GetCreateTileFromPaletteAttributeMethods()
  53. {
  54. m_CreateTileFromPaletteMethods = new List<MethodInfo>();
  55. foreach (var sortingMethod in TypeCache.GetMethodsWithAttribute<CreateTileFromPaletteAttribute>())
  56. {
  57. m_CreateTileFromPaletteMethods.Add(sortingMethod);
  58. }
  59. }
  60. }
  61. }