using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; namespace UnityEditor.Tilemaps { /// /// Template used to create a RuleTile from Texture2D and Sprites. /// [HelpURL( "https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/RuleTile.html")] public class RuleTileTemplate : TileTemplate { internal static string kExtension = "asset"; /// /// Positional and Rule Data for detecting RuleTile Sprites. /// [Serializable] public struct RuleData { /// /// x, y positions on Texture2D. /// public List spritePositions; /// /// Tiling Rule for Rule at position. /// public RuleTile.TilingRule tilingRule; } /// /// List of Positional Data for detecting Sprites and Tiling Rules. /// public List rules; /// /// Original Width of the Template /// public int textureWidth; /// /// Original Height of the Template /// public int textureHeight; /// /// The Default Sprite set when creating a new Rule. /// public Sprite defaultSprite; /// /// The Default GameObject set when creating a new Rule. /// public GameObject defaultGameObject; /// /// The Default Collider Type set when creating a new Rule. /// public Tile.ColliderType defaultColliderType = Tile.ColliderType.Sprite; /// /// Creates a List of TileBase Assets with a RuleTile from Texture2D /// and Sprites with placement data onto a Tile Palette. /// /// Texture2D to generate Tile Assets from. /// Sprites to generate Tile Assets from. /// RuleTile asset and placement data to generate. public override void CreateTileAssets( Texture2D texture2D , IEnumerable sprites , ref List tilesToAdd) { if (texture2D == null) return; var ruleTile = ScriptableObject.CreateInstance(); ruleTile.name = $"{texture2D.name} RuleTile"; this.ApplyTemplateToRuleTile(texture2D, ruleTile); var tileChangeData = new TileChangeData( Vector3Int.zero , ruleTile , Color.white , Matrix4x4.identity ); tilesToAdd.Add(tileChangeData); } } }