├── .buginfo ├── .npmignore ├── CHANGELOG.md ├── CHANGELOG.md.meta ├── CONTRIBUTING.md ├── CONTRIBUTING.md.meta ├── Documentation~ ├── AdvancedRuleOverrideTile.md ├── AnimatedTile.md ├── Brushes.md ├── Contributors.md ├── CoordinateBrush.md ├── CustomRulesForRuleTile.md ├── GameObjectBrush.md ├── GridInformation.md ├── GroupBrush.md ├── LineBrush.md ├── Other.md ├── PipelineTile.md ├── PrefabBrush.md ├── RandomBrush.md ├── RandomTile.md ├── RuleOverrideTile.md ├── RuleTile.md ├── TableOfContents.md ├── TerrainTile.md ├── Tiles.md ├── TintBrush.md ├── TintBrushSmooth.md ├── WeightedRandomTile.md ├── images │ ├── AdvancedRuleOverrideTile.png │ ├── AdvancedRuleOverrideTileEditor.png │ ├── AnimatedTile.png │ ├── AnimatedTileEditor.png │ ├── BrushDropdown.png │ ├── CoordinateBrush.png │ ├── GameObjectBrush.png │ ├── GroupBrush.png │ ├── LineBrush.png │ ├── LineBrushFillGaps.png │ ├── PipelineTile.png │ ├── PipelineTileEditor.png │ ├── PrefabBrush.png │ ├── PrefabBrushEditor.png │ ├── RandomBrush.png │ ├── RandomBrushTileSet.png │ ├── RandomTile.png │ ├── RandomTileEditor.png │ ├── RuleOverrideTile.png │ ├── RuleOverrideTileEditor.png │ ├── RuleOverrideTileEditorAdvanced.png │ ├── RuleOverrideTileEditorMissing.png │ ├── RuleTile.png │ ├── RuleTileEditor.png │ ├── RuleTileOutputAnimation.png │ ├── RuleTileOutputRandom.png │ ├── RuleTileRule.png │ ├── RuleTileRuleExtendNeighbor.png │ ├── RuleTileRuleFixed.png │ ├── RuleTileRuleMirror.png │ ├── RuleTileRuleRotated.png │ ├── RuleTileRuleTip.png │ ├── TerrainTile.png │ ├── TerrainTileEditor.png │ ├── TintBrush.png │ ├── TintBrushSmooth.png │ ├── WeightedRandomTile.png │ └── WeightedRandomTileEditor.png └── index.md ├── Editor.meta ├── Editor ├── Brushes.meta ├── Brushes │ ├── CoordinateBrush.meta │ ├── CoordinateBrush │ │ ├── CoordinateBrush.cs │ │ └── CoordinateBrush.cs.meta │ ├── GameObjectBrush.meta │ ├── GameObjectBrush │ │ ├── GameObjectBrush.cs │ │ └── GameObjectBrush.cs.meta │ ├── GroupBrush.meta │ ├── GroupBrush │ │ ├── GroupBrush.cs │ │ └── GroupBrush.cs.meta │ ├── LineBrush.meta │ ├── LineBrush │ │ ├── LineBrush.cs │ │ └── LineBrush.cs.meta │ ├── PrefabBrushes.meta │ ├── PrefabBrushes │ │ ├── BasePrefabBrush.cs │ │ ├── BasePrefabBrush.cs.meta │ │ ├── BrushMenuItem.cs │ │ ├── BrushMenuItem.cs.meta │ │ ├── PrefabBrush.meta │ │ ├── PrefabBrush │ │ │ ├── PrefabBrush.cs │ │ │ └── PrefabBrush.cs.meta │ │ ├── PrefabRandomBrush.meta │ │ └── PrefabRandomBrush │ │ │ ├── PrefabRandomBrush.cs │ │ │ └── PrefabRandomBrush.cs.meta │ ├── RandomBrush.meta │ ├── RandomBrush │ │ ├── RandomBrush.cs │ │ └── RandomBrush.cs.meta │ ├── TintBrush.meta │ ├── TintBrush │ │ ├── TintBrush.cs │ │ └── TintBrush.cs.meta │ ├── TintBrushSmooth.meta │ └── TintBrushSmooth │ │ ├── TintBrushSmooth.cs │ │ ├── TintBrushSmooth.cs.meta │ │ ├── TintTextureGeneratorEditor.cs │ │ └── TintTextureGeneratorEditor.cs.meta ├── Menu.meta ├── Menu │ ├── CustomRuleTileMenu.cs │ ├── CustomRuleTileMenu.cs.meta │ ├── MenuItemOrder.cs │ └── MenuItemOrder.cs.meta ├── Tiles.meta ├── Tiles │ ├── HexagonalRuleTile.meta │ ├── HexagonalRuleTile │ │ ├── HexagonalRuleTileEditor.cs │ │ └── HexagonalRuleTileEditor.cs.meta │ ├── IsometricRuleTile.meta │ ├── IsometricRuleTile │ │ ├── IsometricRuleTileEditor.cs │ │ └── IsometricRuleTileEditor.cs.meta │ ├── Menu.meta │ ├── Menu │ │ ├── PipelineTileMenu.cs │ │ ├── PipelineTileMenu.cs.meta │ │ ├── RandomTileMenu.cs │ │ ├── RandomTileMenu.cs.meta │ │ ├── TerrainTileMenu.cs │ │ ├── TerrainTileMenu.cs.meta │ │ ├── WeightedRandomTileMenu.cs │ │ └── WeightedRandomTileMenu.cs.meta │ ├── RuleOverrideTile.meta │ ├── RuleOverrideTile │ │ ├── AdvancedRuleOverrideTileEditor.cs │ │ ├── AdvancedRuleOverrideTileEditor.cs.meta │ │ ├── PopulateRuleOverrideTileWizard.cs │ │ ├── PopulateRuleOverrideTileWizard.cs.meta │ │ ├── RuleOverrideTileEditor.cs │ │ └── RuleOverrideTileEditor.cs.meta │ ├── RuleTile.meta │ └── RuleTile │ │ ├── RuleTileEditor.cs │ │ └── RuleTileEditor.cs.meta ├── Unity.2D.Tilemap.Extras.Editor.asmdef └── Unity.2D.Tilemap.Extras.Editor.asmdef.meta ├── LICENSE.md ├── LICENSE.md.meta ├── QAReport.md ├── QAReport.md.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Brushes.meta ├── Brushes │ ├── TintTextureGenerator.cs │ ├── TintTextureGenerator.cs.meta │ ├── TintedTilemap.shader │ └── TintedTilemap.shader.meta ├── GridInformation.meta ├── GridInformation │ ├── GridInformation.cs │ └── GridInformation.cs.meta ├── Tiles.meta ├── Tiles │ ├── AnimatedTile.meta │ ├── AnimatedTile │ │ ├── AnimatedTile.cs │ │ └── AnimatedTile.cs.meta │ ├── HexagonalRuleTile.meta │ ├── HexagonalRuleTile │ │ ├── HexagonalRuleTile.cs │ │ └── HexagonalRuleTile.cs.meta │ ├── IsometricRuleTile.meta │ ├── IsometricRuleTile │ │ ├── IsometricRuleTile.cs │ │ └── IsometricRuleTile.cs.meta │ ├── PipelineTile.meta │ ├── PipelineTile │ │ ├── PipelineTile.cs │ │ └── PipelineTile.cs.meta │ ├── RandomTile.meta │ ├── RandomTile │ │ ├── RandomTile.cs │ │ └── RandomTile.cs.meta │ ├── RuleOverrideTile.meta │ ├── RuleOverrideTile │ │ ├── AdvancedRuleOverrideTile.cs │ │ ├── AdvancedRuleOverrideTile.cs.meta │ │ ├── RuleOverrideTile.cs │ │ └── RuleOverrideTile.cs.meta │ ├── RuleTile.meta │ ├── RuleTile │ │ ├── RuleTile.cs │ │ └── RuleTile.cs.meta │ ├── TerrainTile.meta │ ├── TerrainTile │ │ ├── TerrainTile.cs │ │ └── TerrainTile.cs.meta │ ├── WeightedRandomTile.meta │ └── WeightedRandomTile │ │ ├── WeightedRandomTile.cs │ │ └── WeightedRandomTile.cs.meta ├── Unity.2D.Tilemap.Extras.asmdef └── Unity.2D.Tilemap.Extras.asmdef.meta ├── Samples~ ├── DungeonRuleTile │ ├── .sample.json │ ├── Sprites │ │ ├── Dungeon.png │ │ └── Dungeon.png.meta │ └── Tiles │ │ ├── Dungeon.asset │ │ └── Dungeon.asset.meta ├── PipeRuleTile │ ├── .sample.json │ ├── Sprites │ │ ├── Pipes.png │ │ └── Pipes.png.meta │ └── Tiles │ │ ├── Pipes.asset │ │ └── Pipes.asset.meta └── WaterfallAnimatedTile │ ├── .sample.json │ ├── Sprites │ ├── Waterfall.png │ └── Waterfall.png.meta │ └── Tiles │ ├── Waterfall.asset │ ├── Waterfall.asset.meta │ ├── Waterfall_Bottom.asset │ └── Waterfall_Bottom.asset.meta ├── Tests.meta ├── Tests ├── Editor.meta └── Editor │ ├── PlaceholderTests.cs │ ├── PlaceholderTests.cs.meta │ ├── Unity.2D.Tilemap.Extras.EditorTests.asmdef │ └── Unity.2D.Tilemap.Extras.EditorTests.asmdef.meta ├── Third Party Notices.md ├── Third Party Notices.md.meta ├── package.json └── package.json.meta /.buginfo: -------------------------------------------------------------------------------- 1 | system: jira 2 | system: jira.unity3d.com 3 | issuetype: Bug 4 | package: 2D Tilemap Extras 5 | project: DANB 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | artifacts/** 2 | build/** 3 | .DS_Store 4 | .npmrc 5 | .npmignore 6 | .gitignore 7 | QAReport.md 8 | QAReport.md.meta 9 | .gitlab-ci.yml 10 | build.bat 11 | build.sh -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e2b8acf174765f141a47de79f2db4b26 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## All contributions are subject to the [Unity Contribution Agreement(UCA)](https://unity3d.com/legal/licenses/Unity_Contribution_Agreement) 4 | By making a pull request, you are confirming agreement to the terms and conditions of the UCA, including that your Contributions are your original creation and that you have complete right and authority to make your Contributions. 5 | 6 | ## Once you have a change ready following these ground rules. Simply make a pull request! -------------------------------------------------------------------------------- /CONTRIBUTING.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6227377cf86ed2341ba50b1d9889f2f7 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Documentation~/AdvancedRuleOverrideTile.md: -------------------------------------------------------------------------------- 1 | # Advanced Rule Override Tile 2 | 3 | __Contributions by:__ [johnsoncodehk](https://github.com/johnsoncodehk), [Autofire](https://github.com/Autofire) 4 | 5 | __Advanced Rule Override Tiles__ are Tiles which can override a subset of Rules for a given [Rule Tile](RuleTile.md) while maintaining most of the other set Rules of the Rule Tile. This allows you to create Tiles that provide specialized behavior in specific scenarios. 6 | 7 | ## Properties 8 | 9 | | Property | Function | 10 | | ----------------- | ------------------------------------------------------------ | 11 | | __Tile__ | The Rule Tile to override. | 12 | 13 | Depending on the Rule Tile that is overridden, there may be further properties which you can override here. Any public property in the Rule Tile that does not have a `RuleTile.DontOverride` attribute will be shown here and can be overridden. 14 | 15 | ## Usage 16 | 17 | First select the Rule Tile to be overridden in the __Tile__ property. The Rule Override Tile editor then displays the different rules in the selected Rule Tile which you can override. 18 | 19 | Select the Rule which you want to override by toggling the Rule. This will allow you to modify the output of the Rule, such as the Sprite, the GameObject or the Collider Type. The outputs are the same as the original [Rule Tile](RuleTile.md) and are detailed there. The matching Rule itself cannot be changed here and is displayed here to help identify it. 20 | 21 | ![Advanced Rule Override Tile Editor](images/AdvancedRuleOverrideTileEditor.png) 22 | 23 | Paint with the Advanced Rule Override Tile using the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Painting.html) tools. 24 | 25 | ![Scene View with Advanced Rule Override Tile](images/AdvancedRuleOverrideTile.png) -------------------------------------------------------------------------------- /Documentation~/AnimatedTile.md: -------------------------------------------------------------------------------- 1 | # Animated Tile 2 | 3 | __Contribution by:__ MahdiMahzuni 4 | 5 | An Animated Tile runs through and displays a list of Sprites in sequence to create a frame-by-frame animation. 6 | 7 | ![](images/AnimatedTileEditor.png)
Animated Tile editor window 8 | 9 | ### Properties 10 | 11 | | Property | Function | 12 | | ------------------------------ | ------------------------------------------------------------ | 13 | | __Number of Animated Sprites__ | Number of Animated Sprites in the Animated Tile. | 14 | | __Sprite list__ | The list displaying the current order of Sprites for this Animated Tile’s animation which plays in sequence. Set a Sprite by selecting the **Select** button at the bottom right of the Sprite preview, then choosing the Sprite from the dialog box. Select and hold the **=** next to each Sprite to reorder their place in the animation sequence. | 15 | | __Minimum Speed__ | The minimum possible speed at which the Animation of the Tile is played. A speed value will be randomly chosen between the minimum and maximum speed. | 16 | | __Maximum Speed__ | The maximum possible speed at which the Animation of the Tile is played. A speed value will be randomly chosen between the minimum and maximum speed. | 17 | | __Start Time__ | The starting time of this Animated Tile. This allows you to start the Animation from a particular time. | 18 | | __Start Frame__ | The starting frame of this Animated Tile. This allows you to start the Animation from a particular Sprite in the list of Animated Sprites. | 19 | | __Collider Type__ | The [Collider](https://docs.unity3d.com/Manual/Collider2D.html) shape generated by the Tile. | 20 | 21 | ### Usage 22 | 23 | Create the Animated Tile by selecting and ordering the Sprites that makes up its animation sequence in the Animated Tile editor, then paint the Animated Tile with the [Tile Palette tools](https://docs.unity3d.com/Manual/Tilemap-Painting.html). 24 | 25 | ![](images/AnimatedTile.png)
Game view, painted with the [Group Brush](GroupBrush.md). -------------------------------------------------------------------------------- /Documentation~/Brushes.md: -------------------------------------------------------------------------------- 1 | # Scriptable Brushes 2 | 3 | You can script Brushes to paint items based on the position and conditions of the cell it targets on the Grid Layout. Brush paint behavior can be further modified by the selected editing Tool, such as __Erase__ or __Floodfill__. 4 | 5 | Here are some implementations of **Scriptable Brushes** which can help save time when designing your Tilemap: 6 | 7 | - [GameObject Brush](GameObjectBrush.md) 8 | - [Random Brush](RandomBrush.md) 9 | - [Line Brush](LineBrush.md) 10 | - [Group Brush](GroupBrush.md) 11 | 12 | Refer to the [Scriptable Brushes](https://docs.unity3d.com/Manual/Tilemap-ScriptableBrushes.html) documentation for more information. 13 | 14 | -------------------------------------------------------------------------------- /Documentation~/Contributors.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | Thank you to all who have contributed to this repository! 4 | 5 | - [johnsoncodehk](https://github.com/johnsoncodehk) 6 | - [nicovain](https://github.com/nicovain) 7 | - [superkerokero](https://github.com/superkerokero) 8 | - [pmurph0305](https://github.com/pmurph0305) 9 | - [janissimsons](https://github.com/janissimsons) 10 | - [distantcam](https://github.com/distantcam) 11 | - [Pepperized](https://github.com/Pepperized) 12 | - MahdiMahzuni 13 | - [DreadBoy](https://github.com/DreadBoy) 14 | - [DoctorShinobi](https://github.com/DoctorShinobi) 15 | - [CraigGraff](https://github.com/CraigGraff) 16 | - [Autofire](https://github.com/Autofire) 17 | - [AVChemodanov](https://github.com/AVChemodanov) 18 | - [ream88](https://github.com/ream88) 19 | - [Quickz](https://github.com/Quickz) 20 | - [capnslipp](https://github.com/capnslipp) 21 | - [TrentSterling](https://github.com/TrentSterling) 22 | - [vladderb](https://github.com/vladderb) 23 | - [trobol](https://github.com/trobol) 24 | - [HyagoOliveira](https://github.com/HyagoOliveira) 25 | - [RyotaMurohoshi](https://github.com/RyotaMurohoshi) 26 | - [ManickYoj](https://github.com/ManickYoj) 27 | - [n4n0lix](https://githubb.com/n4n0lix) 28 | 29 | If anybody has been missed, please do let us know! -------------------------------------------------------------------------------- /Documentation~/CoordinateBrush.md: -------------------------------------------------------------------------------- 1 | # Coordinate Brush 2 | 3 | __Contributions by :__ [nicovain](https://github.com/nicovain), [pmurph0305](https://github.com/pmurph0305) 4 | 5 | This Brush displays the coordinates of the it is currently targeting in the Scene view. Use this Brush as an example for creating custom Brushes that display extra visual features, such as cell coordinates or other information, while painting a Tilemap with the Brush. 6 | 7 | ![](images/CoordinateBrush.png)
When painting with the Coordinate Brush in the Scene view, the position of the currently highlighted cell is displayed. 8 | 9 | -------------------------------------------------------------------------------- /Documentation~/CustomRulesForRuleTile.md: -------------------------------------------------------------------------------- 1 | # Custom Rules for Rule Tile 2 | 3 | __Contribution by:__ [johnsoncodehk](https://github.com/johnsoncodehk) 4 | 5 | Use this template script to create new custom [Rule Tiles](RuleTile.md) with matching options that differ from the Rule Tile’s [default options](RuleTile.md#Usage) (namely **This** and **Not This**). This creates selectable options for each Rule in your custom __Rule Tile__. 6 | 7 | ## Template features 8 | 9 | - Inheritable Rule Tile. 10 | - Customizable properties. 11 | - Expand or rewrite both neighbor Rules and the GUI display of the Rules. 12 | - Usable with by [RuleOverrideTile](RuleOverrideTile.md) 13 | - Create from a template script. 14 | - Neighbor Rules tooltips. 15 | - Backward compatible. 16 | 17 | ## Creating a custom Rule Tile script 18 | 19 | Create a Custom Rule Tile script by going to __Assets > Create > Custom Rule Tile Script__. Name the newly created file when prompted. After creating the file, you can edit it to add new matching options and custom algorithms for testing matches. 20 | 21 | ### Examples 22 | 23 | - Custom properties: 24 | 25 | ```csharp 26 | public class MyTile : RuleTile { 27 | public string tileId; 28 | public bool isWater; 29 | } 30 | ``` 31 | 32 | - Custom rules: 33 | 34 | ```csharp 35 | public class MyTile : RuleTile { 36 | public class Neighbor { 37 | public const int MyRule1 = 0; 38 | public const int MyRule2 = 1; 39 | } 40 | public override bool RuleMatch(int neighbor, TileBase tile) { 41 | switch (neighbor) { 42 | case Neighbor.MyRule1: return false; 43 | case Neighbor.MyRule2: return true; 44 | } 45 | return true; 46 | } 47 | } 48 | ``` 49 | 50 | - Expansion rules 51 | 52 | ```csharp 53 | public class MyTile : RuleTile { 54 | public class Neighbor : RuleTile.TilingRule.Neighbor { 55 | // 0, 1, 2 is using in RuleTile.TilingRule.Neighbor 56 | public const int MyRule1 = 3; 57 | public const int MyRule2 = 4; 58 | } 59 | public override bool RuleMatch(int neighbor, TileBase tile) { 60 | switch (neighbor) { 61 | case Neighbor.MyRule1: return false; 62 | case Neighbor.MyRule2: return true; 63 | } 64 | return base.RuleMatch(neighbor, tile); 65 | } 66 | } 67 | ``` 68 | 69 | - Siblings Tile 1 70 | 71 | ```csharp 72 | public class MyTile : RuleTile { 73 | public List sibings = new List(); 74 | public class Neighbor : RuleTile.TilingRule.Neighbor { 75 | public const int Sibing = 3; 76 | } 77 | public override bool RuleMatch(int neighbor, TileBase tile) { 78 | switch (neighbor) { 79 | case Neighbor.Sibing: return sibings.Contains(tile); 80 | } 81 | return base.RuleMatch(neighbor, tile); 82 | } 83 | } 84 | ``` 85 | 86 | - Siblings Tile 2 87 | 88 | ```csharp 89 | public class MyTile : RuleTile { 90 | public int siblingGroup; 91 | public class Neighbor : RuleTile.TilingRule.Neighbor { 92 | public const int Sibing = 3; 93 | } 94 | public override bool RuleMatch(int neighbor, TileBase tile) { 95 | MyTile myTile = tile as MyTile; 96 | switch (neighbor) { 97 | case Neighbor.Sibing: return myTile && myTile.siblingGroup == siblingGroup; 98 | } 99 | return base.RuleMatch(neighbor, tile); 100 | } 101 | } 102 | ``` -------------------------------------------------------------------------------- /Documentation~/GameObjectBrush.md: -------------------------------------------------------------------------------- 1 | # GameObject Brush 2 | 3 | This Brush instances, places and manipulates GameObjects onto the Scene. Use this Brush as an example for creating custom Brushes which can target and manipulate other GameObjects beside Tiles. 4 | 5 | ## Usage 6 | 7 | First select the GameObject Brush from the Brush drop-down menu. With the Brush selected, then select the [Picker Tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Picker) from the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Painting.html) toolbar. Use the [Select Tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Select) to select GameObjects from the Scene that you want the GameObject Brush to paint with. Note that these GameObjects must be a child of the active Grid to be selectable with this Brush. 8 | 9 | When painting with the GameObject Brush, the Brush will instantiate GameObjects picked onto the Scene. 10 | 11 | ![Scene View with GameObject Brush](images/GameObjectBrush.png) 12 | 13 | ## Implementation 14 | 15 | The GameObjectBrush inherits from the GridBrush and overrides several methods when implemented. The following methods are overridden: 16 | 17 | - It overrides the `Paint` method to paint a GameObject. 18 | - It overrides the `Erase` method to erase the GameObjects from the Scene. 19 | - It overrides the `BoxFill` method to paint a GameObject in each cell defined by the [Box Tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Rec). 20 | - It overrides the `Move` methods to move GameObjects in the Scene. 21 | - It overrides the `Flip` methods to flip GameObjects in the picked selection. -------------------------------------------------------------------------------- /Documentation~/GridInformation.md: -------------------------------------------------------------------------------- 1 | # Grid Information 2 | 3 | This is a simple component that stores and provides information based on Grid positions and keywords. 4 | 5 | ## Usage 6 | 7 | Add this Component to a GameObject with a Grid component. To store information on to the Grid Information component, use the following APIs: 8 | 9 | ```C# 10 | public bool SetPositionProperty(Vector3Int position, String name, int positionProperty) 11 | 12 | public bool SetPositionProperty(Vector3Int position, String name, string positionProperty) 13 | 14 | public bool SetPositionProperty(Vector3Int position, String name, float positionProperty) 15 | 16 | public bool SetPositionProperty(Vector3Int position, String name, double positionProperty) 17 | 18 | public bool SetPositionProperty(Vector3Int position, String name, UnityEngine.Object positionProperty) 19 | 20 | public bool SetPositionProperty(Vector3Int position, String name, Color positionProperty) 21 | ``` 22 | 23 | 24 | 25 | To retrieve information from the Grid Information component, use the following APIs: 26 | 27 | ```C# 28 | public T GetPositionProperty(Vector3Int position, String name, T defaultValue) where T : UnityEngine.Object 29 | 30 | public int GetPositionProperty(Vector3Int position, String name, int defaultValue) 31 | 32 | public string GetPositionProperty(Vector3Int position, String name, string defaultValue) 33 | 34 | public float GetPositionProperty(Vector3Int position, String name, float defaultValue) 35 | 36 | public double GetPositionProperty(Vector3Int position, String name, double defaultValue) 37 | 38 | public Color GetPositionProperty(Vector3Int position, String name, Color defaultValue) 39 | ``` 40 | 41 | You can use this in combination with [Scriptable Tiles](https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles.html) to get the right [TileData](https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles-TileData.html) when creating the layout of your Tilemap. -------------------------------------------------------------------------------- /Documentation~/GroupBrush.md: -------------------------------------------------------------------------------- 1 | # Group Brush 2 | 3 | This Brush picks Tiles which are grouped together according to their position and its set properties. Set the __Gap__ value to identify which Tiles belong to the group, and set the __Limit__ value to ensure that the picked group remains within the desired size. Use this Brush as an example to create your own Brushes that can choose and pick specific Tiles 4 | 5 | ## Properties 6 | 7 | | Property | Function | 8 | | --------- | ------------------------------------------------------------ | 9 | | __Gap__ | This value represents the minimum number of cells that must be in between picked Tiles. Only Tiles that are at least this many cells apart are picked by the Brush and placed in the group. Set this value to 0 to pick up all Tiles that are directly adjacent to each other in the group. | 10 | | __Limit__ | This value represents the maximum number of cells around the initial picked position. Only Tiles within this range of cells are picked by the Brush and placed in the group. | 11 | 12 | ## Usage 13 | 14 | Select the Group Brush, and use the [Picker Tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Picker) and pick a position on the Tilemap. The Group Brush selects a group of Tiles based on its set properties and creates a Group. 15 | 16 | ![Scene View with Group Brush](images/GroupBrush.png) 17 | 18 | ## Implementation 19 | 20 | The Group Brush inherits from the Grid Brush. It overrides the `Pick` method when picking a group of Tiles based on their position and its set properties. -------------------------------------------------------------------------------- /Documentation~/LineBrush.md: -------------------------------------------------------------------------------- 1 | # Line Brush 2 | 3 | __Contribution by :__ [CraigGraff](https://github.com/CraigGraff) 4 | 5 | This Brush draws a line of Tiles onto a Tilemap. With this Brush selected, click once to set the starting point of the line and click again at another position to set the ending point of the line. This Brush then draws a line of Tiles between the two points. 6 | 7 | Use this as an example to create custom Brush behavior to make painting more efficient. 8 | 9 | ## Properties 10 | 11 | | Property | Function | 12 | | --------------------- | ------------------------------------------------------------ | 13 | | __Line Start Active__ | Indicates whether the Line Brush has started drawing a line. | 14 | | __Fill Gaps__ | Ensures that there are orthogonal connections between all Tiles that connect the start and end of the line. | 15 | | __Line Start__ | The current starting point of the line. | 16 | 17 | ## Usage 18 | Select the Line Brush, then click once on a cell of the Tilemap to set the starting point of the line, then click on a second cell to set the ending point of the line. The Brush then draws the line of Tiles between the two set points. When the Line Brush is active, a blue outline will indicate the starting point of the line. 19 | 20 | ![Scene View with Line Brush](images/LineBrush.png) 21 | 22 | To have Tiles which are orthogonally connected from start to end, enable the __Fill Gaps__ property in the Brush Editor. 23 | 24 | ![Scene View with Line Brush with Fill Gaps](images/LineBrushFillGaps.png) 25 | 26 | ## Implementation 27 | 28 | The Line Brush inherits from the Grid Brush and overrides the `Paint` method to implement the line painting functionality. -------------------------------------------------------------------------------- /Documentation~/Other.md: -------------------------------------------------------------------------------- 1 | # Other 2 | 3 | This section will contain other useful scripts which you can use and other details in the future. 4 | 5 | -------------------------------------------------------------------------------- /Documentation~/PipelineTile.md: -------------------------------------------------------------------------------- 1 | # Pipeline Tile 2 | 3 | A Pipeline Tile take into consideration its orthogonal neighboring tiles and displays a Sprite depending on whether the neighboring Tile is the same Tile as itself and the number of Tiles bordering it. 4 | 5 | ## Properties 6 | 7 | | Property | Function | 8 | | --------- | ------------------------------------------------------------ | 9 | | __None__ | Displays this selected Sprite when no other Tiles border the Tile. | 10 | | __One__ | Displays this selected Sprite when one Tile borders the Tile. | 11 | | __Two__ | Displays this selected Sprite when two Tiles border the Tile. | 12 | | __Three__ | Displays this selected Sprite when three Tiles border the Tile. | 13 | | __Four__ | Displays this selected Sprite when four Tiles border the Tile. | 14 | 15 | ## Usage 16 | 17 | In the Pipeline Tile editor window, set up the Pipeline Tile by selecting the Sprites that are displayed depending on the number of Tiles bordering the Sprite. 18 | 19 | ![Pipeline Tile Editor](images/PipelineTileEditor.png) 20 | 21 | Then [paint](https://docs.unity3d.com/Manual/Tilemap-Painting.html) the Pipeline Tile onto the Tilemap with the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Palette.html) tools. 22 | 23 | ![Scene View with Pipeline Tile](images/PipelineTile.png) -------------------------------------------------------------------------------- /Documentation~/PrefabBrush.md: -------------------------------------------------------------------------------- 1 | # Prefab Brush 2 | 3 | __Contributions by:__ [Pepperized](https://github.com/Pepperized), [superkerokero](https://github.com/superkerokero), [vladderb](https://github.com/vladderb), [RyotaMurohoshi](https://github.com/RyotaMurohoshi), [ManickYoj](https://github.com/ManickYoj), [Quickz](https://github.com/Quickz), [basile](https://github.com/bazile) 4 | 5 | This Brush instances and places randomly selected Prefabs onto the target location and parents the instanced object to the [paint target](https://docs.unity3d.com/Manual/Tilemap-Painting.htm). Use this Brush as an example to create custom Brushes which can quickly place an assortment of GameObjects onto structured locations. 6 | 7 | ## Properties 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
PropertyFunction
Perlin ScaleThe factor using the Perlin noise algorithm for the random distribution of Prefabs chosen when painting.
PrefabsSet the number of and selection of Prefabs to paint from.
SizeSet the number of Prefabs that the Brush selects from.
Element *Set one of the Prefabs to select from for each entry. The number of Element entries matches the value set in Size.
37 | 38 | ## Usage 39 | 40 | First set the number of Prefabs to select from in the __Prefabs__ property, then add Prefab Assets to the list. Adjust the __Perlin Scale__ property to adjust the distribution of Prefabs painted onto a particular cell. 41 | 42 | ![Brush Editor with Prefab Brush](images/PrefabBrushEditor.png) 43 | 44 | When painting with the Prefab Brush, the Prefab Brush picks from the available Prefabs based on the __Perlin Scale__ set, and instantiate the Prefabs to the Scene. 45 | 46 | ![Scene View with Prefab Brush](images/PrefabBrush.png) 47 | 48 | ## Implementation 49 | 50 | The Prefab Brush inherits from the Grid Brush and implements the following overrides: 51 | 52 | - It overrides the `Paint` method to paint a Prefab from the Prefab selection. 53 | - It overrides the `Erase` method to be able to erase the instantiated Prefabs or other GameObjects from the Scene. -------------------------------------------------------------------------------- /Documentation~/RandomBrush.md: -------------------------------------------------------------------------------- 1 | # Random Brush 2 | 3 | This Brush places random Tiles onto a Tilemap by selecting from defined **Tile Sets** while painting onto the the Tilemap. Use this as an example to create custom Brushes which store specific data per Brush, and to make Brushes with randomized painting behavior. 4 | 5 | ## Properties 6 | 7 | | Property | Function | 8 | | ----------------------- | ------------------------------------------------------------ | 9 | | __Pick Random Tiles__ | Enable this property to pick the Tiles from the current selection as a random Tile Set. | 10 | | __Add To Random Tiles__ | Enable this property to add the picked Tile Sets to existing Tile Sets instead of replacing them. | 11 | | __Tile Set Size__ | Set the size of the Tile Set that is painted by this Brush. | 12 | | __Number of Tiles__ | The number of Tile Sets. | 13 | | __Tile Set__ | The Tile Set to randomize from | 14 | | __Tiles__ | The Tiles in the Tile Set. | 15 | 16 | ## Usage 17 | 18 | To create a **Tile Set**, first define the size of the Tile Set you want to paint by setting its size values in the **Tile Set Size** property. Then you can add Tile Sets manually with the Brush Editor or select them from an existing Tile Palette. 19 | 20 | To select Tile Sets from an existing [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Palette.html), enable the __Pick Random Tiles__ property and select the Tile Sets using the [Picker Tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Picker). This will create a Tile Set, or multiple Sets if the picked size is larger than the size set in the **Tile Set Size** property. Enable the __Add To Random Tiles__ property to add a picked selection of Tiles onto new or existing Tile Sets instead of replacing them. 21 | 22 | ![Brush Editor with Random Brush](images/RandomBrushTileSet.png)
In this example, 3 Tile Sets of 1x2 are created. 23 | 24 | When painting with the Random Brush, the Random Brush will randomly pick from the available Tile Sets while painting the Tiles. 25 | 26 | ![Scene View with Random Brush](images/RandomBrush.png) 27 | 28 | ## Implementation 29 | 30 | The Random Brush inherits from the Grid Brush and implements the following overrides: 31 | 32 | - It overrides the Paint method to paint random selections of Tiles from chosen Tile Sets. 33 | - It overrides the Pick method to be able to pick selections of Tiles for the random Tile Sets. 34 | -------------------------------------------------------------------------------- /Documentation~/RandomTile.md: -------------------------------------------------------------------------------- 1 | # Random Tile 2 | 3 | Random Tiles are Tiles which pick a Sprite from a given list of Sprites and a target location pseudo-randomly, and then displays that Sprite. The Sprite displayed for the Tile is randomized based on its location and remains fixed for that specific location. 4 | 5 | ### Properties 6 | 7 | | Property | Function | 8 | | --------------------- | ------------------------------------------------------------ | 9 | | __Number of Sprites__ | Set the number of Sprites to randomize from here. | 10 | | __Sprite *__ | Select the Sprite the Tile can randomly place. | 11 | | __Color__ | Set the color of the Tile. | 12 | | __Collider Type__ | Select the type of [Collider Shape](https://docs.unity3d.com/Manual/class-TilemapCollider2D.html) the Tile will generate. | 13 | 14 | ### Usage 15 | 16 | First set the size of the list of Sprites to choose from by setting the value to the __Number of Sprites__ property in the Random Tile editor window. Then select the Sprites that the Tiles chooses from for each Sprite entry. 17 | 18 | ![Random Tile Editor](images/RandomTileEditor.png) 19 | 20 | Paint the Random Tile onto the Tilemap with the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Painting.html) tools. 21 | 22 | ![Scene View with Random Tile](images/RandomTile.png) -------------------------------------------------------------------------------- /Documentation~/RuleOverrideTile.md: -------------------------------------------------------------------------------- 1 | # Rule Override Tile 2 | 3 | __Contributions by:__ [johnsoncodehk](https://github.com/johnsoncodehk), [Autofire](https://github.com/Autofire) 4 | 5 | __Rule Override Tiles__ are Tiles which can override the Sprites and GameObjects for a given [Rule Tile](RuleTile.md) while maintaining the Rule set of the Rule Tile. This allows you to create Tiles that provide variations of a Rule Tile without setting new Rules. 6 | 7 | ## Properties 8 | 9 | | Property | Function | 10 | | ----------------- | ------------------------------------------------------------ | 11 | | __Tile__ | The Rule Tile to override. | 12 | 13 | Depending on the Rule Tile that is overridden, there may be further properties which you can override here. Any public property in the Rule Tile that does not have a `RuleTile.DontOverride` attribute will be shown here and can be overridden. 14 | 15 | ## Usage 16 | 17 | First select the Rule Tile to be overridden in the __Tile__ property. The Editor then displays the different Sprites and GameObjects in the selected Rule Tile which you can override. 18 | 19 | The editor displays the original Sprites that are used in the Rule Tile in the left column. Select the Sprites that override each of the respective original Sprites on the right ‘Override’ column. When the Rule Tile has a match that would usually output the original Sprite, it will instead output the override Sprite. 20 | 21 | Below that, the editor displays the original GameObjects that are used in the Rule Tile in the left column. Select the GameObjects that override each of the respective original GameObjects on the right ‘Override’ column. When the Rule Tile has a match that would usually output the original GameObject, it will instead output the override GameObject. 22 | 23 | ![Rule Override Tile Editor](images/RuleOverrideTileEditor.png) 24 | 25 | If you have modified the original Rule Tile and changed the Sprites there, the Rule Override Tile will note that the original Sprites are missing. You can check the original Rule Tile to see if it is set up correctly or set the Override Sprites to None to remove the override. 26 | 27 | ![Rule Override Tile Editor with Missing Original Sprites](images/RuleOverrideTileEditorMissing.png) 28 | 29 | Paint with the Rule Override Tile using the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Painting.html) tools. 30 | 31 | ![Scene View with Rule Override Tile](images/RuleOverrideTile.png) -------------------------------------------------------------------------------- /Documentation~/RuleTile.md: -------------------------------------------------------------------------------- 1 | # Rule Tile 2 | 3 | __Contributions by:__ [johnsoncodehk](https://github.com/johnsoncodehk), [DreadBoy](https://github.com/DreadBoy), [AVChemodanov](https://github.com/AVChemodanov), [DoctorShinobi](https://github.com/DoctorShinobi), [n4n0lix](https://github.com/n4n0lix) 4 | 5 | This is a generic visual Tile that other Tiles such as the [Terrain Tiles](TerrainTile.md), [Pipeline Tile](PipelineTile.md), [Random Tile](RandomTile.md) or [Animated Tiles](AnimatedTile.md) are based on. There are specific types of Rule Tiles for each of the [Tilemap grid types](https://docs.unity3d.com/Manual/class-Grid.html). The default Rule Tile is for the default [Rectangle Grid](https://docs.unity3d.com/Manual/Tilemap-CreatingTilemaps.html) type; the Hexagonal Rule Tile is for the [Hexagonal Grid](https://docs.unity3d.com/Manual/Tilemap-Hexagonal.html) type; and the Isometric Rule Tile is for the [Isometric Grid](https://docs.unity3d.com/Manual/Tilemap-Isometric.html) types. The different types of Rule Tiles all possess the same properties. 6 | 7 | ## Properties 8 | 9 | ![](images/RuleTileEditor.png)
The Rule Tile editor of a Terrain Tile. 10 | 11 | | Property | Function | 12 | | ----------------------- | ------------------------------------------------------- | 13 | | __Default Sprite__ | The default Sprite set when creating a new Rule. | 14 | | __Default GameObject__ | The default GameObject set when creating a new Rule. | 15 | | __Default Collider__ | The default Collider Type set when creating a new Rule. | 16 | 17 | ### Tiling Rules 18 | 19 | ![](images/RuleTileRule.png)
Tiling Rules properties 20 | 21 | | Property | Function | 22 | | -------------- | ------------------------------------------------------------ | 23 | | __Rule__ | The Rule Type for this Rule. | 24 | | __GameObject__ | The GameObject for the Tile which fits this Rule. | 25 | | __Collider__ | The Collider Type for the Tile which fits this Rule | 26 | | __Output__ | The Output for the Tile which fits this Rule. Each Output type has its own properties. | 27 | 28 | ### Output: Fixed 29 | 30 | | Property | Function | 31 | | ---------- | -------------------------------------------------- | 32 | | __Sprite__ | Display this Sprite for Tiles which fit this Rule. | 33 | 34 | ### Output: Random 35 | 36 | | Property | Function | 37 | | ----------- | ------------------------------------------------------------ | 38 | | __Noise__ | The [Perlin noise](https://en.wikipedia.org/wiki/Perlin_noise) factor when placing the Tile. | 39 | | __Shuffle__ | The randomized transform given to the Tile when placing it. | 40 | | __Size__ | The number of Sprites to randomize from. | 41 | | __Sprite__ | The Sprite for the Tile which fits this Rule. A random Sprite will be chosen out of this when placing the Tile. | 42 | 43 | ### Output: Animation 44 | 45 | | Property | Function | 46 | | ---------- | ------------------------------------------------------------ | 47 | | __MinSpeed__ | The minimum speed at which the animation is played. | 48 | | __MaxSpeed__ | The maximum speed at which the animation is played. | 49 | | __Size__ | The number of Sprites in the animation. | 50 | | __Sprite__ | The Sprite for the Tile which fits this Rule. Sprites will be shown in sequence based on the order of the list. | 51 | 52 | ## Editor Properties 53 | 54 | | Property | Function | 55 | | ----------------------- | ------------------------------------------------------- | 56 | | __Extend Neighbor__ | Enabling this allows you to increase the range of neighbors beyond the 3x3 box. | 57 | 58 | ## Setting up a Rule Tile 59 | 60 | Set up the Rule Tile with the required rules with the __Rule Tile editor__. In the Rule Tile editor, you can change, add, duplicate or remove Rules in the **Tiling Rules** list. Click on the + or - buttons to add or remove Rules. If you have a Rule selected, clicking on the + button will allow you to choose between adding a new Rule or duplicating the selected Rule. The newly created Rule will be placed after the current selected Rule. Select and hold the top left corner of each row to drag them up or down to change the order of the Rules in the list. 61 | 62 | ![](images/RuleTileEditor.png)
Rule Tile Editor 63 | 64 | When you add a new Rule, the Rule editor displays the following: the list of Rule properties, a 3x3 box that visualizes the behavior of the set Rules, and a Sprite selector that displays a preview of the selected Sprite. 65 | 66 | ![](images/RuleTileRule.png) 67 | 68 | The 3x3 box represents the neighbors a Tile can have, where the center represents the Tile itself, and the eight bordering cells are its neighboring Tiles in their relative positions to the Tile. Each of the neighboring cells can be set with one of three options: **Don't Care**, **This** and **Not This**. These define the behavior of the Rule Tile towards these Tiles. Edit the 3x3 box to set up the Rule the Tile must match. 69 | 70 | | Options | Rule Tile behavior | 71 | | -------------- | ------------------------------------------------------------ | 72 | | __Don't Care__ | The Rule Tile ignores the contents in this cell. | 73 | | __This__ | The Rule Tile checks if the contents of this cell is an instance of this Rule Tile. If it is an instance, the rule passes. If it is not an instance, the rule fails. | 74 | | __Not This__ | The Rule Tile checks if the contents of this cell is not an instance of this Rule Tile. If it is not an instance, the rule passes. If it is an instance, the rule fails. | 75 | 76 | If all of the neighbors of the Rule Tile match the options set for their respective directions, then the Rule is considered matched and the rest of the Rule properties are applied. 77 | 78 | When the Rule is set to Fixed, the Rule will only match exactly the conditions set for its neighbors. The example below will only match if there are the same Rule Tiles to the left and right of it. 79 | 80 | ![Rule Tile with Fixed Rule](images/RuleTileRuleFixed.png) 81 | 82 | When the Rule is set to ‘Rotated’, the 3x3 box will be rotated 90 degrees each time the Rule fails to match and it will try to match again with this rotated 3x3 box. If the Rule now matches, the contents of this Rule will be applied as well as the rotation required to match the Rule. Use this if you want the Rule to match for the four 90 degree rotations if rotation is possible. 83 | 84 | ![Rule Tile with Rotated Rule](images/RuleTileRuleRotated.png) 85 | 86 | When the Rule is set to Mirror X, Mirror Y or Mirror XY, the 3x3 box will be mirrored in that axis each time the Rule fails to match and it will try to match again with this mirrored 3x3 box. If the Rule now matches, the contents of this Rule will be applied as well as the mirroring required to match the Rule. Use this if you want the Rule to match for the mirrored locations if mirroring is possible. 87 | 88 | ![Rule Tile with Mirror XY Rule](images/RuleTileRuleMirror.png) 89 | 90 | If you want the Rule Tile to have a Random output, you can set the Output to Random. This will allow you to specify a number of input Sprites to randomize from. The rotation of the Sprites can be randomized as well by changing the __Shuffle__ property. 91 | 92 | ![Rule Tile with Random Output](images/RuleTileOutputRandom.png) 93 | 94 | If you want the Rule Tile to output a Sprite Animation, you can set the Output to Animation. This will allow you to specify a number of Sprites to animate sequentially. The speed of the Animation can be randomized as well by changing the __Speed__ property. 95 | 96 | ![Rule Tile with Animation Output](images/RuleTileOutputAnimation.png) 97 | 98 | When Extend Neighbors is enabled, the 3x3 box can be extended to allow for more specific neighbor matching. The Transform rule matching (eg. Rotated, Mirror) will apply for the extended neighbors set. 99 | 100 | ![Rule Tile with Animation Output](images/RuleTileRuleExtendNeighbor.png) 101 | 102 | Paint with the Rule Tile in the same way as other Tiles by using the Tile Palette tools. 103 | 104 | ![Scene View with Rule Tile](images/RuleTile.png) 105 | 106 | For optimization, please set the most common Rule at the top of the list of Rules and follow with next most common Rule and so on. When matching Rules during the placement of the Tile, the Rule Tile algorithm will check the first Rule first, before proceeding with the next Rules. -------------------------------------------------------------------------------- /Documentation~/TableOfContents.md: -------------------------------------------------------------------------------- 1 | * [Overview](index.md) 2 | * [Scriptable Brushes](Brushes.md) 3 | * [GameObject Brush](GameObjectBrush.md) 4 | * [Group Brush](GroupBrush.md) 5 | * [Line Brush](LineBrush.md) 6 | * [Random Brush](RandomBrush.md) 7 | * [Scriptable Tiles](Tiles.md) 8 | * [Animated Tile](AnimatedTile.md) 9 | * [Rule Tile](RuleTile.md) 10 | * [Rule Override Tile](RuleOverrideTile.md) 11 | * [Other](Other.md) 12 | * [Grid Information](GridInformation.md) 13 | * [Custom Rules for Rule Tile](CustomRulesForRuleTile.md) 14 | * [Contributors](Contributors.md) 15 | 16 | -------------------------------------------------------------------------------- /Documentation~/TerrainTile.md: -------------------------------------------------------------------------------- 1 | # Terrain Tile 2 | 3 | Terrain Tiles take into consideration their orthogonal and diagonal neighbors and displays a Sprite depending on whether the neighboring Tile is the same Tile as itself. This is a similar behavior to [Pipeline Tiles](PipelineTile.md). 4 | 5 | ## Properties 6 | 7 | ![Terrain Tile editor](images/TerrainTileEditor.png) 8 | 9 | 10 | 11 | The following properties describe the appearance of Sprites representing terrain or walls. Assign a Sprite that matches the description to each of these properties. 12 | 13 | | Property | Function | 14 | | --------------------------------- | ------------------------------------------------------------ | 15 | | __Filled__ | A Sprite with all sides filled. | 16 | | __Three Sides__ | A Sprite with three sides. | 17 | | __Two Sides and One Corner__ | A Sprite with two sides and one corner without adjacent sides. | 18 | | __Two Adjacent Sides__ | A Sprite with two adjacent sides. | 19 | | __Two Opposite Sides__ | A Sprite with two opposite sides across each other. | 20 | | __One Side and Two Corners__ | A Sprite with a single side and two corners without adjacent sides. | 21 | | __One Side and One Lower Corner__ | A Sprite with one side and a corner in the lower half of the Sprite. | 22 | | __One Side and One Upper Corner__ | A Sprite with one side and a corner in the upper half of the Sprite. | 23 | | __One Side__ | A Sprite with a single side. | 24 | | __Four Corners__ | A Sprite with four unconnected corners without adjacent sides. | 25 | | __Three Corners__ | A Sprite with three corners without adjacent sides. | 26 | | __Two Adjacent Corners__ | A Sprite with two adjacent corners. | 27 | | __Two Opposite Corners__ | A Sprite with two opposite corners across each other. | 28 | | __One Corner__ | A Sprite with a single corner with no adjacent sides. | 29 | | __Empty__ | A Sprite without any terrain. | 30 | 31 | ## Usage 32 | 33 | Set up a Terrain Tile by select Sprites which fit the characteristics stated on the left of the Terrain Tile editor. As you paint with the Terrain Tile using the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Palette.html) tools, the Tile Sprite automatically adjusts to the appropriate one relative to its position with neighboring Tiles. 34 | 35 | ![Scene View with Terrain Tile](images/TerrainTile.png) -------------------------------------------------------------------------------- /Documentation~/Tiles.md: -------------------------------------------------------------------------------- 1 | # Scriptable Tiles 2 | 3 | You can script Tiles to adapt to different criteria and conditions, such as its position on the Tilemap. It then displays the Sprite which meets its scripted requirements. This allows you to create different Tiles that can help you save time and be more efficient when creating Tilemaps. Refer to the [Scriptable Tiles](https://docs.unity3d.com/Manual/Tilemap-ScriptableTiles.html) page for more information. 4 | 5 | The following **Scriptable Tiles** are included in this package, with examples of how they are implemented. You can use these Tiles as the base for your own custom Tiles as well. 6 | 7 | 8 | - [Animated Tile](AnimatedTile.md) 9 | - [Rule Tile](RuleTile.md) 10 | - [Rule Override Tile](RuleOverrideTile.md) 11 | 12 | -------------------------------------------------------------------------------- /Documentation~/TintBrush.md: -------------------------------------------------------------------------------- 1 | # Tint Brush 2 | 3 | This Brush changes the color of Tiles placed on a Tilemap to the color selected. 4 | 5 | ## Properties 6 | 7 | | Property | Function | 8 | | --------- | ----------------------------- | 9 | | __Color__ | Select the Color of the tint. | 10 | 11 | ## Usage 12 | 13 | Select the color to tint a Tile with in the Brush properties. Then use the Paint tool with the Brush to change the color of the Tiles you paint over. 14 | 15 | ![Scene View with Tint Brush](images/TintBrush.png) 16 | 17 | ## Implementation 18 | 19 | The Tint Brush inherits from the Grid Brush and implements the following overrides: 20 | 21 | - It overrides the `Paint` method to set the color of a Tile. 22 | - It overrides the `Erase` method to be able to set the color of a Tile back to the default white color. -------------------------------------------------------------------------------- /Documentation~/TintBrushSmooth.md: -------------------------------------------------------------------------------- 1 | # Tint Brush (Smooth) 2 | 3 | This advanced Tint Brush interpolates tint color per-cell. This requires the use of a custom Shader (see TintedTilemap.shader in the package contents) and the helper component **TileTextureGenerator**. 4 | 5 | ## Properties 6 | 7 | | Property | Function | 8 | | --------- | ------------------------------------------------------------ | 9 | | __Color__ | Select the color of the tint. | 10 | | __Blend__ | Factor to blend the color of a Tile with this Brush's __Color__. | 11 | 12 | ## Usage 13 | 14 | First set the [Tilemap Renderer](https://docs.unity3d.com/Manual/class-TilemapRenderer.html)'s __Material__ to the TintedTilemap.shader. Add the __Tile Texture Generator__ component to the Tilemap Renderer as well. Then select the desired tint color in the __Color__ property or pick the color from an existing Tile. 15 | 16 | Adjust the __Blend__ property to blend the chosen color with the original color of the Tile. A lower value weighs the new color with the existing color of the Tile, while a higher value weighs the new color with the color of the Brush. 17 | 18 | With the Brush selected, paint Tiles with the [Paintbbrush tool](https://docs.unity3d.com/Manual/Tilemap-Painting.html#Brush) to change their color. 19 | 20 | ![Scene View with Tint Brush (Smooth)](images/TintBrushSmooth.png) 21 | 22 | ## Implementation 23 | 24 | The TintBrushSmooth inherits from the GridBrushBase and implements the following overrides: 25 | 26 | - It overrides the `Paint` method to set the color of a Tile. 27 | - It overrides the `Erase` method to be able to set the color of a Tile back to the default white color. 28 | - It overrides the `Pick` method to pick the color of a Tile. -------------------------------------------------------------------------------- /Documentation~/WeightedRandomTile.md: -------------------------------------------------------------------------------- 1 | # Weighted Random Tile 2 | 3 | __Contributions by:__ [nicovain](https://github.com/nicovain), [distantcam](https://github.com/distantcam) 4 | 5 | Weighted Random Tiles are Tiles which randomly pick a Sprite from a given list of Sprites and displays that Sprite at the target location. Adjusting the __Weight__ value of the Sprites changes their probability of appearing. The Sprite displayed for the Tile is randomized based on its location and remains fixed for that particular location. 6 | 7 | ## Properties 8 | 9 | ![Weighted Random Tile Editor](images/WeightedRandomTileEditor.png) 10 | 11 | | Property | Function | 12 | | --------------------- | ------------------------------------------------------------ | 13 | | __Number of Sprites__ | The number of Sprites to randomize from. | 14 | | __Sprite__ | A Sprite that is in the randomize pool. | 15 | | __Weight__ | A Weight value of the Sprite that affects its probability of appearing. | 16 | | __Color__ | The color of the Tile. | 17 | | __Collider Type__ | The __Collider Shape__ generated by the Tile. | 18 | 19 | ## Usage 20 | 21 | Select the Sprites to randomize from in the Weighted Random Tile editor. The Weight of each Sprite determines the probability of the appearance of the Sprite where the higher the weight, the higher the probability of appearance. Paint the Weighted Random Tile onto the Tilemap with the [Tile Palette](https://docs.unity3d.com/Manual/Tilemap-Palette.html) tools. 22 | 23 | ![Scene View with Weighted Random Tile](images/WeightedRandomTile.png) -------------------------------------------------------------------------------- /Documentation~/images/AdvancedRuleOverrideTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/AdvancedRuleOverrideTile.png -------------------------------------------------------------------------------- /Documentation~/images/AdvancedRuleOverrideTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/AdvancedRuleOverrideTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/AnimatedTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/AnimatedTile.png -------------------------------------------------------------------------------- /Documentation~/images/AnimatedTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/AnimatedTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/BrushDropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/BrushDropdown.png -------------------------------------------------------------------------------- /Documentation~/images/CoordinateBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/CoordinateBrush.png -------------------------------------------------------------------------------- /Documentation~/images/GameObjectBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/GameObjectBrush.png -------------------------------------------------------------------------------- /Documentation~/images/GroupBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/GroupBrush.png -------------------------------------------------------------------------------- /Documentation~/images/LineBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/LineBrush.png -------------------------------------------------------------------------------- /Documentation~/images/LineBrushFillGaps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/LineBrushFillGaps.png -------------------------------------------------------------------------------- /Documentation~/images/PipelineTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/PipelineTile.png -------------------------------------------------------------------------------- /Documentation~/images/PipelineTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/PipelineTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/PrefabBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/PrefabBrush.png -------------------------------------------------------------------------------- /Documentation~/images/PrefabBrushEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/PrefabBrushEditor.png -------------------------------------------------------------------------------- /Documentation~/images/RandomBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RandomBrush.png -------------------------------------------------------------------------------- /Documentation~/images/RandomBrushTileSet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RandomBrushTileSet.png -------------------------------------------------------------------------------- /Documentation~/images/RandomTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RandomTile.png -------------------------------------------------------------------------------- /Documentation~/images/RandomTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RandomTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/RuleOverrideTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleOverrideTile.png -------------------------------------------------------------------------------- /Documentation~/images/RuleOverrideTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleOverrideTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/RuleOverrideTileEditorAdvanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleOverrideTileEditorAdvanced.png -------------------------------------------------------------------------------- /Documentation~/images/RuleOverrideTileEditorMissing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleOverrideTileEditorMissing.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTile.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileOutputAnimation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileOutputAnimation.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileOutputRandom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileOutputRandom.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRule.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRuleExtendNeighbor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRuleExtendNeighbor.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRuleFixed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRuleFixed.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRuleMirror.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRuleMirror.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRuleRotated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRuleRotated.png -------------------------------------------------------------------------------- /Documentation~/images/RuleTileRuleTip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/RuleTileRuleTip.png -------------------------------------------------------------------------------- /Documentation~/images/TerrainTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/TerrainTile.png -------------------------------------------------------------------------------- /Documentation~/images/TerrainTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/TerrainTileEditor.png -------------------------------------------------------------------------------- /Documentation~/images/TintBrush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/TintBrush.png -------------------------------------------------------------------------------- /Documentation~/images/TintBrushSmooth.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/TintBrushSmooth.png -------------------------------------------------------------------------------- /Documentation~/images/WeightedRandomTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/WeightedRandomTile.png -------------------------------------------------------------------------------- /Documentation~/images/WeightedRandomTileEditor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Documentation~/images/WeightedRandomTileEditor.png -------------------------------------------------------------------------------- /Documentation~/index.md: -------------------------------------------------------------------------------- 1 | # 2D Tilemap Extras 2 | 3 | The 2D Tilemap Extras package contains reusable 2D and Tilemap editor scripts which you can use for your own Projects, and as the basis for your own custom Brushes and Tiles. You can freely customize the behavior of the scripts to create new Brushes that suit different uses or scenarios. To find these additional Brushes, open the Tile Palette window (menu: __Window > 2D > Tile Palette__) and open the Brush drop-down menu near the bottom of the editor. Select from the available Brush options for different effects. 4 | 5 | ![](images/BrushDropdown.png) 6 | 7 | The source code for these scripts can be found in the repository [2d-extras](https://github.com/Unity-Technologies/2d-extras "2d-extras: Extras for 2d features"), and examples of the implemented scripts can be found in the sister repository [2d-techdemos](https://github.com/Unity-Technologies/2d-techdemos "2d-techdemos: Examples for 2d features"). 8 | 9 | ## Scriptable Brushes 10 | 11 | - [GameObject](GameObjectBrush.md): This Brush instances, places and manipulates GameObjects onto the Scene. Use this as an example to create Brushes which targets GameObjects, other than Tiles, for instancing and manipulation. 12 | 13 | - [Group](GroupBrush.md): This Brush picks groups of Tiles based on their positions relative to each other. Adjust the size of groups the Brush picks by setting the Gap and Limit properties. Use this Brush as an example to create Brushes that pick Tiles based on specific criteria. 14 | 15 | - [Line](LineBrush.md): This Brush draws a line of Tiles between two points onto a Tilemap. Use this as an example to modify Brush painting behavior to make painting more efficient. 16 | 17 | - [Random](RandomBrush.md): This Brush places random Tiles onto a Tilemap. Use this as an example to create Brushes which store specific data per Brush and to make Brushes which randomize behavior. 18 | 19 | ## Scriptable Tiles 20 | 21 | The following are the [Scriptable Tiles](Tiles.md) included in this package. You can create (menu: __Create > Tiles__ ) the following additional Tile types that are included with this package. 22 | 23 | - [Animated](AnimatedTile.md): This Tile runs through and displays a list of Sprites in sequence to create a frame-by-frame animation. 24 | - [Rule Tile](RuleTile.md): This is a generic visual Tile that accepts rules you create with the __Tiling Rules__ editor to create different Tilesets. Rule Tiles are the basis of the Terrain, Pipeline, Random or Animated Tiles. There are different types of Rule Tiles for each of the [Tilemap grid types](https://docs.unity3d.com/Manual/class-Grid.html). The default Rule Tile is only used with the Rectangle Grid type Tilemap, while the Hexagonal and Isometric Rule Tiles are used with their respective Grid types. 25 | - __Hexagonal Rule Tile__: A Rule Tile for [Hexagonal Grids](https://docs.unity3d.com/Documentation/Manual/Tilemap-Hexagonal.html). Enable the **Flat Top** property for a Flat Top Hexagonal Grid, or clear it for a Pointed Top Hexagonal Grid. 26 | - __Isometric Rule Tile__: A Rule Tile for use with [Isometric Grids](https://docs.unity3d.com/Documentation/Manual/Tilemap-Isometric-CreateIso.html). 27 | - [Rule Override Tile](RuleOverrideTile.md): This Tile can override Sprites and GameObjects for a given [Rule Tile](RuleTile.md) to provide different behaviour without changing the original Rules. 28 | - [Advanced Rule Override Tile](AdvancedRuleOverrideTile.md): This Tile can override a subset of Rules for a given [Rule Tile](RuleTile.md) to provide specialized behavior, while keeping the rest of the original Rules intact. 29 | 30 | ## Other 31 | 32 | - [GridInformation](GridInformation.md): A simple MonoBehavior that stores and provides information based on Grid positions and keywords. 33 | - [Custom Rules for RuleTile](CustomRulesForRuleTile.md): This helps to create new custom Rules for the Rule Tile with more options. -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58147b5e82a62ad4aacd2cfa2ef653bc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b56ed00274c3c354593c893dbb7264c6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/CoordinateBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f770bfc3e11779c4dac1955be8899365 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/CoordinateBrush/CoordinateBrush.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UnityEditor.Tilemaps 4 | { 5 | /// 6 | /// This Brush displays the cell coordinates it is targeting in the SceneView. 7 | /// Use this as an example to create brushes which have extra visualization features when painting onto a Tilemap. 8 | /// 9 | [CustomGridBrush(true, false, false, "Coordinate Brush")] 10 | public class CoordinateBrush : GridBrush 11 | { 12 | } 13 | 14 | /// 15 | /// The Brush Editor for a Coordinate Brush. 16 | /// 17 | [CustomEditor(typeof(CoordinateBrush))] 18 | public class CoordinateBrushEditor : GridBrushEditor 19 | { 20 | /// 21 | /// Callback for painting the GUI for the GridBrush in the Scene View. 22 | /// The CoordinateBrush Editor overrides this to draw the current coordinates of the brush. 23 | /// 24 | /// Grid that the brush is being used on. 25 | /// Target of the GridBrushBase::ref::Tool operation. By default the currently selected GameObject. 26 | /// Current selected location of the brush. 27 | /// Current GridBrushBase::ref::Tool selected. 28 | /// Whether brush is being used. 29 | public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) 30 | { 31 | base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing); 32 | 33 | var labelText = "Pos: " + position.position; 34 | if (position.size.x > 1 || position.size.y > 1) { 35 | labelText += " Size: " + position.size; 36 | } 37 | 38 | Handles.Label(grid.CellToWorld(position.position), labelText); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Editor/Brushes/CoordinateBrush/CoordinateBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d283e353fe1f4c34f8ac458281740fb4 3 | timeCreated: 1499149770 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/GameObjectBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 122c3790d8f747345a2c265e1d0b6fc2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/GameObjectBrush/GameObjectBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0abded712ad706044a53ef292972edbb 3 | timeCreated: 1501700935 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/GroupBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7780fefa5c524be4d9f1151a0cd89ae1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/GroupBrush/GroupBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eec4c0c21e439e04083398ccd1928db0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Brushes/LineBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aebb69cf5dff0af40889258ae645be7a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/LineBrush/LineBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6210598a979f8724a8dac4531c428889 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a616f75a0128f4349bfbedb608a30c03 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/BasePrefabBrush.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | /// 7 | /// This base class for PrefabBrushes that contains common functionality 8 | /// 9 | public class BasePrefabBrush : GridBrush 10 | { /// 11 | /// Anchor Point of the Instantiated Prefab in the cell when painting 12 | /// 13 | public Vector3 m_Anchor = new Vector3(0.5f, 0.5f, 0.5f); 14 | 15 | /// 16 | /// Gets all children of the parent Transform which are within the given Grid's cell position. 17 | /// 18 | /// Grid to determine cell position. 19 | /// Parent transform to get child Objects from. 20 | /// Cell position to get Objects from. 21 | /// A list of GameObjects within the given Grid's cell position. 22 | protected List GetObjectsInCell(GridLayout grid, Transform parent, Vector3Int position) 23 | { 24 | var results = new List(); 25 | var childCount = parent.childCount; 26 | var anchorCellOffset = Vector3Int.FloorToInt(m_Anchor); 27 | var cellSize = grid.cellSize; 28 | anchorCellOffset.x = cellSize.x == 0 ? 0 : anchorCellOffset.x; 29 | anchorCellOffset.y = cellSize.y == 0 ? 0 : anchorCellOffset.y; 30 | anchorCellOffset.z = cellSize.z == 0 ? 0 : anchorCellOffset.z; 31 | for (var i = 0; i < childCount; i++) 32 | { 33 | var child = parent.GetChild(i); 34 | if (position == grid.WorldToCell(child.position) - anchorCellOffset) 35 | { 36 | results.Add(child.gameObject); 37 | } 38 | } 39 | return results; 40 | } 41 | 42 | /// 43 | /// Instantiates a Prefab into the given Grid's cell position parented to the brush target. 44 | /// 45 | /// Grid to determine cell position. 46 | /// Target to instantiate child to. 47 | /// Cell position to instantiate to. 48 | /// Prefab to instantiate. 49 | protected void InstantiatePrefabInCell(GridLayout grid, GameObject brushTarget, Vector3Int position, GameObject prefab, Quaternion rotation = default) 50 | { 51 | var instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab); 52 | if (instance != null) 53 | { 54 | Undo.MoveGameObjectToScene(instance, brushTarget.scene, "Paint Prefabs"); 55 | Undo.RegisterCreatedObjectUndo((Object)instance, "Paint Prefabs"); 56 | 57 | Undo.SetTransformParent(instance.transform, brushTarget.transform, "Paint Prefabs: Modify parent"); 58 | instance.transform.position = grid.LocalToWorld(grid.CellToLocalInterpolated(position + m_Anchor)); 59 | instance.transform.rotation = rotation; 60 | } 61 | } 62 | } 63 | 64 | /// 65 | /// The Base Brush Editor for a Prefab Brush. 66 | /// 67 | public class BasePrefabBrushEditor : GridBrushEditor 68 | { 69 | private SerializedProperty m_Anchor; 70 | 71 | /// 72 | /// SerializedObject representation of the target Prefab Brush 73 | /// 74 | protected SerializedObject m_SerializedObject; 75 | 76 | /// 77 | /// OnEnable for the BasePrefabBrushEditor 78 | /// 79 | protected override void OnEnable() 80 | { 81 | base.OnEnable(); 82 | m_SerializedObject = new SerializedObject(target); 83 | m_Anchor = m_SerializedObject.FindProperty("m_Anchor"); 84 | } 85 | 86 | /// 87 | /// Callback for painting the inspector GUI for the PrefabBrush in the Tile Palette. 88 | /// The PrefabBrush Editor overrides this to have a custom inspector for this Brush. 89 | /// 90 | public override void OnPaintInspectorGUI() 91 | { 92 | m_SerializedObject.UpdateIfRequiredOrScript(); 93 | EditorGUILayout.PropertyField(m_Anchor); 94 | m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/BasePrefabBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71e49d8cb93a4e46b07eea7c8dd2186b 3 | timeCreated: 1584030887 -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/BrushMenuItem.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UnityEditor.Tilemaps 4 | { 5 | static internal partial class AssetCreation 6 | { 7 | [MenuItem("Assets/Create/2D/Brushes/Prefab Brush", priority = (int) EBrushMenuItemOrder.PrefabBrush)] 8 | static void CreatePrefabBrush() 9 | { 10 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Prefab Brush.asset"); 11 | } 12 | 13 | [MenuItem("Assets/Create/2D/Brushes/Prefab Random Brush", 14 | priority = (int) EBrushMenuItemOrder.PrefabRandomBrush)] 15 | static void CreatePrefabRandomBrush() 16 | { 17 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), 18 | "New Prefab Random Brush.asset"); 19 | } 20 | 21 | [MenuItem("Assets/Create/2D/Brushes/Random Brush", priority = (int) EBrushMenuItemOrder.RandomBrush)] 22 | static void CreateRandomBrush() 23 | { 24 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Random Brush.asset"); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/BrushMenuItem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 083cc01539b3849bea2ad657b333981d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d6d2cdd834b42ac8b0666be436db917 3 | timeCreated: 1584030876 -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabBrush/PrefabBrush.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | /// 7 | /// This Brush instances and places a containing prefab onto the targeted location and parents the instanced object to the paint target. 8 | /// 9 | [CustomGridBrush(false, true, false, "Prefab Brush")] 10 | public class PrefabBrush : BasePrefabBrush 11 | { 12 | #pragma warning disable 0649 13 | /// 14 | /// The selection of Prefab to paint from 15 | /// 16 | [SerializeField] GameObject m_Prefab; 17 | Quaternion m_Rotation = default; 18 | 19 | #pragma warning restore 0649 20 | 21 | /// 22 | /// If true, erases any GameObjects that are in a given position within the selected layers with Erasing. 23 | /// Otherwise, erases only GameObjects that are created from owned Prefab in a given position within the selected layers with Erasing. 24 | /// 25 | bool m_EraseAnyObjects; 26 | 27 | /// 28 | /// Rotates the brush in the given direction. 29 | /// 30 | /// Direction to rotate by. 31 | /// Cell Layout for rotating. 32 | public override void Rotate(RotationDirection direction, GridLayout.CellLayout layout) 33 | { 34 | var angle = layout == GridLayout.CellLayout.Hexagon ? 60f : 90f; 35 | m_Rotation = Quaternion.Euler(0f, 0f, direction == RotationDirection.Clockwise ? m_Rotation.eulerAngles.z + angle : m_Rotation.eulerAngles.z - angle); 36 | } 37 | 38 | /// 39 | /// Paints GameObject from containing Prefab into a given position within the selected layers. 40 | /// The PrefabBrush overrides this to provide Prefab painting functionality. 41 | /// 42 | /// Grid used for layout. 43 | /// Target of the paint operation. By default the currently selected GameObject. 44 | /// The coordinates of the cell to paint data to. 45 | public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position) 46 | { 47 | var objectsInCell = GetObjectsInCell(grid, brushTarget.transform, position); 48 | var existPrefabObjectInCell = objectsInCell.Any(objectInCell => PrefabUtility.GetCorrespondingObjectFromSource(objectInCell) == m_Prefab); 49 | 50 | if (!existPrefabObjectInCell) 51 | { 52 | base.InstantiatePrefabInCell(grid, brushTarget, position, m_Prefab, m_Rotation); 53 | } 54 | } 55 | 56 | /// 57 | /// Paints the PrefabBrush instance's prefab into all positions specified by the box fill tool. 58 | /// 59 | /// Grid used for layout. 60 | /// Target of the box fill operation. By default the currently selected GameObject. 61 | /// The cooridnate boundries to fill. 62 | public override void BoxFill(GridLayout grid, GameObject brushTarget, BoundsInt bounds) 63 | { 64 | foreach(Vector3Int tilePosition in bounds.allPositionsWithin) 65 | Paint(grid, brushTarget, tilePosition); 66 | } 67 | 68 | public override void BoxErase(GridLayout grid, GameObject brushTarget, BoundsInt bounds) 69 | { 70 | foreach (Vector3Int tilePosition in bounds.allPositionsWithin) 71 | Erase(grid, brushTarget, tilePosition); 72 | } 73 | 74 | /// 75 | /// If "Erase Any Objects" is true, erases any GameObjects that are in a given position within the selected layers. 76 | /// If "Erase Any Objects" is false, erases only GameObjects that are created from owned Prefab in a given position within the selected layers. 77 | /// The PrefabBrush overrides this to provide Prefab erasing functionality. 78 | /// 79 | /// Grid used for layout. 80 | /// Target of the erase operation. By default the currently selected GameObject. 81 | /// The coordinates of the cell to erase data from. 82 | public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position) 83 | { 84 | foreach (var objectInCell in GetObjectsInCell(grid, brushTarget.transform, position)) 85 | { 86 | if (m_EraseAnyObjects || PrefabUtility.GetCorrespondingObjectFromSource(objectInCell) == m_Prefab) 87 | { 88 | Undo.DestroyObjectImmediate(objectInCell); 89 | } 90 | } 91 | } 92 | 93 | /// 94 | /// Pick prefab from selected Tilemap, given the coordinates of the cells. 95 | /// 96 | public override void Pick(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, Vector3Int pickStart) 97 | { 98 | if (brushTarget == null) 99 | { 100 | return; 101 | } 102 | foreach (var objectInCell in GetObjectsInCell(gridLayout, brushTarget.transform, position.position)) 103 | { 104 | if (objectInCell) 105 | { 106 | m_Prefab = PrefabUtility.GetCorrespondingObjectFromSource(objectInCell); 107 | } 108 | } 109 | } 110 | 111 | /// 112 | /// The Brush Editor for a Prefab Brush. 113 | /// 114 | [CustomEditor(typeof(PrefabBrush))] 115 | public class PrefabBrushEditor : BasePrefabBrushEditor 116 | { 117 | private PrefabBrush prefabBrush => target as PrefabBrush; 118 | private SerializedProperty m_Prefab; 119 | 120 | /// 121 | /// OnEnable for the PrefabBrushEditor 122 | /// 123 | protected override void OnEnable() 124 | { 125 | base.OnEnable(); 126 | m_Prefab = m_SerializedObject.FindProperty(nameof(m_Prefab)); 127 | } 128 | 129 | /// 130 | /// Callback for painting the inspector GUI for the PrefabBrush in the Tile Palette. 131 | /// The PrefabBrush Editor overrides this to have a custom inspector for this Brush. 132 | /// 133 | public override void OnPaintInspectorGUI() 134 | { 135 | const string eraseAnyObjectsTooltip = 136 | "If true, erases any GameObjects that are in a given position " + 137 | "within the selected layers with Erasing. " + 138 | "Otherwise, erases only GameObjects that are created " + 139 | "from owned Prefab in a given position within the selected layers with Erasing."; 140 | 141 | base.OnPaintInspectorGUI(); 142 | 143 | m_SerializedObject.UpdateIfRequiredOrScript(); 144 | EditorGUILayout.PropertyField(m_Prefab, true); 145 | prefabBrush.m_EraseAnyObjects = EditorGUILayout.Toggle( 146 | new GUIContent("Erase Any Objects", eraseAnyObjectsTooltip), 147 | prefabBrush.m_EraseAnyObjects); 148 | 149 | m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); 150 | } 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabBrush/PrefabBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d5751a2c961df945a34295ccf5e576d 3 | timeCreated: 1501681786 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabRandomBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f8a67fc3786cfca4baa247e99c9c77ad 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabRandomBrush/PrefabRandomBrush.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | /// 7 | /// This Brush instances and places a randomly selected Prefabs onto the targeted location and parents the instanced object to the paint target. Use this as an example to quickly place an assorted type of GameObjects onto structured locations. 8 | /// 9 | [CustomGridBrush(false, true, false, "Prefab Random Brush")] 10 | public class PrefabRandomBrush : BasePrefabBrush 11 | { 12 | private const float k_PerlinOffset = 100000f; 13 | 14 | #pragma warning disable 0649 15 | /// 16 | /// The selection of Prefabs to paint from 17 | /// 18 | [SerializeField] GameObject[] m_Prefabs; 19 | 20 | /// 21 | /// Factor for distribution of choice of Prefabs to paint 22 | /// 23 | [SerializeField] float m_PerlinScale = 0.5f; 24 | #pragma warning restore 0649 25 | 26 | /// 27 | /// If true, erases any GameObjects that are in a given position within the selected layers with Erasing. 28 | /// Otherwise, erases only GameObjects that are created from owned Prefab in a given position within the selected layers with Erasing. 29 | /// 30 | bool m_EraseAnyObjects; 31 | 32 | /// 33 | /// Paints GameObject from containg Prefabs with randomly into a given position within the selected layers. 34 | /// The PrefabRandomBrush overrides this to provide Prefab painting functionality. 35 | /// 36 | /// Grid used for layout. 37 | /// Target of the paint operation. By default the currently selected GameObject. 38 | /// The coordinates of the cell to paint data to. 39 | public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position) 40 | { 41 | // Do not allow editing palettes 42 | if (brushTarget == null || brushTarget.layer == 31) 43 | { 44 | return; 45 | } 46 | 47 | var objectsInCell = GetObjectsInCell(grid, brushTarget.transform, position); 48 | var existPrefabObjectInCell = objectsInCell.Any(objectInCell => 49 | { 50 | return m_Prefabs.Any(prefab => PrefabUtility.GetCorrespondingObjectFromSource(objectInCell) == prefab); 51 | }); 52 | 53 | if (!existPrefabObjectInCell) 54 | { 55 | var index = Mathf.Clamp(Mathf.FloorToInt(GetPerlinValue(position, m_PerlinScale, k_PerlinOffset) * m_Prefabs.Length), 0, m_Prefabs.Length - 1); 56 | var prefab = m_Prefabs[index]; 57 | base.InstantiatePrefabInCell(grid, brushTarget, position, prefab); 58 | } 59 | } 60 | 61 | /// 62 | /// If "Erase Any Objects" is true, erases any GameObjects that are in a given position within the selected layers. 63 | /// If "Erase Any Objects" is false, erases only GameObjects that are created from owned Prefab in a given position within the selected layers. 64 | /// The PrefabRandomBrush overrides this to provide Prefab erasing functionality. 65 | /// 66 | /// Grid used for layout. 67 | /// Target of the erase operation. By default the currently selected GameObject. 68 | /// The coordinates of the cell to erase data from. 69 | public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position) 70 | { 71 | if (brushTarget.layer == 31 || brushTarget.transform == null) 72 | { 73 | return; 74 | } 75 | 76 | foreach (var objectInCell in GetObjectsInCell(grid, brushTarget.transform, position)) 77 | { 78 | foreach (var prefab in m_Prefabs) 79 | { 80 | if (objectInCell != null && (m_EraseAnyObjects || PrefabUtility.GetCorrespondingObjectFromSource(objectInCell) == prefab)) 81 | { 82 | Undo.DestroyObjectImmediate(objectInCell); 83 | } 84 | } 85 | } 86 | } 87 | 88 | private static float GetPerlinValue(Vector3Int position, float scale, float offset) 89 | { 90 | return Mathf.PerlinNoise((position.x + offset)*scale, (position.y + offset)*scale); 91 | } 92 | 93 | /// 94 | /// The Brush Editor for a Prefab Brush. 95 | /// 96 | [CustomEditor(typeof(PrefabRandomBrush))] 97 | public class PrefabRandomBrushEditor : BasePrefabBrushEditor 98 | { 99 | private PrefabRandomBrush prefabRandomBrush => target as PrefabRandomBrush; 100 | 101 | private SerializedProperty m_Prefabs; 102 | 103 | /// 104 | /// OnEnable for the PrefabRandomBrushEditor 105 | /// 106 | protected override void OnEnable() 107 | { 108 | base.OnEnable(); 109 | m_Prefabs = m_SerializedObject.FindProperty("m_Prefabs"); 110 | } 111 | 112 | /// 113 | /// Callback for painting the inspector GUI for the PrefabBrush in the Tile Palette. 114 | /// The PrefabBrush Editor overrides this to have a custom inspector for this Brush. 115 | /// 116 | public override void OnPaintInspectorGUI() 117 | { 118 | base.OnPaintInspectorGUI(); 119 | m_SerializedObject.UpdateIfRequiredOrScript(); 120 | prefabRandomBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabRandomBrush.m_PerlinScale, 0.001f, 0.999f); 121 | EditorGUILayout.PropertyField(m_Prefabs, true); 122 | prefabRandomBrush.m_EraseAnyObjects = EditorGUILayout.Toggle("Erase Any Objects", prefabRandomBrush.m_EraseAnyObjects); 123 | m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); 124 | } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Editor/Brushes/PrefabBrushes/PrefabRandomBrush/PrefabRandomBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdc5e1eccedb29e4894bbfab99032590 3 | timeCreated: 1501681786 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/RandomBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4007e34ec02b614b894ce8e20b48644 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/RandomBrush/RandomBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d80edd6caba93514eb01722041fe50b4 3 | timeCreated: 1499223220 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrush.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa3049f8883fd3d418d8a008505b489e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrush/TintBrush.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | using UnityEngine.Tilemaps; 4 | 5 | namespace UnityEditor.Tilemaps 6 | { 7 | /// 8 | /// This Brush changes the color of Tiles placed on a Tilemap. 9 | /// 10 | [CustomGridBrush(true, false, false, "Tint Brush")] 11 | public class TintBrush : GridBrushBase 12 | { 13 | /// 14 | /// Color of the Tile to tint 15 | /// 16 | public Color m_Color = Color.white; 17 | 18 | /// 19 | /// Tints tiles into a given position within the selected layers. 20 | /// The TintBrush overrides this to set the color of the Tile to tint it. 21 | /// 22 | /// Grid used for layout. 23 | /// Target of the paint operation. By default the currently selected GameObject. 24 | /// The coordinates of the cell to paint data to. 25 | public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position) 26 | { 27 | Tilemap tilemap = brushTarget.GetComponent(); 28 | if (tilemap != null) 29 | { 30 | SetColor(tilemap, position, m_Color); 31 | } 32 | } 33 | 34 | /// 35 | /// Resets the color of the tiles in a given position within the selected layers to White. 36 | /// The TintBrush overrides this to set the color of the Tile to White. 37 | /// 38 | /// Grid used for layout. 39 | /// Target of the erase operation. By default the currently selected GameObject. 40 | /// The coordinates of the cell to erase data from. 41 | public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position) 42 | { 43 | Tilemap tilemap = brushTarget.GetComponent(); 44 | if (tilemap != null) 45 | { 46 | SetColor(tilemap, position, Color.white); 47 | } 48 | } 49 | 50 | private static void SetColor(Tilemap tilemap, Vector3Int position, Color color) 51 | { 52 | TileBase tile = tilemap.GetTile(position); 53 | if (tile != null) 54 | { 55 | if ((tilemap.GetTileFlags(position) & TileFlags.LockColor) != 0) 56 | { 57 | if (tile is Tile) 58 | { 59 | Debug.LogWarning("Tint brush cancelled, because Tile (" + tile.name + ") has TileFlags.LockColor set. Unlock it from the Tile asset debug inspector."); 60 | } 61 | else 62 | { 63 | Debug.LogWarning("Tint brush cancelled. because Tile (" + tile.name + ") has TileFlags.LockColor set. Unset it in GetTileData()."); 64 | } 65 | } 66 | 67 | tilemap.SetColor(position, color); 68 | } 69 | } 70 | } 71 | 72 | /// 73 | /// The Brush Editor for a Tint Brush. 74 | /// 75 | [CustomEditor(typeof(TintBrush))] 76 | public class TintBrushEditor : GridBrushEditorBase 77 | { 78 | /// Returns all valid targets that the brush can edit. 79 | /// Valid targets for the TintBrush are any GameObjects with a Tilemap component. 80 | public override GameObject[] validTargets 81 | { 82 | get 83 | { 84 | return GameObject.FindObjectsOfType().Select(x => x.gameObject).ToArray(); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrush/TintBrush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5461c6f43c33cae4e8367042630017f7 3 | timeCreated: 1502200727 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrushSmooth.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d170c661919d6654faecafa5625d9cd6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrushSmooth/TintBrushSmooth.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEngine; 3 | using UnityEngine.Tilemaps; 4 | 5 | namespace UnityEditor.Tilemaps 6 | { 7 | /// 8 | /// Advanced tint brush for interpolated tint color per-cell. Requires the use of custom shader (see TintedTilemap.shader) and helper component TileTextureGenerator. 9 | /// 10 | [CustomGridBrush(false, false, false, "Tint Brush (Smooth)")] 11 | public class TintBrushSmooth : GridBrushBase 12 | { 13 | /// 14 | /// Factor to blend the Color of Tile with its color and this Brush's color 15 | /// 16 | public float m_Blend = 1f; 17 | /// 18 | /// Color of the Tile to tint 19 | /// 20 | public Color m_Color = Color.white; 21 | 22 | /// 23 | /// Tints tiles into a given position within the selected layers. 24 | /// The TintBrushSmooth overrides this to set the color of the Grid position to tint it. 25 | /// 26 | /// Grid used for layout. 27 | /// Target of the paint operation. By default the currently selected GameObject. 28 | /// The coordinates of the cell to paint data to. 29 | public override void Paint(GridLayout grid, GameObject brushTarget, Vector3Int position) 30 | { 31 | TintTextureGenerator generator = GetGenerator(grid); 32 | if (generator != null) 33 | { 34 | var oldColor = generator.GetColor(grid as Grid, position); 35 | var blendColor = oldColor * (1 - m_Blend) + m_Color * m_Blend; 36 | generator.SetColor(grid as Grid, position, blendColor); 37 | } 38 | } 39 | 40 | /// 41 | /// Resets the color of the tiles in a given position within the selected layers to White. 42 | /// The TintBrushSmooth overrides this to set the color of the Grid position to White. 43 | /// 44 | /// Grid used for layout. 45 | /// Target of the erase operation. By default the currently selected GameObject. 46 | /// The coordinates of the cell to erase data from. 47 | public override void Erase(GridLayout grid, GameObject brushTarget, Vector3Int position) 48 | { 49 | TintTextureGenerator generator = GetGenerator(grid); 50 | if (generator != null) 51 | { 52 | generator.SetColor(grid as Grid, position, Color.white); 53 | } 54 | } 55 | 56 | /// 57 | /// Picks the tint color given the coordinates of the cells. 58 | /// The TintBrushSmoot overrides this to provide color picking functionality. 59 | /// 60 | /// Grid to pick data from. 61 | /// Target of the picking operation. By default the currently selected GameObject. 62 | /// The coordinates of the cells to paint data from. 63 | /// Pivot of the picking brush. 64 | public override void Pick(GridLayout grid, GameObject brushTarget, BoundsInt position, Vector3Int pivot) 65 | { 66 | TintTextureGenerator generator = GetGenerator(grid); 67 | if (generator != null) 68 | { 69 | m_Color = generator.GetColor(grid as Grid, position.min); 70 | } 71 | } 72 | 73 | private TintTextureGenerator GetGenerator(GridLayout grid) 74 | { 75 | TintTextureGenerator generator = FindObjectOfType(); 76 | if (generator == null) 77 | { 78 | if (grid != null) 79 | { 80 | generator = grid.gameObject.AddComponent(); 81 | } 82 | } 83 | return generator; 84 | } 85 | } 86 | 87 | /// 88 | /// The Brush Editor for a Tint Brush Smooth. 89 | /// 90 | [CustomEditor(typeof(TintBrushSmooth))] 91 | public class TintBrushSmoothEditor : GridBrushEditorBase 92 | { 93 | /// 94 | /// The TintBrushSmooth for this Editor 95 | /// 96 | public TintBrushSmooth brush { get { return target as TintBrushSmooth; } } 97 | 98 | /// Returns all valid targets that the brush can edit. 99 | /// Valid targets for the TintBrushSmooth are any GameObjects with a Tilemap component. 100 | public override GameObject[] validTargets 101 | { 102 | get 103 | { 104 | return GameObject.FindObjectsOfType().Select(x => x.gameObject).ToArray(); 105 | } 106 | } 107 | 108 | /// 109 | /// Callback for painting the inspector GUI for the TintBrushSmooth in the Tile Palette. 110 | /// The TintBrushSmooth Editor overrides this to have a custom inspector for this Brush. 111 | /// 112 | public override void OnPaintInspectorGUI() 113 | { 114 | brush.m_Color = EditorGUILayout.ColorField("Color", brush.m_Color); 115 | brush.m_Blend = EditorGUILayout.Slider("Blend", brush.m_Blend, 0f, 1f); 116 | GUILayout.Label("Note: Tilemap needs to use TintedTilemap.shader!"); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrushSmooth/TintBrushSmooth.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed363ce3b4856fa408111529bc784318 3 | timeCreated: 1502800385 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Brushes/TintBrushSmooth/TintTextureGeneratorEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | [CustomEditor(typeof(TintTextureGenerator))] 7 | public class TintTextureGeneratorEditor : Editor 8 | { 9 | private static class Styles 10 | { 11 | public static GUIContent tintMapSize = new GUIContent("Tint Map Size", "Size of the Tint Map in cells"); 12 | public static GUIContent scaleFactor = new GUIContent("Scale Factor", "Mapping scale for cells to Tint map texture. Adjust to get better definition."); 13 | } 14 | 15 | private const int k_TextureSizeLimit = 4096; 16 | 17 | private SerializedProperty m_TintMapSize; 18 | private SerializedProperty m_ScaleFactor; 19 | 20 | public void OnEnable() 21 | { 22 | m_TintMapSize = serializedObject.FindProperty("k_TintMapSize"); 23 | m_ScaleFactor = serializedObject.FindProperty("k_ScaleFactor"); 24 | } 25 | 26 | public override void OnInspectorGUI() 27 | { 28 | serializedObject.Update(); 29 | EditorGUILayout.IntSlider(m_TintMapSize, 256, k_TextureSizeLimit, Styles.tintMapSize); 30 | EditorGUILayout.IntSlider(m_ScaleFactor, 1, Math.Min(8, Math.Max(1, k_TextureSizeLimit / m_TintMapSize.intValue)), Styles.scaleFactor); 31 | serializedObject.ApplyModifiedProperties(); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Editor/Brushes/TintBrushSmooth/TintTextureGeneratorEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86a60437712ccf741bcf537b0d1c9bfe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Menu.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 123abb5d8f7434106bb182008cbd5f07 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Menu/CustomRuleTileMenu.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using UnityEditor.Tilemaps; 4 | using UnityEngine; 5 | 6 | namespace UnityEditor 7 | { 8 | static class CustomRuleTileMenu 9 | { 10 | private static string tempCustomRuleTilePath; 11 | private const string customRuleTileScript = 12 | @"using System.Collections; 13 | using System.Collections.Generic; 14 | using UnityEngine; 15 | using UnityEngine.Tilemaps; 16 | 17 | [CreateAssetMenu] 18 | public class #SCRIPTNAME# : RuleTile<#SCRIPTNAME#.Neighbor> { 19 | public bool customField; 20 | 21 | public class Neighbor : RuleTile.TilingRule.Neighbor { 22 | public const int Null = 3; 23 | public const int NotNull = 4; 24 | } 25 | 26 | public override bool RuleMatch(int neighbor, TileBase tile) { 27 | switch (neighbor) { 28 | case Neighbor.Null: return tile == null; 29 | case Neighbor.NotNull: return tile != null; 30 | } 31 | return base.RuleMatch(neighbor, tile); 32 | } 33 | }"; 34 | 35 | [MenuItem("Assets/Create/2D/Tiles/Custom Rule Tile Script", false, (int)ETilesMenuItemOrder.CustomRuleTile)] 36 | static void CreateCustomRuleTile() 37 | { 38 | if (String.IsNullOrEmpty(tempCustomRuleTilePath) || !File.Exists(tempCustomRuleTilePath)) 39 | tempCustomRuleTilePath = FileUtil.GetUniqueTempPathInProject(); 40 | File.WriteAllText(tempCustomRuleTilePath, customRuleTileScript); 41 | ProjectWindowUtil.CreateScriptAssetFromTemplateFile(tempCustomRuleTilePath, "NewCustomRuleTile.cs"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Editor/Menu/CustomRuleTileMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a641ca7aea56f8428c8c6efc8e618cb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Menu/MenuItemOrder.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | internal enum ETilesMenuItemOrder 7 | { 8 | AnimatedTile = 2, 9 | RuleTile = 100, 10 | IsometricRuleTile, 11 | HexagonalRuleTile, 12 | RuleOverrideTile, 13 | AdvanceRuleOverrideTile, 14 | CustomRuleTile, 15 | RandomTile = 200, 16 | WeightedRandomTile, 17 | PipelineTile, 18 | TerrainTile, 19 | } 20 | internal enum EBrushMenuItemOrder 21 | { 22 | RandomBrush = 3, 23 | PrefabBrush, 24 | PrefabRandomBrush 25 | } 26 | 27 | static internal partial class AssetCreation 28 | { 29 | 30 | [MenuItem("Assets/Create/2D/Tiles/Animated Tile", priority = (int) ETilesMenuItemOrder.AnimatedTile)] 31 | static void CreateAnimatedTile() 32 | { 33 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Animated Tile.asset"); 34 | } 35 | 36 | [MenuItem( "Assets/Create/2D/Tiles/Hexagonal Rule Tile", priority = (int)ETilesMenuItemOrder.HexagonalRuleTile)] 37 | static void CreateHexagonalRuleTile() 38 | { 39 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Hexagonal Rule Tile.asset"); 40 | } 41 | 42 | [MenuItem("Assets/Create/2D/Tiles/Isometric Rule Tile", priority = (int)ETilesMenuItemOrder.IsometricRuleTile)] 43 | static void CreateIsometricRuleTile() 44 | { 45 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Isometric Rule Tile.asset"); 46 | } 47 | 48 | [MenuItem("Assets/Create/2D/Tiles/Advanced Rule Override Tile", priority = (int)ETilesMenuItemOrder.AdvanceRuleOverrideTile)] 49 | static void CreateAdvancedRuleOverrideTile() 50 | { 51 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Advanced Rule Override Tile.asset"); 52 | } 53 | 54 | [MenuItem("Assets/Create/2D/Tiles/Rule Override Tile", priority = (int)ETilesMenuItemOrder.RuleOverrideTile)] 55 | static void CreateRuleOverrideTile() 56 | { 57 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Rule Override Tile.asset"); 58 | } 59 | 60 | [MenuItem("Assets/Create/2D/Tiles/Rule Tile", priority = (int)ETilesMenuItemOrder.RuleTile)] 61 | static void CreateRuleTile() 62 | { 63 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Rule Tile.asset"); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Editor/Menu/MenuItemOrder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f11ba7bd032140bfbcd546d93db1548 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f03b3016bcc582043b27ae775025ef88 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/HexagonalRuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b68386deea7c2246bd5fe7bd6fa13c6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/HexagonalRuleTile/HexagonalRuleTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a573a189e85fcd243a32fa6ac742ca44 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/IsometricRuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ee1b1583a594cf47baebcd4a5d46cb9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/IsometricRuleTile/IsometricRuleTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor 5 | { 6 | /// 7 | /// The Editor for an IsometricRuleTile. 8 | /// 9 | [CustomEditor(typeof(IsometricRuleTile), true)] 10 | [CanEditMultipleObjects] 11 | public class IsometricRuleTileEditor : RuleTileEditor 12 | { 13 | /// 14 | /// Gets the index for a Rule with the IsometricRuleTileEditor to display an arrow. 15 | /// 16 | /// The adjacent position of the arrow. 17 | /// Returns the index for a Rule with the IsometricRuleTileEditor to display an arrow 18 | private static readonly int[] s_Arrows = { 3, 0, 1, 6, -1, 2, 7, 8, 5 }; 19 | 20 | /// 21 | /// Gets the index for a Rule with the HexagonalRuleTile to display an arrow. 22 | /// 23 | /// The adjacent position of the arrow. 24 | /// Returns the index for a Rule with the HexagonalRuleTile to display an arrow. 25 | public override int GetArrowIndex(Vector3Int position) 26 | { 27 | return s_Arrows[base.GetArrowIndex(position)]; 28 | } 29 | 30 | /// 31 | /// Gets the GUI matrix size for a Rule of a IsometricRuleTile 32 | /// 33 | /// Cell bounds of the Rule. 34 | /// Returns the GUI matrix size for a Rule of a IsometricRuleTile. 35 | public override Vector2 GetMatrixSize(BoundsInt bounds) 36 | { 37 | float p = Mathf.Pow(2, 0.5f); 38 | float w = (bounds.size.x / p + bounds.size.y / p) * k_SingleLineHeight; 39 | return new Vector2(w, w); 40 | } 41 | 42 | /// 43 | /// Draws a Rule Matrix for the given Rule for a IsometricRuleTile. 44 | /// 45 | /// Tile to draw rule for. 46 | /// GUI Rect to draw rule at. 47 | /// Cell bounds of the Rule. 48 | /// Rule to draw Rule Matrix for. 49 | public override void RuleMatrixOnGUI(RuleTile tile, Rect rect, BoundsInt bounds, RuleTile.TilingRule tilingRule) 50 | { 51 | Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); 52 | float w = rect.width / bounds.size.x; 53 | float h = rect.height / bounds.size.y; 54 | 55 | // Grid 56 | float d = rect.width / (bounds.size.x + bounds.size.y); 57 | for (int y = 0; y <= bounds.size.y; y++) 58 | { 59 | float left = rect.xMin + d * y; 60 | float top = rect.yMin + d * y; 61 | float right = rect.xMax - d * (bounds.size.y - y); 62 | float bottom = rect.yMax - d * (bounds.size.y - y); 63 | Handles.DrawLine(new Vector3(left, bottom), new Vector3(right, top)); 64 | } 65 | for (int x = 0; x <= bounds.size.x; x++) 66 | { 67 | float left = rect.xMin + d * x; 68 | float top = rect.yMax - d * x; 69 | float right = rect.xMax - d * (bounds.size.x - x); 70 | float bottom = rect.yMin + d * (bounds.size.x - x); 71 | Handles.DrawLine(new Vector3(left, bottom), new Vector3(right, top)); 72 | } 73 | Handles.color = Color.white; 74 | 75 | var neighbors = tilingRule.GetNeighbors(); 76 | 77 | // Icons 78 | float iconSize = (rect.width - d) / (bounds.size.x + bounds.size.y - 1); 79 | float iconScale = Mathf.Pow(2, 0.5f); 80 | 81 | for (int y = bounds.yMin; y < bounds.yMax; y++) 82 | { 83 | for (int x = bounds.xMin; x < bounds.xMax; x++) 84 | { 85 | Vector3Int pos = new Vector3Int(x, y, 0); 86 | Vector3Int offset = new Vector3Int(pos.x - bounds.xMin, pos.y - bounds.yMin, 0); 87 | Rect r = new Rect( 88 | rect.xMin + rect.size.x - iconSize * (offset.y - offset.x + 0.5f + bounds.size.x), 89 | rect.yMin + rect.size.y - iconSize * (offset.y + offset.x + 1.5f), 90 | iconSize, iconSize 91 | ); 92 | Vector2 center = r.center; 93 | r.size *= iconScale; 94 | r.center = center; 95 | 96 | RuleMatrixIconOnGUI(tilingRule, neighbors, pos, r); 97 | } 98 | } 99 | } 100 | 101 | /// 102 | /// Determines the current mouse position is within the given Rect. 103 | /// 104 | /// Rect to test mouse position for. 105 | /// True if the current mouse position is within the given Rect. False otherwise. 106 | public override bool ContainsMousePosition(Rect rect) 107 | { 108 | var center = rect.center; 109 | var halfWidth = rect.width / 2; 110 | var halfHeight = rect.height / 2; 111 | var mouseFromCenter = Event.current.mousePosition - center; 112 | var xAbs = Mathf.Abs(Vector2.Dot(mouseFromCenter, Vector2.right)); 113 | var yAbs = Mathf.Abs(Vector2.Dot(mouseFromCenter, Vector2.up)); 114 | return (xAbs / halfWidth + yAbs / halfHeight) <= 1; 115 | } 116 | 117 | /// 118 | /// Updates preview settings for the IsometricRuleTile. 119 | /// 120 | public override void OnPreviewSettings() 121 | { 122 | base.OnPreviewSettings(); 123 | 124 | if (m_PreviewGrid) 125 | { 126 | float height = EditorGUILayout.FloatField("Cell Height", m_PreviewGrid.cellSize.y); 127 | m_PreviewGrid.cellSize = new Vector3(1f, Mathf.Max(height, 0), 1f); 128 | } 129 | } 130 | 131 | /// 132 | /// Creates a Preview for the IsometricRuleTile. 133 | /// 134 | protected override void CreatePreview() 135 | { 136 | base.CreatePreview(); 137 | 138 | m_PreviewGrid.cellSize = new Vector3(1f, 0.5f, 1f); 139 | m_PreviewGrid.cellLayout = GridLayout.CellLayout.Isometric; 140 | 141 | foreach (var tilemapRenderer in m_PreviewTilemapRenderers) 142 | tilemapRenderer.sortOrder = TilemapRenderer.SortOrder.TopRight; 143 | 144 | m_PreviewTilemapRenderers[0].sortingOrder = 0; 145 | m_PreviewTilemapRenderers[1].sortingOrder = -1; 146 | m_PreviewTilemapRenderers[2].sortingOrder = 1; 147 | m_PreviewTilemapRenderers[3].sortingOrder = 0; 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Editor/Tiles/IsometricRuleTile/IsometricRuleTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35a64db21fde55046a6d60c50f766aa7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/Menu.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 50c7c1a06cd3c42629d150afe8235b81 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/Menu/PipelineTileMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | static internal partial class AssetCreation 7 | { 8 | [MenuItem("Assets/Create/2D/Tiles/Pipeline Tile", priority = (int)ETilesMenuItemOrder.PipelineTile)] 9 | static void CreatePipelineTile() 10 | { 11 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Pipeline Tile.asset"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Editor/Tiles/Menu/PipelineTileMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cca55e39f80d432d8f73394b1210999 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/Menu/RandomTileMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | static internal partial class AssetCreation 7 | { 8 | [MenuItem("Assets/Create/2D/Tiles/Random Tile", priority = (int)ETilesMenuItemOrder.RandomTile)] 9 | static void CreateRandomTile() 10 | { 11 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Random Tile.asset"); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Editor/Tiles/Menu/RandomTileMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa22e74a1cea546e2abfc3606a959191 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/Menu/TerrainTileMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | static internal partial class AssetCreation 7 | { 8 | 9 | [MenuItem("Assets/Create/2D/Tiles/Terrain Tile", priority = (int)ETilesMenuItemOrder.TerrainTile)] 10 | static void CreateTerrainTile() 11 | { 12 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Terrain Tile.asset"); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Editor/Tiles/Menu/TerrainTileMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3bb18a640e6c45f7b90b85de9b43926 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/Menu/WeightedRandomTileMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | 4 | namespace UnityEditor.Tilemaps 5 | { 6 | static internal partial class AssetCreation 7 | { 8 | 9 | [MenuItem("Assets/Create/2D/Tiles/Weighted Random Tile", priority = (int)ETilesMenuItemOrder.WeightedRandomTile)] 10 | static void CreateWeightedRandomTile() 11 | { 12 | ProjectWindowUtil.CreateAsset(ScriptableObject.CreateInstance(), "New Weighted Random Tile.asset"); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Editor/Tiles/Menu/WeightedRandomTileMenu.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1cc1aa0485d0449faca8f1ce01ec015 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleOverrideTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a1ce61609bfe5541aea5f933f4a25de 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleOverrideTile/AdvancedRuleOverrideTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd604afe90023492586ef97592e54ba4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleOverrideTile/PopulateRuleOverrideTileWizard.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Tilemaps; 3 | using System.Linq; 4 | using System.Text.RegularExpressions; 5 | using UnityEngine.Scripting.APIUpdating; 6 | 7 | namespace UnityEditor.Tilemaps 8 | { 9 | /// 10 | /// Wizard for populating RuleOverrideTile from a SpriteSheet 11 | /// 12 | [MovedFrom(true, "UnityEditor")] 13 | public class PopulateRuleOverideTileWizard : ScriptableWizard 14 | { 15 | [MenuItem("CONTEXT/RuleOverrideTile/Populate From Sprite Sheet")] 16 | static void MenuOption(MenuCommand menuCommand) 17 | { 18 | PopulateRuleOverideTileWizard.CreateWizard(menuCommand.context as RuleOverrideTile); 19 | } 20 | [MenuItem("CONTEXT/RuleOverrideTile/Populate From Sprite Sheet", true)] 21 | static bool MenuOptionValidation(MenuCommand menuCommand) 22 | { 23 | RuleOverrideTile tile = menuCommand.context as RuleOverrideTile; 24 | return tile.m_Tile; 25 | } 26 | 27 | /// 28 | /// The Texture2D containing the Sprites to override with 29 | /// 30 | public Texture2D m_spriteSet; 31 | 32 | private RuleOverrideTile m_tileset; 33 | 34 | /// 35 | /// Creates a wizard for the target RuleOverrideTIle 36 | /// 37 | /// The RuleOverrideTile to be edited by the wizard 38 | public static void CreateWizard(RuleOverrideTile target) { 39 | PopulateRuleOverideTileWizard wizard = DisplayWizard("Populate Override", "Populate"); 40 | wizard.m_tileset = target; 41 | } 42 | 43 | /// 44 | /// Creates a new PopulateRuleOverideTileWizard and copies the settings from an existing PopulateRuleOverideTileWizard 45 | /// 46 | /// The wizard to copy settings from 47 | public static void CloneWizard(PopulateRuleOverideTileWizard oldWizard) { 48 | PopulateRuleOverideTileWizard wizard = DisplayWizard("Populate Override", "Populate"); 49 | wizard.m_tileset = oldWizard.m_tileset; 50 | wizard.m_spriteSet = oldWizard.m_spriteSet; 51 | } 52 | 53 | private void OnWizardUpdate() { 54 | isValid = m_tileset != null && m_spriteSet != null; 55 | } 56 | 57 | private void OnWizardCreate() { 58 | try { 59 | Populate(); 60 | } 61 | catch(System.Exception ex) { 62 | EditorUtility.DisplayDialog("Auto-populate failed!", ex.Message, "Ok"); 63 | CloneWizard(this); 64 | } 65 | } 66 | 67 | /// 68 | /// Attempts to populate the selected override tile using the chosen sprite. 69 | /// The assumption here is that the sprite set selected by the user has the same 70 | /// naming scheme as the original sprite. That is to say, they should both have the same number 71 | /// of sprites, each sprite ends in an underscore followed by a number, and that they are 72 | /// intended to be equivalent in function. 73 | /// 74 | private void Populate() { 75 | string spriteSheet = AssetDatabase.GetAssetPath(m_spriteSet); 76 | Sprite[] overrideSprites = AssetDatabase.LoadAllAssetsAtPath(spriteSheet).OfType().ToArray(); 77 | 78 | bool finished = false; 79 | 80 | try { 81 | Undo.RecordObject(m_tileset, "Auto-populate " + m_tileset.name); 82 | 83 | foreach(RuleTile.TilingRule rule in m_tileset.m_Tile.m_TilingRules) { 84 | foreach(Sprite originalSprite in rule.m_Sprites) { 85 | string spriteName = originalSprite.name; 86 | string spriteNumber = Regex.Match(spriteName, @"_\d+$").Value; 87 | 88 | Sprite matchingOverrideSprite = overrideSprites.First(sprite => sprite.name.EndsWith(spriteNumber)); 89 | 90 | m_tileset[originalSprite] = matchingOverrideSprite; 91 | } 92 | } 93 | 94 | finished = true; 95 | } 96 | catch(System.InvalidOperationException ex) { 97 | throw (new System.ArgumentOutOfRangeException("Sprite sheet mismatch", ex)); 98 | } 99 | finally { 100 | // We handle the undo like this in case we end up catching more exceptions. 101 | // We want this to ALWAYS happen unless we complete the population. 102 | if(!finished) { 103 | Undo.PerformUndo(); 104 | } 105 | } 106 | } 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleOverrideTile/PopulateRuleOverrideTileWizard.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4dcb91d1bb7d18847b5ce74c4cdb1921 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleOverrideTile/RuleOverrideTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dd977390416471341b10fd1278290da0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fac9738c4893c34785c399d087c715d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Tiles/RuleTile/RuleTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 139f9377103555b49b8dcd62686df3bf 3 | timeCreated: 1501789622 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/Unity.2D.Tilemap.Extras.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.2D.Tilemap.Extras.Editor", 3 | "references": [ 4 | "GUID:613783dc1674e844b87788ea74ede0f6", 5 | "GUID:3a9781db4804a9945b9883f3a7c46d45" 6 | ], 7 | "optionalUnityReferences": [], 8 | "includePlatforms": [ 9 | "Editor" 10 | ], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [], 17 | "versionDefines": [] 18 | } -------------------------------------------------------------------------------- /Editor/Unity.2D.Tilemap.Extras.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cbdf09464b6b87745be748a67e5a21a0 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2D Tilemap Extras copyright © 2020 Unity Technologies ApS 2 | 3 | Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License). 4 | 5 | Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions. 6 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d096e666129ea0247bb05049143ba33a 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /QAReport.md: -------------------------------------------------------------------------------- 1 | # QA Report 2 | Use this file to outline the test strategy for this package. 3 | 4 | ## QA Owner: [*Add Name*] 5 | 6 | ## Test strategy 7 | *Use this section to describe how this feature was tested.* 8 | * A link to the Test Plan (Test Rails, other) 9 | * Results from the package's editor and runtime test suite. 10 | * Link to automated test results (if any) 11 | * Manual test Results, [here's an example](https://docs.google.com/spreadsheets/d/12A76U5Gf969w10KL4Ik0wC1oFIBDUoRrqIvQgD18TFo/edit#gid=0) 12 | * Scenario test week outcome 13 | * etc. 14 | 15 | ## Package Status 16 | Use this section to describe: 17 | * package stability 18 | * known bugs, issues 19 | * performance metrics, 20 | * etc 21 | 22 | In other words, a general feeling on the health of this package. 23 | -------------------------------------------------------------------------------- /QAReport.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ddb995fe98f35a44818e802c99f4b1e 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notice 2 | 3 | ## No more development on 2d-extras GitHub repository 4 | 5 | We are changing how we develop additional 2D Tiles and Brushes for 2D Tilemap. An important part of this change involves ensuring a single point of entry for users to get the latest tiles and brushes for Tilemap. To this end we created the Tilemap Extras package which is accessible from Package Manager. Moving forward, the 2D-extras GitHub repository will be made read-only. You will still be able to clone and pull the contents of the repository as it is right now. 6 | 7 | Tilemap Extras already includes Animated Tiles, RuleTile (Rectangular Isometric and Hexagonal), the Rule Override Tiles, Group Brush, Line Brush, Random Brush and GameObject Brush. It also includes 3 samples covering common use-cases of Rule Tiles and Animated Tiles. Read more about Tilemap Extras in the announcement thread. 8 | 9 | If there is functionality in 2d-extras that is important to your team and your product please let us know in this thread or start a discussion in the 2D forums and we will consider adding it to the Tilemap Extras package. 10 | 11 | For issues with the Tilemap Extras please use the standard Unity channels via the Unity Bug Reporter and/or starting a thread in our forums instead of the GitHub Repository Issues tracker. 12 | 13 | Thank you for all your contributions over the years. As always, let us know about your needs and project plans and we will endeavor to make Tilemap Extras an even better tool for developing 2D games in Unity! 14 | 15 | 16 | # 2d-extras 17 | 18 | 2d-extras is a repository containing helpful reusable scripts which you can use to make your games, with a slant towards 2D. Feel free to customise the behavior of the scripts to create new tools for your use case! 19 | 20 | Implemented examples using these scripts can be found in the sister repository [2d-techdemos](https://github.com/Unity-Technologies/2d-techdemos "2d-techdemos: Examples for 2d features"). 21 | 22 | All items in the repository are grouped by use for a feature and are listed below. 23 | 24 | ## How to use this 25 | 26 | You can use this in two different ways: downloading this repository or adding it to your project's Package Manager manifest. 27 | 28 | Alternatively, you can pick and choose the scripts that you want by placing only these scripts in your project's `Assets` folder. 29 | 30 | ### Download 31 | 32 | #### Setup 33 | Download or clone this repository into your project in the folder `Packages/com.unity.2d.tilemap.extras`. 34 | 35 | ### Package Manager Manifest 36 | 37 | #### Requirements 38 | [Git](https://git-scm.com/) must be installed and added to your path. 39 | 40 | #### Setup 41 | The following line needs to be added to your `Packages/manifest.json` file in your Unity Project under the `dependencies` section: 42 | 43 | ```json 44 | "com.unity.2d.tilemap.extras": "https://github.com/Unity-Technologies/2d-extras.git#master" 45 | ``` 46 | 47 | ### Tilemap 48 | 49 | For use with Unity `2021.1.0f1` onwards. 50 | 51 | Please use the `2020.3` branch for Unity 2020.1-2020.3 versions. 52 | 53 | Please use the `1.5.0-preview` tag for Unity 2019.2-2019.4 versions. 54 | 55 | Please use the `2019.1` tag for Unity 2019.1 versions. 56 | 57 | Please use the `2018.3` branch or the `2018.3` tag for Unity 2018.3-2018.4 versions. 58 | 59 | Please use the `2018.2` branch or the `2018.2` tag for Unity 2018.2 versions. 60 | 61 | Please use the `2017` branch or the `2017` tag for earlier versions of Unity (from 2017.2 and up). 62 | 63 | ##### Brushes 64 | 65 | - **Coordinate**: This Brush displays the cell coordinates it is targeting in the SceneView. Use this as an example to create brushes which have extra visualization features when painting onto a Tilemap. 66 | - **Line**: This Brush helps draw lines of Tiles onto a Tilemap. The first click of the mouse sets the starting point of the line and the second click sets the ending point of the line and draws the lines of Tiles. Use this as an example to modify brush painting behaviour to making painting quicker with less actions. 67 | - **Random**: This Brush helps to place random Tiles onto a Tilemap. Use this as an example to create brushes which store specific data per brush and to make brushes which randomize behaviour. 68 | - **Prefab**: This Brush instances and places the containing Prefab onto the targeted location and parents the instanced object to the paint target. Use this as an example to quickly place an assorted type of GameObjects onto structured locations. 69 | - **PrefabRandom**: This Brush instances and places a randomly selected Prefabs onto the targeted location and parents the instanced object to the paint target. Use this as an example to quickly place an assorted type of GameObjects onto structured locations. 70 | - **GameObject**: This Brush instances, places and manipulates GameObjects onto the scene. Use this as an example to create brushes which targets objects other than tiles for manipulation. 71 | - **TintBrush**: Brush to edit Tilemap per-cell tint colors. 72 | - **TintBrushSmooth**: Advanced tint brush for interpolated tint color per-cell. Requires the use of custom shader (see TintedTilemap.shader) and helper component TileTextureGenerator. 73 | - **Group**: This Brush helps to pick Tiles which are grouped together by position. Gaps can be set to identify if Tiles belong to a Group. Limits can be set to ensure that an over-sized Group will not be picked. Use this as an example to create brushes that have the ability to choose and pick whichever Tiles it is interested in. 74 | 75 | ##### Tiles 76 | 77 | - **Animated**: Animated Tiles are tiles which run through and display a list of sprites in sequence. 78 | - **Pipeline**: Pipeline Tiles are tiles which take into consideration its orthogonal neighboring tiles and displays a sprite depending on whether the neighboring tile is the same tile. 79 | - **Random**: Random Tiles are tiles which pseudo-randomly pick a sprite from a given list of sprites and a target location, and displays that sprite. 80 | - **Terrain**: Terrain Tiles, similar to Pipeline Tiles, are tiles which take into consideration its orthogonal and diagonal neighboring tiles and displays a sprite depending on whether the neighboring tile is the same tile. 81 | - **RuleTile**: Generic visual tile for creating different tilesets like terrain, pipeline, random or animated tiles. 82 | - **Hexagonal Rule Tile**: A Rule Tile for use with Hexagonal Grids. Enable Flat Top for Flat Top Hexagonal Grids and disable for Pointed Top Hexagonal Grids. 83 | - **Isometric Rule Tile**: A Rule Tile for use with Isometric Grids. 84 | - **RuleOverrideTile**: Rule Override Tiles are Tiles which can override a subset of Rules for a given Rule Tile to provide specialised behaviour while keeping most of the Rules originally set in the Rule Tile. 85 | - **Weighted Random**: Weighted Random Tiles are tiles which randomly pick a sprite from a given list of sprites and a target location, and displays that sprite. The sprites can be weighted with a value to change its probability of appearing. 86 | 87 | ##### Other 88 | 89 | - **GridInformation**: A simple MonoBehaviour that stores and provides information based on Grid positions and keywords. 90 | - **Custom Rules for RuleTile**: This helps to create new custom Rules for the Rule Tile. Check the [Wiki](https://github.com/Unity-Technologies/2d-extras/wiki) or this great [video](https://youtu.be/FwOxLkJTXag) for more information on how to use this! 91 | 92 | [![How to make Custom Rule Tiles in Unity Video](http://img.youtube.com/vi/FwOxLkJTXag/0.jpg)](http://www.youtube.com/watch?v=FwOxLkJTXag "How to make Custom Rule Tiles in Unity") 93 | 94 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a2cf010fb12d5146a68fb9a7b4d89fe 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb6e0fae761c98e4babad8a6c2188e8d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Brushes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 111a320d9ff44f74c927510506ca4709 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Brushes/TintTextureGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.Tilemaps; 4 | 5 | /// 6 | /// A helper class for tinting a Grid component 7 | /// 8 | [ExecuteInEditMode] 9 | public class TintTextureGenerator : MonoBehaviour 10 | { 11 | /// 12 | /// Size of the Tint map in cells 13 | /// 14 | public int k_TintMapSize = 256; 15 | 16 | /// 17 | /// Mapping scale for cells to Tint map texture 18 | /// 19 | /// /// 20 | /// Adjust to get better definition. 21 | /// 22 | public int k_ScaleFactor = 1; 23 | 24 | /// 25 | /// Size of the Tint map texture in pixels 26 | /// 27 | public int k_TintMapTextureSize => k_TintMapSize * k_ScaleFactor; 28 | 29 | private Grid m_Grid; 30 | 31 | 32 | /// 33 | /// Callback when the TintTextureGenerator is loaded. 34 | /// Refreshes the Grid Component on this GameObject. 35 | /// 36 | public void Start() 37 | { 38 | m_Grid = GetComponent(); 39 | Refresh(m_Grid); 40 | } 41 | 42 | private Texture2D m_TintTexture; 43 | 44 | /// 45 | /// Tint texture generated from Grid values 46 | /// 47 | public Texture2D tintTexture 48 | { 49 | get 50 | { 51 | if (m_TintTexture == null || m_TintTexture.width != k_TintMapTextureSize) 52 | { 53 | m_TintTexture = new Texture2D(k_TintMapTextureSize, k_TintMapTextureSize, TextureFormat.ARGB32, false); 54 | m_TintTexture.hideFlags = HideFlags.HideAndDontSave; 55 | m_TintTexture.wrapMode = TextureWrapMode.Clamp; 56 | m_TintTexture.filterMode = FilterMode.Bilinear; 57 | RefreshGlobalShaderValues(); 58 | Refresh(m_Grid); 59 | } 60 | return m_TintTexture; 61 | } 62 | } 63 | 64 | /// 65 | /// Refreshes the tint color of the Grid 66 | /// 67 | /// Grid to refresh color 68 | public void Refresh(Grid grid) 69 | { 70 | if (grid == null) 71 | return; 72 | 73 | var gi = GetGridInformation(grid); 74 | int w = tintTexture.width; 75 | int h = tintTexture.height; 76 | for (int y = 0; y < h; y++) 77 | { 78 | for (int x = 0; x < w; x++) 79 | { 80 | Vector3 worldPos = TextureToWorld(new Vector3Int(x, y, 0)); 81 | Vector3Int cellPos = grid.WorldToCell(worldPos); 82 | tintTexture.SetPixel(x, y, gi.GetPositionProperty(cellPos, "Tint", Color.white)); 83 | } 84 | } 85 | tintTexture.Apply(); 86 | } 87 | 88 | /// 89 | /// Refreshes the color of a position on a Grid 90 | /// 91 | /// Grid to refresh color 92 | /// Position of the Grid to refresh color 93 | public void Refresh(Grid grid, Vector3Int position) 94 | { 95 | if (grid == null) 96 | return; 97 | 98 | RefreshGlobalShaderValues(); 99 | var worldPosition = grid.CellToWorld(position); 100 | Vector3Int texPosition = WorldToTexture(worldPosition); 101 | var color = GetGridInformation(grid).GetPositionProperty(position, "Tint", Color.white); 102 | var scale = Math.Max(0, k_ScaleFactor - 2); 103 | var radius = new Vector2Int(Mathf.RoundToInt(scale * grid.cellSize.x), Mathf.RoundToInt(scale * grid.cellSize.y)); 104 | for (int y = -radius.y; y <= radius.y; ++y) 105 | { 106 | for (int x = -radius.x; x <= radius.x; ++x) 107 | { 108 | tintTexture.SetPixel(texPosition.x + x, texPosition.y + y, color); 109 | } 110 | } 111 | tintTexture.Apply(); 112 | } 113 | 114 | /// 115 | /// Get the color of a position on a Grid 116 | /// 117 | /// Grid to get color from 118 | /// Position of the Grid to get color from 119 | /// Color of a position on a Grid 120 | public Color GetColor(Grid grid, Vector3Int position) 121 | { 122 | if (grid == null) 123 | return Color.white; 124 | 125 | return GetGridInformation(grid).GetPositionProperty(position, "Tint", Color.white); 126 | } 127 | 128 | /// 129 | /// Set the color of a position on a Grid 130 | /// 131 | /// Grid to set color to 132 | /// Position of the Grid to set color to 133 | /// Color to set to 134 | public void SetColor(Grid grid, Vector3Int position, Color color) 135 | { 136 | if (grid == null) 137 | return; 138 | 139 | GetGridInformation(grid).SetPositionProperty(position, "Tint", color); 140 | Refresh(grid, position); 141 | } 142 | 143 | Vector3Int WorldToTexture(Vector3 worldPos) 144 | { 145 | return new Vector3Int(Mathf.FloorToInt((worldPos.x * k_ScaleFactor) + tintTexture.width / 2f) 146 | , Mathf.FloorToInt((worldPos.y * k_ScaleFactor) + tintTexture.height / 2f), 0); 147 | } 148 | 149 | Vector3 TextureToWorld(Vector3Int texPos) 150 | { 151 | var inv = 1 / (k_ScaleFactor == 0 ? 1 : k_ScaleFactor); 152 | return new Vector3((texPos.x - tintTexture.width / 2) * inv 153 | , (texPos.y - tintTexture.height / 2) * inv, 0); 154 | } 155 | 156 | GridInformation GetGridInformation(Grid grid) 157 | { 158 | GridInformation gridInformation = grid.GetComponent(); 159 | 160 | if (gridInformation == null) 161 | gridInformation = grid.gameObject.AddComponent(); 162 | 163 | return gridInformation; 164 | } 165 | 166 | void RefreshGlobalShaderValues() 167 | { 168 | Shader.SetGlobalTexture("_TintMap", m_TintTexture); 169 | Shader.SetGlobalFloat("_TintMapSize", k_TintMapSize); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /Runtime/Brushes/TintTextureGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b41bf0cc11b1c8f419f96e8eb0adea40 3 | timeCreated: 1502798706 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Runtime/Brushes/TintedTilemap.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/TintedTilemap" 2 | { 3 | Properties 4 | { 5 | [PerRendererData]_MainTex ("Albedo (RGB)", 2D) = "white" {} 6 | } 7 | 8 | SubShader 9 | { 10 | Tags { "Queue"="Transparent" "Render"="Transparent" "IgnoreProjector"="True"} 11 | LOD 200 12 | 13 | Cull Off 14 | ZWrite Off 15 | Blend SrcAlpha OneMinusSrcAlpha 16 | 17 | Pass{ 18 | CGPROGRAM 19 | 20 | #pragma target 3.0 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | #include "UnityCG.cginc" 25 | 26 | struct appdata { 27 | float4 vertex : POSITION; 28 | float4 texcoord : TEXCOORD0; 29 | }; 30 | 31 | sampler2D _MainTex; 32 | sampler2D _TintMap; 33 | float _TintMapSize; 34 | 35 | struct v2f { 36 | float4 vertex : SV_POSITION; 37 | float4 uv : TEXCOORD0; 38 | float3 worldPos : float3; 39 | }; 40 | 41 | v2f vert(appdata v) { 42 | v2f o; 43 | 44 | o.worldPos = mul (unity_ObjectToWorld, v.vertex); 45 | o.vertex = UnityObjectToClipPos(v.vertex); 46 | o.uv = float4(v.texcoord.xy, 0, 0); 47 | 48 | return o; 49 | } 50 | 51 | fixed4 frag(v2f i) : SV_Target { 52 | fixed4 col = tex2D (_MainTex, i.uv); 53 | fixed4 tint = tex2D(_TintMap, (i.worldPos.xy / _TintMapSize) + .5); 54 | return tint * col; 55 | } 56 | ENDCG 57 | } 58 | 59 | 60 | } 61 | FallBack "Diffuse" 62 | } 63 | -------------------------------------------------------------------------------- /Runtime/Brushes/TintedTilemap.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9fcc3b710e7f7ae44bcf65125a08d5ef 3 | timeCreated: 1502805334 4 | licenseType: Pro 5 | ShaderImporter: 6 | externalObjects: {} 7 | defaultTextures: [] 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Runtime/GridInformation.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ecefc247a9b423b4f8398f5e03d27f76 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/GridInformation/GridInformation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7bb9acb2cffc5f45abddc238a0ad9b0 3 | timeCreated: 1501815409 4 | licenseType: Free 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Runtime/Tiles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86aeedb511333af45943236d5d6be1b4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/AnimatedTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: daa079e375a6c2c49a30d83bd2d842c2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/AnimatedTile/AnimatedTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13b75c95f34a00d4e8c04f76b73312e6 3 | timeCreated: 1464531813 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Runtime/Tiles/HexagonalRuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d0cb420882fe5d48ba544c0bb493094 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/HexagonalRuleTile/HexagonalRuleTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityEngine 4 | { 5 | /// 6 | /// Generic visual tile for creating different tilesets like terrain, pipeline, random or animated tiles. 7 | /// This is templated to accept a Neighbor Rule Class for Custom Rules. 8 | /// Use this for Hexagonal Grids. 9 | /// 10 | /// Neighbor Rule Class for Custom Rules 11 | public class HexagonalRuleTile : HexagonalRuleTile 12 | { 13 | /// 14 | /// Returns the Neighbor Rule Class type for this Rule Tile. 15 | /// 16 | public sealed override Type m_NeighborType => typeof(T); 17 | } 18 | 19 | /// 20 | /// Generic visual tile for creating different tilesets like terrain, pipeline, random or animated tiles. 21 | /// Use this for Hexagonal Grids. 22 | /// 23 | [Serializable] 24 | [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/RuleTile.html")] 25 | public class HexagonalRuleTile : RuleTile 26 | { 27 | /// 28 | /// Angle in which the HexagonalRuleTile is rotated by for matching in Degrees. 29 | /// 30 | public override int m_RotationAngle => 60; 31 | 32 | private static float[] m_CosAngleArr1 = { 33 | Mathf.Cos(0 * Mathf.Deg2Rad), 34 | Mathf.Cos(-60 * Mathf.Deg2Rad), 35 | Mathf.Cos(-120 * Mathf.Deg2Rad), 36 | Mathf.Cos(-180 * Mathf.Deg2Rad), 37 | Mathf.Cos(-240 * Mathf.Deg2Rad), 38 | Mathf.Cos(-300 * Mathf.Deg2Rad), 39 | }; 40 | private static float[] m_SinAngleArr1 = { 41 | Mathf.Sin(0 * Mathf.Deg2Rad), 42 | Mathf.Sin(-60 * Mathf.Deg2Rad), 43 | Mathf.Sin(-120 * Mathf.Deg2Rad), 44 | Mathf.Sin(-180 * Mathf.Deg2Rad), 45 | Mathf.Sin(-240 * Mathf.Deg2Rad), 46 | Mathf.Sin(-300 * Mathf.Deg2Rad), 47 | }; 48 | private static float[] m_CosAngleArr2 = { 49 | Mathf.Cos(0 * Mathf.Deg2Rad), 50 | Mathf.Cos(60 * Mathf.Deg2Rad), 51 | Mathf.Cos(120 * Mathf.Deg2Rad), 52 | Mathf.Cos(180 * Mathf.Deg2Rad), 53 | Mathf.Cos(240 * Mathf.Deg2Rad), 54 | Mathf.Cos(300 * Mathf.Deg2Rad), 55 | }; 56 | private static float[] m_SinAngleArr2 = { 57 | Mathf.Sin(0 * Mathf.Deg2Rad), 58 | Mathf.Sin(60 * Mathf.Deg2Rad), 59 | Mathf.Sin(120 * Mathf.Deg2Rad), 60 | Mathf.Sin(180 * Mathf.Deg2Rad), 61 | Mathf.Sin(240 * Mathf.Deg2Rad), 62 | Mathf.Sin(300 * Mathf.Deg2Rad), 63 | }; 64 | 65 | /// 66 | /// Whether this is a flat top Hexagonal Tile 67 | /// 68 | [DontOverride] public bool m_FlatTop; 69 | 70 | static float m_TilemapToWorldYScale = Mathf.Pow(1 - Mathf.Pow(0.5f, 2f), 0.5f); 71 | 72 | /// 73 | /// Converts a Tilemap Position to World Position. 74 | /// 75 | /// Tilemap Position to convert. 76 | /// World Position. 77 | public static Vector3 TilemapPositionToWorldPosition(Vector3Int tilemapPosition) 78 | { 79 | Vector3 worldPosition = new Vector3(tilemapPosition.x, tilemapPosition.y); 80 | if (tilemapPosition.y % 2 != 0) 81 | worldPosition.x += 0.5f; 82 | worldPosition.y *= m_TilemapToWorldYScale; 83 | return worldPosition; 84 | } 85 | 86 | /// 87 | /// Converts a World Position to Tilemap Position. 88 | /// 89 | /// World Position to convert. 90 | /// Tilemap Position. 91 | public static Vector3Int WorldPositionToTilemapPosition(Vector3 worldPosition) 92 | { 93 | worldPosition.y /= m_TilemapToWorldYScale; 94 | Vector3Int tilemapPosition = new Vector3Int(); 95 | tilemapPosition.y = Mathf.RoundToInt(worldPosition.y); 96 | if (tilemapPosition.y % 2 != 0) 97 | tilemapPosition.x = Mathf.RoundToInt(worldPosition.x - 0.5f); 98 | else 99 | tilemapPosition.x = Mathf.RoundToInt(worldPosition.x); 100 | return tilemapPosition; 101 | } 102 | 103 | /// 104 | /// Get the offset for the given position with the given offset. 105 | /// 106 | /// Position to offset. 107 | /// Offset for the position. 108 | /// The offset position. 109 | public override Vector3Int GetOffsetPosition(Vector3Int position, Vector3Int offset) 110 | { 111 | Vector3Int offsetPosition = position + offset; 112 | 113 | if (offset.y % 2 != 0 && position.y % 2 != 0) 114 | offsetPosition.x += 1; 115 | 116 | return offsetPosition; 117 | } 118 | 119 | /// 120 | /// Get the reversed offset for the given position with the given offset. 121 | /// 122 | /// Position to offset. 123 | /// Offset for the position. 124 | /// The reversed offset position. 125 | public override Vector3Int GetOffsetPositionReverse(Vector3Int position, Vector3Int offset) 126 | { 127 | return GetOffsetPosition(position, GetRotatedPosition(offset, 180)); 128 | } 129 | 130 | /// 131 | /// Gets a rotated position given its original position and the rotation in degrees. 132 | /// 133 | /// Original position of Tile. 134 | /// Rotation in degrees. 135 | /// Rotated position of Tile. 136 | public override Vector3Int GetRotatedPosition(Vector3Int position, int rotation) 137 | { 138 | if (rotation != 0) 139 | { 140 | Vector3 worldPosition = TilemapPositionToWorldPosition(position); 141 | 142 | int index = rotation / 60; 143 | if (m_FlatTop) 144 | { 145 | worldPosition = new Vector3( 146 | worldPosition.x * m_CosAngleArr2[index] - worldPosition.y * m_SinAngleArr2[index], 147 | worldPosition.x * m_SinAngleArr2[index] + worldPosition.y * m_CosAngleArr2[index] 148 | ); 149 | } 150 | else 151 | { 152 | worldPosition = new Vector3( 153 | worldPosition.x * m_CosAngleArr1[index] - worldPosition.y * m_SinAngleArr1[index], 154 | worldPosition.x * m_SinAngleArr1[index] + worldPosition.y * m_CosAngleArr1[index] 155 | ); 156 | } 157 | 158 | position = WorldPositionToTilemapPosition(worldPosition); 159 | } 160 | return position; 161 | } 162 | 163 | /// 164 | /// Gets a mirrored position given its original position and the mirroring axii. 165 | /// 166 | /// Original position of Tile. 167 | /// Mirror in the X Axis. 168 | /// Mirror in the Y Axis. 169 | /// Mirrored position of Tile. 170 | public override Vector3Int GetMirroredPosition(Vector3Int position, bool mirrorX, bool mirrorY) 171 | { 172 | if (mirrorX || mirrorY) 173 | { 174 | Vector3 worldPosition = TilemapPositionToWorldPosition(position); 175 | 176 | if (m_FlatTop) 177 | { 178 | if (mirrorX) 179 | worldPosition.y *= -1; 180 | if (mirrorY) 181 | worldPosition.x *= -1; 182 | } 183 | else 184 | { 185 | if (mirrorX) 186 | worldPosition.x *= -1; 187 | if (mirrorY) 188 | worldPosition.y *= -1; 189 | } 190 | 191 | position = WorldPositionToTilemapPosition(worldPosition); 192 | } 193 | return position; 194 | } 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /Runtime/Tiles/HexagonalRuleTile/HexagonalRuleTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55f747e8af38fbe4d8819f37be6fd5aa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Tiles/IsometricRuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8c72f5be5ed1d44b9a3bde2d9c137c8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/IsometricRuleTile/IsometricRuleTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityEngine 4 | { 5 | /// 6 | /// Generic visual tile for creating different tilesets like terrain, pipeline, random or animated tiles. 7 | /// This is templated to accept a Neighbor Rule Class for Custom Rules. 8 | /// Use this for Isometric Grids. 9 | /// 10 | /// Neighbor Rule Class for Custom Rules 11 | public class IsometricRuleTile : IsometricRuleTile 12 | { 13 | /// 14 | /// Returns the Neighbor Rule Class type for this Rule Tile. 15 | /// 16 | public sealed override Type m_NeighborType => typeof(T); 17 | } 18 | 19 | /// 20 | /// Generic visual tile for creating different tilesets like terrain, pipeline, random or animated tiles. 21 | /// Use this for Isometric Grids. 22 | /// 23 | [Serializable] 24 | [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/RuleTile.html")] 25 | public class IsometricRuleTile : RuleTile 26 | { 27 | // This has no differences with the RuleTile 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Runtime/Tiles/IsometricRuleTile/IsometricRuleTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e6f3fbb560bd6041a202ea918fa4f23 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Tiles/PipelineTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8cc7b6611da8a674c890494a2a21acbc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/PipelineTile/PipelineTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | #if UNITY_EDITOR 6 | using UnityEditor; 7 | #endif 8 | 9 | using UnityEngine; 10 | 11 | namespace UnityEngine.Tilemaps 12 | { 13 | /// 14 | /// Pipeline Tiles are tiles which take into consideration its orthogonal neighboring tiles and displays a sprite depending on whether the neighboring tile is the same tile. 15 | /// 16 | [Serializable] 17 | public class PipelineTile : TileBase 18 | { 19 | /// 20 | /// The Sprites used for defining the Pipeline. 21 | /// 22 | [SerializeField] 23 | public Sprite[] m_Sprites; 24 | 25 | /// 26 | /// This method is called when the tile is refreshed. 27 | /// 28 | /// Position of the Tile on the Tilemap. 29 | /// The Tilemap the tile is present on. 30 | public override void RefreshTile(Vector3Int position, ITilemap tilemap) 31 | { 32 | for (int yd = -1; yd <= 1; yd++) 33 | for (int xd = -1; xd <= 1; xd++) 34 | { 35 | Vector3Int pos = new Vector3Int(position.x + xd, position.y + yd, position.z); 36 | if (TileValue(tilemap, pos)) 37 | tilemap.RefreshTile(pos); 38 | } 39 | } 40 | 41 | /// 42 | /// Retrieves any tile rendering data from the scripted tile. 43 | /// 44 | /// Position of the Tile on the Tilemap. 45 | /// The Tilemap the tile is present on. 46 | /// Data to render the tile. 47 | public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) 48 | { 49 | UpdateTile(position, tilemap, ref tileData); 50 | } 51 | 52 | private void UpdateTile(Vector3Int position, ITilemap tilemap, ref TileData tileData) 53 | { 54 | tileData.transform = Matrix4x4.identity; 55 | tileData.color = Color.white; 56 | 57 | int mask = TileValue(tilemap, position + new Vector3Int(0, 1, 0)) ? 1 : 0; 58 | mask += TileValue(tilemap, position + new Vector3Int(1, 0, 0)) ? 2 : 0; 59 | mask += TileValue(tilemap, position + new Vector3Int(0, -1, 0)) ? 4 : 0; 60 | mask += TileValue(tilemap, position + new Vector3Int(-1, 0, 0)) ? 8 : 0; 61 | 62 | int index = GetIndex((byte)mask); 63 | if (index >= 0 && index < m_Sprites.Length && TileValue(tilemap, position)) 64 | { 65 | tileData.sprite = m_Sprites[index]; 66 | tileData.transform = GetTransform((byte)mask); 67 | tileData.flags = TileFlags.LockTransform | TileFlags.LockColor; 68 | tileData.colliderType = Tile.ColliderType.Sprite; 69 | } 70 | } 71 | 72 | private bool TileValue(ITilemap tileMap, Vector3Int position) 73 | { 74 | TileBase tile = tileMap.GetTile(position); 75 | return (tile != null && tile == this); 76 | } 77 | 78 | private int GetIndex(byte mask) 79 | { 80 | switch (mask) 81 | { 82 | case 0: return 0; 83 | case 3: 84 | case 6: 85 | case 9: 86 | case 12: return 1; 87 | case 1: 88 | case 2: 89 | case 4: 90 | case 5: 91 | case 10: 92 | case 8: return 2; 93 | case 7: 94 | case 11: 95 | case 13: 96 | case 14: return 3; 97 | case 15: return 4; 98 | } 99 | return -1; 100 | } 101 | 102 | private Matrix4x4 GetTransform(byte mask) 103 | { 104 | switch (mask) 105 | { 106 | case 9: 107 | case 10: 108 | case 7: 109 | case 2: 110 | case 8: 111 | return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, -90f), Vector3.one); 112 | case 3: 113 | case 14: 114 | return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, -180f), Vector3.one); 115 | case 6: 116 | case 13: 117 | return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, -270f), Vector3.one); 118 | } 119 | return Matrix4x4.identity; 120 | } 121 | } 122 | 123 | #if UNITY_EDITOR 124 | [CustomEditor(typeof(PipelineTile))] 125 | public class PipelineTileEditor : Editor 126 | { 127 | private PipelineTile tile { get { return (target as PipelineTile); } } 128 | 129 | /// 130 | /// OnEnable for PipelineTile. 131 | /// 132 | public void OnEnable() 133 | { 134 | if (tile.m_Sprites == null || tile.m_Sprites.Length != 5) 135 | tile.m_Sprites = new Sprite[5]; 136 | } 137 | 138 | /// 139 | /// Draws an Inspector for the PipelineTile. 140 | /// 141 | public override void OnInspectorGUI() 142 | { 143 | EditorGUILayout.LabelField("Place sprites shown based on the number of tiles bordering it."); 144 | EditorGUILayout.Space(); 145 | 146 | EditorGUI.BeginChangeCheck(); 147 | tile.m_Sprites[0] = (Sprite) EditorGUILayout.ObjectField("None", tile.m_Sprites[0], typeof(Sprite), false, null); 148 | tile.m_Sprites[2] = (Sprite) EditorGUILayout.ObjectField("One", tile.m_Sprites[2], typeof(Sprite), false, null); 149 | tile.m_Sprites[1] = (Sprite) EditorGUILayout.ObjectField("Two", tile.m_Sprites[1], typeof(Sprite), false, null); 150 | tile.m_Sprites[3] = (Sprite) EditorGUILayout.ObjectField("Three", tile.m_Sprites[3], typeof(Sprite), false, null); 151 | tile.m_Sprites[4] = (Sprite) EditorGUILayout.ObjectField("Four", tile.m_Sprites[4], typeof(Sprite), false, null); 152 | if (EditorGUI.EndChangeCheck()) 153 | EditorUtility.SetDirty(tile); 154 | } 155 | } 156 | #endif 157 | } 158 | -------------------------------------------------------------------------------- /Runtime/Tiles/PipelineTile/PipelineTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25192638efa881c469b1ac4d8cfd3f1b 3 | timeCreated: 1464534747 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Runtime/Tiles/RandomTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f459333af097b894b838c61a2fc7c220 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/RandomTile/RandomTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if UNITY_EDITOR 4 | using UnityEditor; 5 | #endif 6 | 7 | namespace UnityEngine.Tilemaps 8 | { 9 | /// 10 | /// Random Tiles are tiles which pseudo-randomly pick a sprite from a given list of sprites and a target location, and displays that sprite. 11 | /// The Sprite displayed for the Tile is randomized based on its location and will be fixed for that particular location. 12 | /// 13 | [Serializable] 14 | public class RandomTile : Tile 15 | { 16 | /// 17 | /// The Sprites used for randomizing output. 18 | /// 19 | [SerializeField] 20 | public Sprite[] m_Sprites; 21 | 22 | /// 23 | /// Retrieves any tile rendering data from the scripted tile. 24 | /// 25 | /// Position of the Tile on the Tilemap. 26 | /// The Tilemap the tile is present on. 27 | /// Data to render the tile. 28 | public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) 29 | { 30 | base.GetTileData(position, tilemap, ref tileData); 31 | if ((m_Sprites != null) && (m_Sprites.Length > 0)) 32 | { 33 | long hash = position.x; 34 | hash = (hash + 0xabcd1234) + (hash << 15); 35 | hash = (hash + 0x0987efab) ^ (hash >> 11); 36 | hash ^= position.y; 37 | hash = (hash + 0x46ac12fd) + (hash << 7); 38 | hash = (hash + 0xbe9730af) ^ (hash << 11); 39 | var oldState = Random.state; 40 | Random.InitState((int)hash); 41 | tileData.sprite = m_Sprites[(int) (m_Sprites.Length * Random.value)]; 42 | Random.state = oldState; 43 | } 44 | } 45 | } 46 | 47 | #if UNITY_EDITOR 48 | [CustomEditor(typeof(RandomTile))] 49 | public class RandomTileEditor : Editor 50 | { 51 | private SerializedProperty m_Color; 52 | private SerializedProperty m_ColliderType; 53 | 54 | private RandomTile tile { get { return (target as RandomTile); } } 55 | 56 | /// 57 | /// OnEnable for RandomTile. 58 | /// 59 | public void OnEnable() 60 | { 61 | m_Color = serializedObject.FindProperty("m_Color"); 62 | m_ColliderType = serializedObject.FindProperty("m_ColliderType"); 63 | } 64 | 65 | /// 66 | /// Draws an Inspector for the RandomTile. 67 | /// 68 | public override void OnInspectorGUI() 69 | { 70 | serializedObject.Update(); 71 | 72 | EditorGUI.BeginChangeCheck(); 73 | int count = EditorGUILayout.DelayedIntField("Number of Sprites", tile.m_Sprites != null ? tile.m_Sprites.Length : 0); 74 | if (count < 0) 75 | count = 0; 76 | if (tile.m_Sprites == null || tile.m_Sprites.Length != count) 77 | { 78 | Array.Resize(ref tile.m_Sprites, count); 79 | } 80 | 81 | if (count == 0) 82 | return; 83 | 84 | EditorGUILayout.LabelField("Place random sprites."); 85 | EditorGUILayout.Space(); 86 | 87 | for (int i = 0; i < count; i++) 88 | { 89 | tile.m_Sprites[i] = (Sprite) EditorGUILayout.ObjectField("Sprite " + (i+1), tile.m_Sprites[i], typeof(Sprite), false, null); 90 | } 91 | 92 | EditorGUILayout.Space(); 93 | 94 | EditorGUILayout.PropertyField(m_Color); 95 | EditorGUILayout.PropertyField(m_ColliderType); 96 | 97 | if (EditorGUI.EndChangeCheck()) 98 | { 99 | EditorUtility.SetDirty(tile); 100 | serializedObject.ApplyModifiedProperties(); 101 | } 102 | } 103 | } 104 | #endif 105 | } 106 | -------------------------------------------------------------------------------- /Runtime/Tiles/RandomTile/RandomTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 535f8e525ff367c4ba67961e201a05ed 3 | timeCreated: 1445235751 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleOverrideTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3404b3ef5c8133646b532504aef95120 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleOverrideTile/AdvancedRuleOverrideTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine.Scripting.APIUpdating; 4 | 5 | namespace UnityEngine.Tilemaps 6 | { 7 | /// 8 | /// Rule Override Tiles are Tiles which can override a subset of Rules for a given Rule Tile to provide specialised behaviour while keeping most of the Rules originally set in the Rule Tile. 9 | /// 10 | [MovedFrom(true, "UnityEngine")] 11 | [Serializable] 12 | [HelpURL("https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/RuleOverrideTile.html")] 13 | public class AdvancedRuleOverrideTile : RuleOverrideTile 14 | { 15 | 16 | /// 17 | /// Gets the overriding TilingRuleOutput of a given TilingRule. 18 | /// 19 | /// The original TilingRule that is overridden 20 | public RuleTile.TilingRuleOutput this[RuleTile.TilingRule originalRule] 21 | { 22 | get 23 | { 24 | foreach (var overrideRule in m_OverrideTilingRules) 25 | if (overrideRule.m_Id == originalRule.m_Id) 26 | return overrideRule; 27 | 28 | return null; 29 | } 30 | set 31 | { 32 | for (int i = m_OverrideTilingRules.Count - 1; i >= 0; i--) 33 | { 34 | if (m_OverrideTilingRules[i].m_Id == originalRule.m_Id) 35 | { 36 | m_OverrideTilingRules.RemoveAt(i); 37 | break; 38 | } 39 | } 40 | if (value != null) 41 | { 42 | var json = JsonUtility.ToJson(value); 43 | var overrideRule = JsonUtility.FromJson(json); 44 | m_OverrideTilingRules.Add(overrideRule); 45 | } 46 | } 47 | } 48 | 49 | /// 50 | /// The Default Sprite set when creating a new Rule override. 51 | /// 52 | public Sprite m_DefaultSprite; 53 | /// 54 | /// The Default GameObject set when creating a new Rule override. 55 | /// 56 | public GameObject m_DefaultGameObject; 57 | /// 58 | /// The Default Collider Type set when creating a new Rule override. 59 | /// 60 | public Tile.ColliderType m_DefaultColliderType = Tile.ColliderType.Sprite; 61 | 62 | /// 63 | /// A list of TilingRule Overrides 64 | /// 65 | public List m_OverrideTilingRules = new List(); 66 | 67 | /// 68 | /// Applies overrides to this 69 | /// 70 | /// A list of overrides to apply 71 | /// The input overrides list is not valid 72 | public void ApplyOverrides(IList> overrides) 73 | { 74 | if (overrides == null) 75 | throw new System.ArgumentNullException("overrides"); 76 | 77 | for (int i = 0; i < overrides.Count; i++) 78 | this[overrides[i].Key] = overrides[i].Value; 79 | } 80 | 81 | /// 82 | /// Gets overrides for this 83 | /// 84 | /// A list of overrides to fill 85 | /// Returns the number of valid overrides for Rules 86 | /// The input overrides list is not valid 87 | public void GetOverrides(List> overrides, ref int validCount) 88 | { 89 | if (overrides == null) 90 | throw new System.ArgumentNullException("overrides"); 91 | 92 | overrides.Clear(); 93 | 94 | if (m_Tile) 95 | { 96 | foreach (var originalRule in m_Tile.m_TilingRules) 97 | { 98 | RuleTile.TilingRuleOutput overrideRule = this[originalRule]; 99 | overrides.Add(new KeyValuePair(originalRule, overrideRule)); 100 | } 101 | } 102 | 103 | validCount = overrides.Count; 104 | 105 | foreach (var overrideRule in m_OverrideTilingRules) 106 | { 107 | if (!overrides.Exists(o => o.Key.m_Id == overrideRule.m_Id)) 108 | { 109 | var originalRule = new RuleTile.TilingRule() { m_Id = overrideRule.m_Id }; 110 | overrides.Add(new KeyValuePair(originalRule, overrideRule)); 111 | } 112 | } 113 | } 114 | 115 | /// 116 | /// Updates the Rules with the Overrides set for this AdvancedRuleOverrideTile 117 | /// 118 | public override void Override() 119 | { 120 | if (!m_Tile || !m_InstanceTile) 121 | return; 122 | 123 | PrepareOverride(); 124 | 125 | var tile = m_InstanceTile; 126 | 127 | tile.m_DefaultSprite = m_DefaultSprite; 128 | tile.m_DefaultGameObject = m_DefaultGameObject; 129 | tile.m_DefaultColliderType = m_DefaultColliderType; 130 | 131 | foreach (var rule in tile.m_TilingRules) 132 | { 133 | var overrideRule = this[rule]; 134 | if (overrideRule != null) 135 | { 136 | JsonUtility.FromJsonOverwrite(JsonUtility.ToJson(overrideRule), rule); 137 | } 138 | } 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleOverrideTile/AdvancedRuleOverrideTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ff2caf20a1df406d9ab8f2f5a57f734 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleOverrideTile/RuleOverrideTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c779848d9dd029409ca676b49e10a18 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ba757fb3d4cc7e641ab2b91814856b68 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/RuleTile/RuleTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d1514134bc4fbd41bb739b1b9a49231 3 | timeCreated: 1501789622 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Runtime/Tiles/TerrainTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb65a41a206451e419f4513e440069d3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/TerrainTile/TerrainTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6e4e4fc705376343a3e65b25d94f0e2 3 | timeCreated: 1464534739 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Runtime/Tiles/WeightedRandomTile.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c1ac7817487f7984ab80d00618cf091a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Tiles/WeightedRandomTile/WeightedRandomTile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | #if UNITY_EDITOR 4 | using UnityEditor; 5 | #endif 6 | 7 | namespace UnityEngine.Tilemaps 8 | { 9 | /// 10 | /// A Sprite with a Weight value for randomization. 11 | /// 12 | [Serializable] 13 | public struct WeightedSprite 14 | { 15 | /// 16 | /// Sprite. 17 | /// 18 | public Sprite Sprite; 19 | /// 20 | /// Weight of the Sprite. 21 | /// 22 | public int Weight; 23 | } 24 | 25 | /// 26 | /// Weighted Random Tiles are tiles which randomly pick a sprite from a given list of sprites and a target location, and displays that sprite. 27 | /// The sprites can be weighted with a value to change its probability of appearing. The Sprite displayed for the Tile is randomized based on its location and will be fixed for that particular location. 28 | /// 29 | [Serializable] 30 | public class WeightedRandomTile : Tile 31 | { 32 | /// 33 | /// The Sprites used for randomizing output. 34 | /// 35 | [SerializeField] public WeightedSprite[] Sprites; 36 | 37 | /// 38 | /// Retrieves any tile rendering data from the scripted tile. 39 | /// 40 | /// Position of the Tile on the Tilemap. 41 | /// The Tilemap the tile is present on. 42 | /// Data to render the tile. 43 | public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) 44 | { 45 | base.GetTileData(position, tilemap, ref tileData); 46 | 47 | if (Sprites == null || Sprites.Length <= 0) return; 48 | 49 | var oldState = Random.state; 50 | long hash = position.x; 51 | hash = hash + 0xabcd1234 + (hash << 15); 52 | hash = hash + 0x0987efab ^ (hash >> 11); 53 | hash ^= position.y; 54 | hash = hash + 0x46ac12fd + (hash << 7); 55 | hash = hash + 0xbe9730af ^ (hash << 11); 56 | Random.InitState((int) hash); 57 | 58 | // Get the cumulative weight of the sprites 59 | var cumulativeWeight = 0; 60 | foreach (var spriteInfo in Sprites) cumulativeWeight += spriteInfo.Weight; 61 | 62 | // Pick a random weight and choose a sprite depending on it 63 | var randomWeight = Random.Range(0, cumulativeWeight); 64 | foreach (var spriteInfo in Sprites) 65 | { 66 | randomWeight -= spriteInfo.Weight; 67 | if (randomWeight < 0) 68 | { 69 | tileData.sprite = spriteInfo.Sprite; 70 | break; 71 | } 72 | } 73 | Random.state = oldState; 74 | } 75 | } 76 | 77 | #if UNITY_EDITOR 78 | [CustomEditor(typeof(WeightedRandomTile))] 79 | public class WeightedRandomTileEditor : Editor 80 | { 81 | private SerializedProperty m_Color; 82 | private SerializedProperty m_ColliderType; 83 | 84 | private WeightedRandomTile Tile { 85 | get { return target as WeightedRandomTile; } 86 | } 87 | 88 | /// 89 | /// OnEnable for WeightedRandomTile. 90 | /// 91 | public void OnEnable() 92 | { 93 | m_Color = serializedObject.FindProperty("m_Color"); 94 | m_ColliderType = serializedObject.FindProperty("m_ColliderType"); 95 | } 96 | 97 | /// 98 | /// Draws an Inspector for the WeightedRandomTile. 99 | /// 100 | public override void OnInspectorGUI() 101 | { 102 | serializedObject.Update(); 103 | 104 | EditorGUI.BeginChangeCheck(); 105 | 106 | int count = EditorGUILayout.DelayedIntField("Number of Sprites", Tile.Sprites != null ? Tile.Sprites.Length : 0); 107 | if (count < 0) 108 | count = 0; 109 | 110 | if (Tile.Sprites == null || Tile.Sprites.Length != count) 111 | { 112 | Array.Resize(ref Tile.Sprites, count); 113 | } 114 | 115 | if (count == 0) 116 | return; 117 | 118 | EditorGUILayout.LabelField("Place random sprites."); 119 | EditorGUILayout.Space(); 120 | 121 | for (int i = 0; i < count; i++) 122 | { 123 | Tile.Sprites[i].Sprite = (Sprite) EditorGUILayout.ObjectField("Sprite " + (i + 1), Tile.Sprites[i].Sprite, typeof(Sprite), false, null); 124 | Tile.Sprites[i].Weight = EditorGUILayout.IntField("Weight " + (i + 1), Tile.Sprites[i].Weight); 125 | } 126 | 127 | EditorGUILayout.Space(); 128 | 129 | EditorGUILayout.PropertyField(m_Color); 130 | EditorGUILayout.PropertyField(m_ColliderType); 131 | 132 | if (EditorGUI.EndChangeCheck()) 133 | { 134 | EditorUtility.SetDirty(Tile); 135 | serializedObject.ApplyModifiedProperties(); 136 | } 137 | } 138 | } 139 | #endif 140 | } 141 | -------------------------------------------------------------------------------- /Runtime/Tiles/WeightedRandomTile/WeightedRandomTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52f942ca9511f354a8efbf325740f4ab 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/Unity.2D.Tilemap.Extras.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.2D.Tilemap.Extras" 3 | } 4 | -------------------------------------------------------------------------------- /Runtime/Unity.2D.Tilemap.Extras.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 613783dc1674e844b87788ea74ede0f6 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Samples~/DungeonRuleTile/.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Dungeon Rule Tile", 3 | "interactiveImport": "false", 4 | "description": "An example implementation of a Rule Tile with rules matching eight-way orthogonal and diagonal neighbors.", 5 | } -------------------------------------------------------------------------------- /Samples~/DungeonRuleTile/Sprites/Dungeon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Samples~/DungeonRuleTile/Sprites/Dungeon.png -------------------------------------------------------------------------------- /Samples~/DungeonRuleTile/Tiles/Dungeon.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 9d1514134bc4fbd41bb739b1b9a49231, type: 3} 13 | m_Name: Dungeon 14 | m_EditorClassIdentifier: 15 | m_DefaultSprite: {fileID: -2860982009417361707, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 16 | m_DefaultGameObject: {fileID: 0} 17 | m_DefaultColliderType: 1 18 | m_TilingRules: 19 | - m_Id: 0 20 | m_Sprites: 21 | - {fileID: 8074338581418846440, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 22 | m_GameObject: {fileID: 0} 23 | m_AnimationSpeed: 1 24 | m_PerlinScale: 0.915 25 | m_Output: 0 26 | m_ColliderType: 1 27 | m_RandomTransform: 0 28 | m_Neighbors: 0100000001000000010000000100000001000000010000000100000001000000 29 | m_NeighborPositions: 30 | - {x: -1, y: 1, z: 0} 31 | - {x: 0, y: 1, z: 0} 32 | - {x: 1, y: 1, z: 0} 33 | - {x: -1, y: 0, z: 0} 34 | - {x: 1, y: 0, z: 0} 35 | - {x: -1, y: -1, z: 0} 36 | - {x: 0, y: -1, z: 0} 37 | - {x: 1, y: -1, z: 0} 38 | m_RuleTransform: 0 39 | - m_Id: 13 40 | m_Sprites: 41 | - {fileID: 4519664136019108208, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 42 | m_GameObject: {fileID: 0} 43 | m_AnimationSpeed: 1 44 | m_PerlinScale: 0.5 45 | m_Output: 0 46 | m_ColliderType: 1 47 | m_RandomTransform: 0 48 | m_Neighbors: 01000000010000000100000001000000010000000100000001000000 49 | m_NeighborPositions: 50 | - {x: 0, y: 1, z: 0} 51 | - {x: 1, y: 1, z: 0} 52 | - {x: -1, y: 0, z: 0} 53 | - {x: 1, y: 0, z: 0} 54 | - {x: -1, y: -1, z: 0} 55 | - {x: 0, y: -1, z: 0} 56 | - {x: 1, y: -1, z: 0} 57 | m_RuleTransform: 1 58 | - m_Id: 11 59 | m_Sprites: 60 | - {fileID: -6337999885091750218, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 61 | m_GameObject: {fileID: 0} 62 | m_AnimationSpeed: 1 63 | m_PerlinScale: 0.5 64 | m_Output: 0 65 | m_ColliderType: 1 66 | m_RandomTransform: 0 67 | m_Neighbors: 010000000100000001000000010000000100000001000000 68 | m_NeighborPositions: 69 | - {x: 0, y: 1, z: 0} 70 | - {x: -1, y: 0, z: 0} 71 | - {x: 1, y: 0, z: 0} 72 | - {x: 0, y: -1, z: 0} 73 | - {x: -1, y: -1, z: 0} 74 | - {x: 1, y: -1, z: 0} 75 | m_RuleTransform: 1 76 | - m_Id: 12 77 | m_Sprites: 78 | - {fileID: -5779282676337348671, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 79 | m_GameObject: {fileID: 0} 80 | m_AnimationSpeed: 1 81 | m_PerlinScale: 0.5 82 | m_Output: 0 83 | m_ColliderType: 1 84 | m_RandomTransform: 0 85 | m_Neighbors: 010000000100000001000000010000000100000001000000 86 | m_NeighborPositions: 87 | - {x: 0, y: 1, z: 0} 88 | - {x: 1, y: 1, z: 0} 89 | - {x: -1, y: 0, z: 0} 90 | - {x: 1, y: 0, z: 0} 91 | - {x: -1, y: -1, z: 0} 92 | - {x: 0, y: -1, z: 0} 93 | m_RuleTransform: 1 94 | - m_Id: 10 95 | m_Sprites: 96 | - {fileID: -1238933728272178944, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 97 | m_GameObject: {fileID: 0} 98 | m_AnimationSpeed: 1 99 | m_PerlinScale: 0.5 100 | m_Output: 0 101 | m_ColliderType: 1 102 | m_RandomTransform: 0 103 | m_Neighbors: 0100000001000000010000000100000001000000 104 | m_NeighborPositions: 105 | - {x: 0, y: 1, z: 0} 106 | - {x: -1, y: 0, z: 0} 107 | - {x: 1, y: 0, z: 0} 108 | - {x: 0, y: -1, z: 0} 109 | - {x: -1, y: -1, z: 0} 110 | m_RuleTransform: 1 111 | - m_Id: 9 112 | m_Sprites: 113 | - {fileID: -4637172546458061636, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 114 | m_GameObject: {fileID: 0} 115 | m_AnimationSpeed: 1 116 | m_PerlinScale: 0.5 117 | m_Output: 0 118 | m_ColliderType: 1 119 | m_RandomTransform: 0 120 | m_Neighbors: 01000000010000000100000001000000 121 | m_NeighborPositions: 122 | - {x: 0, y: 1, z: 0} 123 | - {x: -1, y: 0, z: 0} 124 | - {x: 1, y: 0, z: 0} 125 | - {x: 0, y: -1, z: 0} 126 | m_RuleTransform: 0 127 | - m_Id: 8 128 | m_Sprites: 129 | - {fileID: 1404196382344981941, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 130 | m_GameObject: {fileID: 0} 131 | m_AnimationSpeed: 1 132 | m_PerlinScale: 0.5 133 | m_Output: 0 134 | m_ColliderType: 1 135 | m_RandomTransform: 0 136 | m_Neighbors: 0100000001000000010000000100000001000000 137 | m_NeighborPositions: 138 | - {x: 1, y: 0, z: 0} 139 | - {x: -1, y: 0, z: 0} 140 | - {x: 1, y: -1, z: 0} 141 | - {x: 0, y: -1, z: 0} 142 | - {x: -1, y: -1, z: 0} 143 | m_RuleTransform: 1 144 | - m_Id: 7 145 | m_Sprites: 146 | - {fileID: -6537453368205885854, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 147 | m_GameObject: {fileID: 0} 148 | m_AnimationSpeed: 1 149 | m_PerlinScale: 0.5 150 | m_Output: 0 151 | m_ColliderType: 1 152 | m_RandomTransform: 0 153 | m_Neighbors: 01000000010000000100000001000000 154 | m_NeighborPositions: 155 | - {x: 1, y: 0, z: 0} 156 | - {x: -1, y: 0, z: 0} 157 | - {x: 0, y: -1, z: 0} 158 | - {x: -1, y: -1, z: 0} 159 | m_RuleTransform: 1 160 | - m_Id: 6 161 | m_Sprites: 162 | - {fileID: -3932762474534642510, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 163 | m_GameObject: {fileID: 0} 164 | m_AnimationSpeed: 1 165 | m_PerlinScale: 0.5 166 | m_Output: 0 167 | m_ColliderType: 1 168 | m_RandomTransform: 0 169 | m_Neighbors: 01000000010000000100000001000000 170 | m_NeighborPositions: 171 | - {x: 1, y: 0, z: 0} 172 | - {x: -1, y: 0, z: 0} 173 | - {x: 1, y: -1, z: 0} 174 | - {x: 0, y: -1, z: 0} 175 | m_RuleTransform: 1 176 | - m_Id: 3 177 | m_Sprites: 178 | - {fileID: -38647862416911262, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 179 | m_GameObject: {fileID: 0} 180 | m_AnimationSpeed: 1 181 | m_PerlinScale: 0.5 182 | m_Output: 0 183 | m_ColliderType: 1 184 | m_RandomTransform: 0 185 | m_Neighbors: 010000000100000001000000 186 | m_NeighborPositions: 187 | - {x: -1, y: 0, z: 0} 188 | - {x: 1, y: 0, z: 0} 189 | - {x: 0, y: -1, z: 0} 190 | m_RuleTransform: 1 191 | - m_Id: 5 192 | m_Sprites: 193 | - {fileID: 9158922217335370285, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 194 | m_GameObject: {fileID: 0} 195 | m_AnimationSpeed: 1 196 | m_PerlinScale: 0.5 197 | m_Output: 0 198 | m_ColliderType: 1 199 | m_RandomTransform: 0 200 | m_Neighbors: 0100000001000000 201 | m_NeighborPositions: 202 | - {x: 1, y: 0, z: 0} 203 | - {x: -1, y: 0, z: 0} 204 | m_RuleTransform: 1 205 | - m_Id: 4 206 | m_Sprites: 207 | - {fileID: -2913927307954446974, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 208 | m_GameObject: {fileID: 0} 209 | m_AnimationSpeed: 1 210 | m_PerlinScale: 0.5 211 | m_Output: 0 212 | m_ColliderType: 1 213 | m_RandomTransform: 0 214 | m_Neighbors: 010000000100000001000000 215 | m_NeighborPositions: 216 | - {x: 1, y: 0, z: 0} 217 | - {x: 0, y: -1, z: 0} 218 | - {x: 1, y: -1, z: 0} 219 | m_RuleTransform: 1 220 | - m_Id: 2 221 | m_Sprites: 222 | - {fileID: -8314697479797604436, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 223 | m_GameObject: {fileID: 0} 224 | m_AnimationSpeed: 1 225 | m_PerlinScale: 0.5 226 | m_Output: 0 227 | m_ColliderType: 1 228 | m_RandomTransform: 0 229 | m_Neighbors: 0100000001000000 230 | m_NeighborPositions: 231 | - {x: 1, y: 0, z: 0} 232 | - {x: 0, y: -1, z: 0} 233 | m_RuleTransform: 1 234 | - m_Id: 1 235 | m_Sprites: 236 | - {fileID: -8560909203809222747, guid: 4e794009527fa49a7a0e11880aaa3a50, type: 3} 237 | m_GameObject: {fileID: 0} 238 | m_AnimationSpeed: 1 239 | m_PerlinScale: 0.5 240 | m_Output: 0 241 | m_ColliderType: 1 242 | m_RandomTransform: 0 243 | m_Neighbors: 01000000 244 | m_NeighborPositions: 245 | - {x: -1, y: 0, z: 0} 246 | m_RuleTransform: 1 247 | -------------------------------------------------------------------------------- /Samples~/DungeonRuleTile/Tiles/Dungeon.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08002d404144b40bf842342dda8fa3e4 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/PipeRuleTile/.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Pipe Rule Tile", 3 | "interactiveImport": "false", 4 | "description": "An example implementation of a Rule Tile with rules matching four-way orthogonal neighbors.", 5 | } -------------------------------------------------------------------------------- /Samples~/PipeRuleTile/Sprites/Pipes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Samples~/PipeRuleTile/Sprites/Pipes.png -------------------------------------------------------------------------------- /Samples~/PipeRuleTile/Sprites/Pipes.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ebc1aff258f04220b2ce4e1240442fa 3 | TextureImporter: 4 | internalIDToNameTable: 5 | - first: 6 | 213: -3350344413380223241 7 | second: Pipes_00 8 | - first: 9 | 213: -982495737459262880 10 | second: Pipes_01 11 | - first: 12 | 213: 6001099972171207910 13 | second: Pipes_02 14 | - first: 15 | 213: 4376287821753702255 16 | second: Pipes_03 17 | - first: 18 | 213: -8656142213013974842 19 | second: Pipes_04 20 | - first: 21 | 213: 8455133356877028895 22 | second: Pipes_05 23 | externalObjects: {} 24 | serializedVersion: 11 25 | mipmaps: 26 | mipMapMode: 0 27 | enableMipMap: 0 28 | sRGBTexture: 1 29 | linearTexture: 0 30 | fadeOut: 0 31 | borderMipMap: 0 32 | mipMapsPreserveCoverage: 0 33 | alphaTestReferenceValue: 0.5 34 | mipMapFadeDistanceStart: 1 35 | mipMapFadeDistanceEnd: 3 36 | bumpmap: 37 | convertToNormalMap: 0 38 | externalNormalMap: 0 39 | heightScale: 0.25 40 | normalMapFilter: 0 41 | isReadable: 0 42 | streamingMipmaps: 0 43 | streamingMipmapsPriority: 0 44 | vTOnly: 0 45 | grayScaleToAlpha: 0 46 | generateCubemap: 6 47 | cubemapConvolution: 0 48 | seamlessCubemap: 0 49 | textureFormat: 1 50 | maxTextureSize: 2048 51 | textureSettings: 52 | serializedVersion: 2 53 | filterMode: -1 54 | aniso: -1 55 | mipBias: -100 56 | wrapU: 1 57 | wrapV: 1 58 | wrapW: -1 59 | nPOTScale: 0 60 | lightmap: 0 61 | compressionQuality: 50 62 | spriteMode: 2 63 | spriteExtrude: 1 64 | spriteMeshType: 1 65 | alignment: 0 66 | spritePivot: {x: 0.5, y: 0.5} 67 | spritePixelsToUnits: 128 68 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 69 | spriteGenerateFallbackPhysicsShape: 1 70 | alphaUsage: 1 71 | alphaIsTransparency: 1 72 | spriteTessellationDetail: -1 73 | textureType: 8 74 | textureShape: 1 75 | singleChannelComponent: 0 76 | maxTextureSizeSet: 0 77 | compressionQualitySet: 0 78 | textureFormatSet: 0 79 | ignorePngGamma: 0 80 | applyGammaDecoding: 0 81 | platformSettings: 82 | - serializedVersion: 3 83 | buildTarget: DefaultTexturePlatform 84 | maxTextureSize: 2048 85 | resizeAlgorithm: 0 86 | textureFormat: -1 87 | textureCompression: 2 88 | compressionQuality: 50 89 | crunchedCompression: 0 90 | allowsAlphaSplitting: 0 91 | overridden: 0 92 | androidETC2FallbackOverride: 0 93 | forceMaximumCompressionQuality_BC6H_BC7: 0 94 | - serializedVersion: 3 95 | buildTarget: Standalone 96 | maxTextureSize: 2048 97 | resizeAlgorithm: 0 98 | textureFormat: -1 99 | textureCompression: 2 100 | compressionQuality: 50 101 | crunchedCompression: 0 102 | allowsAlphaSplitting: 0 103 | overridden: 0 104 | androidETC2FallbackOverride: 0 105 | forceMaximumCompressionQuality_BC6H_BC7: 0 106 | - serializedVersion: 3 107 | buildTarget: iPhone 108 | maxTextureSize: 2048 109 | resizeAlgorithm: 0 110 | textureFormat: -1 111 | textureCompression: 2 112 | compressionQuality: 50 113 | crunchedCompression: 0 114 | allowsAlphaSplitting: 0 115 | overridden: 0 116 | androidETC2FallbackOverride: 0 117 | forceMaximumCompressionQuality_BC6H_BC7: 0 118 | - serializedVersion: 3 119 | buildTarget: Android 120 | maxTextureSize: 2048 121 | resizeAlgorithm: 0 122 | textureFormat: -1 123 | textureCompression: 2 124 | compressionQuality: 50 125 | crunchedCompression: 0 126 | allowsAlphaSplitting: 0 127 | overridden: 0 128 | androidETC2FallbackOverride: 0 129 | forceMaximumCompressionQuality_BC6H_BC7: 0 130 | - serializedVersion: 3 131 | buildTarget: WebGL 132 | maxTextureSize: 2048 133 | resizeAlgorithm: 0 134 | textureFormat: -1 135 | textureCompression: 2 136 | compressionQuality: 50 137 | crunchedCompression: 0 138 | allowsAlphaSplitting: 0 139 | overridden: 0 140 | androidETC2FallbackOverride: 0 141 | forceMaximumCompressionQuality_BC6H_BC7: 0 142 | spriteSheet: 143 | serializedVersion: 2 144 | sprites: 145 | - serializedVersion: 2 146 | name: Pipes_00 147 | rect: 148 | serializedVersion: 2 149 | x: 8 150 | y: 152 151 | width: 128 152 | height: 128 153 | alignment: 0 154 | pivot: {x: 0.5, y: 0.5} 155 | border: {x: 0, y: 0, z: 0, w: 0} 156 | outline: [] 157 | physicsShape: [] 158 | tessellationDetail: 0 159 | bones: [] 160 | spriteID: 7fed145c18f2181d0800000000000000 161 | internalID: -3350344413380223241 162 | vertices: [] 163 | indices: 164 | edges: [] 165 | weights: [] 166 | - serializedVersion: 2 167 | name: Pipes_01 168 | rect: 169 | serializedVersion: 2 170 | x: 152 171 | y: 152 172 | width: 128 173 | height: 128 174 | alignment: 0 175 | pivot: {x: 0.5, y: 0.5} 176 | border: {x: 0, y: 0, z: 0, w: 0} 177 | outline: [] 178 | physicsShape: [] 179 | tessellationDetail: 0 180 | bones: [] 181 | spriteID: 06ab76f05597d52f0800000000000000 182 | internalID: -982495737459262880 183 | vertices: [] 184 | indices: 185 | edges: [] 186 | weights: [] 187 | - serializedVersion: 2 188 | name: Pipes_02 189 | rect: 190 | serializedVersion: 2 191 | x: 296 192 | y: 152 193 | width: 128 194 | height: 128 195 | alignment: 0 196 | pivot: {x: 0.5, y: 0.5} 197 | border: {x: 0, y: 0, z: 0, w: 0} 198 | outline: [] 199 | physicsShape: [] 200 | tessellationDetail: 0 201 | bones: [] 202 | spriteID: 6e41fd621a0384350800000000000000 203 | internalID: 6001099972171207910 204 | vertices: [] 205 | indices: 206 | edges: [] 207 | weights: [] 208 | - serializedVersion: 2 209 | name: Pipes_03 210 | rect: 211 | serializedVersion: 2 212 | x: 8 213 | y: 8 214 | width: 128 215 | height: 128 216 | alignment: 0 217 | pivot: {x: 0.5, y: 0.5} 218 | border: {x: 0, y: 0, z: 0, w: 0} 219 | outline: [] 220 | physicsShape: [] 221 | tessellationDetail: 0 222 | bones: [] 223 | spriteID: f675f7a5692bbbc30800000000000000 224 | internalID: 4376287821753702255 225 | vertices: [] 226 | indices: 227 | edges: [] 228 | weights: [] 229 | - serializedVersion: 2 230 | name: Pipes_04 231 | rect: 232 | serializedVersion: 2 233 | x: 152 234 | y: 8 235 | width: 128 236 | height: 128 237 | alignment: 0 238 | pivot: {x: 0.5, y: 0.5} 239 | border: {x: 0, y: 0, z: 0, w: 0} 240 | outline: [] 241 | physicsShape: [] 242 | tessellationDetail: 0 243 | bones: [] 244 | spriteID: 6c0d90cf4843fd780800000000000000 245 | internalID: -8656142213013974842 246 | vertices: [] 247 | indices: 248 | edges: [] 249 | weights: [] 250 | - serializedVersion: 2 251 | name: Pipes_05 252 | rect: 253 | serializedVersion: 2 254 | x: 296 255 | y: 8 256 | width: 128 257 | height: 128 258 | alignment: 0 259 | pivot: {x: 0.5, y: 0.5} 260 | border: {x: 0, y: 0, z: 0, w: 0} 261 | outline: [] 262 | physicsShape: [] 263 | tessellationDetail: 0 264 | bones: [] 265 | spriteID: f1e1639adfaa65570800000000000000 266 | internalID: 8455133356877028895 267 | vertices: [] 268 | indices: 269 | edges: [] 270 | weights: [] 271 | outline: [] 272 | physicsShape: [] 273 | bones: [] 274 | spriteID: a10240c83e0c94dbaa728f513a672cd2 275 | internalID: 0 276 | vertices: [] 277 | indices: 278 | edges: [] 279 | weights: [] 280 | secondaryTextures: [] 281 | spritePackingTag: 282 | pSDRemoveMatte: 0 283 | pSDShowRemoveMatteOption: 1 284 | userData: 285 | assetBundleName: 286 | assetBundleVariant: 287 | -------------------------------------------------------------------------------- /Samples~/PipeRuleTile/Tiles/Pipes.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 9d1514134bc4fbd41bb739b1b9a49231, type: 3} 13 | m_Name: Pipes 14 | m_EditorClassIdentifier: 15 | m_DefaultSprite: {fileID: -3350344413380223241, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 16 | m_DefaultGameObject: {fileID: 0} 17 | m_DefaultColliderType: 1 18 | m_TilingRules: 19 | - m_Id: 4 20 | m_Sprites: 21 | - {fileID: -982495737459262880, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 22 | m_GameObject: {fileID: 0} 23 | m_AnimationSpeed: 1 24 | m_PerlinScale: 0.5 25 | m_Output: 0 26 | m_ColliderType: 1 27 | m_RandomTransform: 0 28 | m_Neighbors: 01000000010000000100000001000000 29 | m_NeighborPositions: 30 | - {x: 0, y: 1, z: 0} 31 | - {x: -1, y: 0, z: 0} 32 | - {x: 0, y: -1, z: 0} 33 | - {x: 1, y: 0, z: 0} 34 | m_RuleTransform: 0 35 | - m_Id: 3 36 | m_Sprites: 37 | - {fileID: 6001099972171207910, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 38 | m_GameObject: {fileID: 0} 39 | m_AnimationSpeed: 1 40 | m_PerlinScale: 0.5 41 | m_Output: 0 42 | m_ColliderType: 1 43 | m_RandomTransform: 0 44 | m_Neighbors: 010000000100000001000000 45 | m_NeighborPositions: 46 | - {x: 0, y: 1, z: 0} 47 | - {x: -1, y: 0, z: 0} 48 | - {x: 1, y: 0, z: 0} 49 | m_RuleTransform: 1 50 | - m_Id: 1 51 | m_Sprites: 52 | - {fileID: 4376287821753702255, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 53 | m_GameObject: {fileID: 0} 54 | m_AnimationSpeed: 1 55 | m_PerlinScale: 0.5 56 | m_Output: 0 57 | m_ColliderType: 1 58 | m_RandomTransform: 0 59 | m_Neighbors: 0100000001000000 60 | m_NeighborPositions: 61 | - {x: -1, y: 0, z: 0} 62 | - {x: 1, y: 0, z: 0} 63 | m_RuleTransform: 1 64 | - m_Id: 2 65 | m_Sprites: 66 | - {fileID: -8656142213013974842, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 67 | m_GameObject: {fileID: 0} 68 | m_AnimationSpeed: 1 69 | m_PerlinScale: 0.5 70 | m_Output: 0 71 | m_ColliderType: 1 72 | m_RandomTransform: 0 73 | m_Neighbors: 0100000001000000 74 | m_NeighborPositions: 75 | - {x: -1, y: 0, z: 0} 76 | - {x: 0, y: 1, z: 0} 77 | m_RuleTransform: 1 78 | - m_Id: 0 79 | m_Sprites: 80 | - {fileID: 8455133356877028895, guid: 1ebc1aff258f04220b2ce4e1240442fa, type: 3} 81 | m_GameObject: {fileID: 0} 82 | m_AnimationSpeed: 1 83 | m_PerlinScale: 0.5 84 | m_Output: 0 85 | m_ColliderType: 1 86 | m_RandomTransform: 0 87 | m_Neighbors: 01000000 88 | m_NeighborPositions: 89 | - {x: -1, y: 0, z: 0} 90 | m_RuleTransform: 1 91 | -------------------------------------------------------------------------------- /Samples~/PipeRuleTile/Tiles/Pipes.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3866e832eb1cd4493870232771332091 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/.sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "displayName": "Waterfall Animated Tile", 3 | "interactiveImport": "false", 4 | "description": "An example implementation of an Animated Tile.", 5 | } -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/Sprites/Waterfall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/2d-extras/8de698ac55b7ed01ec95a43e714c6358505b8110/Samples~/WaterfallAnimatedTile/Sprites/Waterfall.png -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/Tiles/Waterfall.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 13b75c95f34a00d4e8c04f76b73312e6, type: 3} 13 | m_Name: Waterfall 14 | m_EditorClassIdentifier: 15 | m_AnimatedSprites: 16 | - {fileID: 4721293536888397434, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 17 | - {fileID: 5364352939883245045, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 18 | - {fileID: 7196270143389622831, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 19 | - {fileID: 6029957480157117390, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 20 | - {fileID: -2507161886035769597, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 21 | m_MinSpeed: 1 22 | m_MaxSpeed: 1 23 | m_AnimationStartTime: 0 24 | m_AnimationStartFrame: 0 25 | m_TileColliderType: 0 26 | -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/Tiles/Waterfall.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9eb6880a443e94253bbdc5b52fa3e1d3 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/Tiles/Waterfall_Bottom.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 13b75c95f34a00d4e8c04f76b73312e6, type: 3} 13 | m_Name: Waterfall_Bottom 14 | m_EditorClassIdentifier: 15 | m_AnimatedSprites: 16 | - {fileID: 1725676371340164549, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 17 | - {fileID: 2872686455240326431, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 18 | - {fileID: 3786080894526622295, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 19 | - {fileID: 5045660051849922305, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 20 | - {fileID: 5612536237972652912, guid: ea3d66a7edd9d46d38e40be89ae8d3cf, type: 3} 21 | m_MinSpeed: 1 22 | m_MaxSpeed: 1 23 | m_AnimationStartTime: 0 24 | m_AnimationStartFrame: 0 25 | m_TileColliderType: 0 26 | -------------------------------------------------------------------------------- /Samples~/WaterfallAnimatedTile/Tiles/Waterfall_Bottom.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6cac02ba5b9814dbcb8988ddc06da6bb 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 0 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e501fe6c6911484c907a1a3b00692dd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b679ec8b3957ea64ebd2626843d0a81e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor/PlaceholderTests.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | 3 | internal class U2DExtrasPlaceholder 4 | { 5 | [Test] 6 | public void PlaceHolderTest() 7 | { 8 | Assert.Pass("2D Extras tests are in a separate package."); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Tests/Editor/PlaceholderTests.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1570cfa747cfb0647a5afa98d8babd66 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/Unity.2D.Tilemap.Extras.EditorTests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Unity.2D.Tilemap.Extras.Placeholder.EditorTests", 3 | "references": [ 4 | "UnityEngine.TestRunner", 5 | "UnityEditor.TestRunner" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": true, 13 | "precompiledReferences": [ 14 | "nunit.framework.dll" 15 | ], 16 | "autoReferenced": false, 17 | "defineConstraints": [ 18 | "UNITY_INCLUDE_TESTS" 19 | ], 20 | "versionDefines": [], 21 | "noEngineReferences": false 22 | } -------------------------------------------------------------------------------- /Tests/Editor/Unity.2D.Tilemap.Extras.EditorTests.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e1c163768a31b44ba01cc5392db861e 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Third Party Notices.md: -------------------------------------------------------------------------------- 1 | This package contains third-party software components governed by the license(s) indicated below: 2 | --------- 3 | 4 | Component Name: Line Brush 5 | public static IEnumerable GetPointsOnLine(Vector2Int p1, Vector2Int p2) 6 | http://ericw.ca/notes/bresenhams-line-algorithm-in-csharp.html 7 | 8 | License Type: MIT 9 | 10 | Copyright (c) 2020 Eric Woroshow 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | 18 | ericw.ca / Content © 2009-2020 Eric Woroshow. All rights reserved. 19 | Code under MIT license unless otherwise noted. 20 | 21 | --------- 22 | -------------------------------------------------------------------------------- /Third Party Notices.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d131a2d0c5c33464b90253c59096277f 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.unity.2d.tilemap.extras", 3 | "displayName": "2D Tilemap Extras", 4 | "version": "2.2.5", 5 | "unity": "2021.1", 6 | "description": "2D Tilemap Extras is a package that contains extra scripts for use with 2D Tilemap features in Unity. These include custom Tiles and Brushes for the Tilemap feature.\n\nThe following are included in the package:\nBrushes: GameObject Brush, Group Brush, Line Brush, Random Brush\nTiles: Animated Tile, Rule Tile, Rule Override Tile\nOther: Grid Information, Custom Rules for Rule Tile", 7 | "keywords": ["2d"], 8 | "category": "2D", 9 | "dependencies": { 10 | "com.unity.modules.tilemap": "1.0.0", 11 | "com.unity.2d.tilemap": "1.0.0", 12 | "com.unity.ugui": "1.0.0", 13 | "com.unity.modules.jsonserialize": "1.0.0" 14 | }, 15 | "relatedPackages": { 16 | "com.unity.2d.tilemap.extras.tests": "2.2.5" 17 | }, 18 | "samples": [ 19 | { 20 | "displayName": "Waterfall Animated Tile", 21 | "description": "An example implementation of an Animated Tile.", 22 | "path": "Samples~/WaterfallAnimatedTile" 23 | }, 24 | { 25 | "displayName": "Pipe Rule Tile", 26 | "description": "An example implementation of a Rule Tile with rules matching four-way orthogonal neighbors.", 27 | "path": "Samples~/PipeRuleTile" 28 | }, 29 | { 30 | "displayName": "Dungeon Rule Tile", 31 | "description": "An example implementation of a Rule Tile with rules matching eight-way orthogonal and diagonal neighbors.", 32 | "path": "Samples~/DungeonRuleTile" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9f15b7c9363d9944a7d69248fd279ec 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------