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