No Description
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.

CustomRuleTileMenu.cs 1.4KB

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