A game about forced loneliness, made by TACStudios
1using System.IO;
2using UnityEditor.Tilemaps;
3
4namespace UnityEditor
5{
6 internal static class CustomRuleTileMenu
7 {
8 private const string customRuleTileScript =
9 @"using System.Collections;
10using System.Collections.Generic;
11using UnityEngine;
12using UnityEngine.Tilemaps;
13
14[CreateAssetMenu]
15public class #SCRIPTNAME# : RuleTile<#SCRIPTNAME#.Neighbor> {
16 public bool customField;
17
18 public class Neighbor : RuleTile.TilingRule.Neighbor {
19 public const int Null = 3;
20 public const int NotNull = 4;
21 }
22
23 public override bool RuleMatch(int neighbor, TileBase tile) {
24 switch (neighbor) {
25 case Neighbor.Null: return tile == null;
26 case Neighbor.NotNull: return tile != null;
27 }
28 return base.RuleMatch(neighbor, tile);
29 }
30}";
31
32 private static string tempCustomRuleTilePath;
33
34 [MenuItem("Assets/Create/2D/Tiles/Custom Rule Tile Script", false, (int)ETilesMenuItemOrder.CustomRuleTile)]
35 private static void CreateCustomRuleTile()
36 {
37 if (string.IsNullOrEmpty(tempCustomRuleTilePath) || !File.Exists(tempCustomRuleTilePath))
38 tempCustomRuleTilePath = FileUtil.GetUniqueTempPathInProject();
39 File.WriteAllText(tempCustomRuleTilePath, customRuleTileScript);
40 ProjectWindowUtil.CreateScriptAssetFromTemplateFile(tempCustomRuleTilePath, "NewCustomRuleTile.cs");
41 }
42 }
43}