├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── Assets ├── Examples.meta ├── Examples │ ├── Basic Example.meta │ ├── Basic Example │ │ ├── Auto Stone.asset │ │ ├── Auto Stone.asset.meta │ │ ├── Basic Example.unity │ │ ├── Basic Example.unity.meta │ │ ├── Random Flower.asset │ │ ├── Random Flower.asset.meta │ │ ├── Rock.asset │ │ ├── Rock.asset.meta │ │ ├── tileset.png │ │ └── tileset.png.meta │ ├── Runtime Example.meta │ └── Runtime Example │ │ ├── Floor.asset │ │ ├── Floor.asset.meta │ │ ├── RandomWalk.cs │ │ ├── RandomWalk.cs.meta │ │ ├── Runtime Example.unity │ │ ├── Runtime Example.unity.meta │ │ ├── Wall.asset │ │ ├── Wall.asset.meta │ │ ├── dungeon tileset.png │ │ └── dungeon tileset.png.meta ├── toinfiniityandbeyond.meta └── toinfiniityandbeyond │ ├── Tilemap.meta │ ├── Tilemap │ ├── Editor.meta │ ├── Editor │ │ ├── AnimatedTileEditor.cs │ │ ├── AnimatedTileEditor.cs.meta │ │ ├── AutoTileEditor.cs │ │ ├── AutoTileEditor.cs.meta │ │ ├── RandomTileEditor.cs │ │ ├── RandomTileEditor.cs.meta │ │ ├── ScriptFactory.cs │ │ ├── ScriptFactory.cs.meta │ │ ├── ScriptableTileEditor.cs │ │ ├── ScriptableTileEditor.cs.meta │ │ ├── SimpleTileEditor.cs │ │ ├── SimpleTileEditor.cs.meta │ │ ├── TileMapContainerEditor.cs │ │ ├── TileMapContainerEditor.cs.meta │ │ ├── TileMapEditor.cs │ │ ├── TileMapEditor.cs.meta │ │ ├── TileMapInspectorEditor.cs │ │ ├── TileMapInspectorEditor.cs.meta │ │ ├── TileMapSceneEditor.cs │ │ ├── TileMapSceneEditor.cs.meta │ │ ├── TileMultipleQuadsRenderer.cs │ │ ├── TileMultipleQuadsRenderer.cs.meta │ │ ├── TileRendererEditor.cs │ │ ├── TileRendererEditor.cs.meta │ │ ├── TileSpriteRenderer.cs │ │ └── TileSpriteRenderer.cs.meta │ ├── Icons.meta │ ├── Icons │ │ ├── Tile Icon.png │ │ ├── Tile Icon.png.meta │ │ ├── Tile Script Icon.png │ │ ├── Tile Script Icon.png.meta │ │ ├── TileMap Icon.png │ │ ├── TileMap Icon.png.meta │ │ ├── TileMapContainer.png │ │ ├── TileMapContainer.png.meta │ │ ├── TileMapRenderer Icon.png │ │ ├── TileMapRenderer Icon.png.meta │ │ ├── Tool Icon.png │ │ ├── Tool Icon.png.meta │ │ ├── Tool Script Icon.png │ │ └── Tool Script Icon.png.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── Renderers.meta │ │ ├── Renderers │ │ ├── TileMultipleQuadsRenderer.cs │ │ ├── TileMultipleQuadsRenderer.cs.meta │ │ ├── TileRenderer.cs │ │ ├── TileRenderer.cs.meta │ │ ├── TileSpriteRenderer.cs │ │ └── TileSpriteRenderer.cs.meta │ │ ├── TileMap.cs │ │ ├── TileMap.cs.meta │ │ ├── TileMapContainer.cs │ │ ├── TileMapContainer.cs.meta │ │ ├── Tiles.meta │ │ ├── Tiles │ │ ├── AnimatedTile.cs │ │ ├── AnimatedTile.cs.meta │ │ ├── AutoTile.cs │ │ ├── AutoTile.cs.meta │ │ ├── RandomTile.cs │ │ ├── RandomTile.cs.meta │ │ ├── ScriptableTile.cs │ │ ├── ScriptableTile.cs.meta │ │ ├── SimpleTile.cs │ │ └── SimpleTile.cs.meta │ │ ├── Timeline.cs │ │ ├── Timeline.cs.meta │ │ ├── Tools.meta │ │ └── Tools │ │ ├── Brush.cs │ │ ├── Brush.cs.meta │ │ ├── Elipse.cs │ │ ├── Elipse.cs.meta │ │ ├── Eraser.cs │ │ ├── Eraser.cs.meta │ │ ├── Eyedropper.cs │ │ ├── Eyedropper.cs.meta │ │ ├── Fill.cs │ │ ├── Fill.cs.meta │ │ ├── Line.cs │ │ ├── Line.cs.meta │ │ ├── Pencil.cs │ │ ├── Pencil.cs.meta │ │ ├── Rectangle.cs │ │ ├── Rectangle.cs.meta │ │ ├── ScriptableTool.cs │ │ └── ScriptableTool.cs.meta │ ├── Utility.meta │ └── Utility │ ├── Editor.meta │ ├── Editor │ ├── EditorStyleViewer.cs │ ├── EditorStyleViewer.cs.meta │ ├── MyGUI.cs │ ├── MyGUI.cs.meta │ ├── ScriptableObjectUtility.cs │ ├── ScriptableObjectUtility.cs.meta │ ├── UnityTextures.cs │ └── UnityTextures.cs.meta │ ├── Point.cs │ ├── Point.cs.meta │ ├── SpriteExtensionMethods.cs │ └── SpriteExtensionMethods.cs.meta ├── LICENSE.md ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset ├── README.md └── images └── banner.gif /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /.vscode/ 7 | /Assets/AssetStoreTools* 8 | 9 | # Autogenerated VS/MD solution and project files 10 | ExportedObj/ 11 | *.csproj 12 | *.unityproj 13 | *.sln 14 | *.suo 15 | *.tmp 16 | *.user 17 | *.userprefs 18 | *.pidb 19 | *.booproj 20 | *.svd 21 | *.vscode 22 | 23 | 24 | # Unity3D generated meta files 25 | *.pidb.meta 26 | 27 | # Unity3D Generated File On Crash Reports 28 | sysinfo.txt 29 | 30 | # Builds 31 | *.apk 32 | *.unitypackage 33 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Unity Editor", 6 | "type": "unity", 7 | "request": "launch" 8 | }, 9 | { 10 | "name": "Windows Player", 11 | "type": "unity", 12 | "request": "launch" 13 | }, 14 | { 15 | "name": "OSX Player", 16 | "type": "unity", 17 | "request": "launch" 18 | }, 19 | { 20 | "name": "Linux Player", 21 | "type": "unity", 22 | "request": "launch" 23 | }, 24 | { 25 | "name": "iOS Player", 26 | "type": "unity", 27 | "request": "launch" 28 | }, 29 | { 30 | "name": "Android Player", 31 | "type": "unity", 32 | "request": "launch" 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | // Configure glob patterns for excluding files and folders. 4 | "files.exclude": { 5 | "**/.git": true, 6 | "**/.DS_Store": true, 7 | "**/*.meta": true, 8 | "**/*.*.meta": true, 9 | "**/*.unity": true, 10 | "**/*.unityproj": true, 11 | "**/*.mat": true, 12 | "**/*.fbx": true, 13 | "**/*.FBX": true, 14 | "**/*.tga": true, 15 | "**/*.cubemap": true, 16 | "**/**.prefab": true, 17 | "**/Library": true, 18 | "**/ProjectSettings": true, 19 | "**/Temp": true 20 | } 21 | } -------------------------------------------------------------------------------- /Assets/Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30a6bd7971ad45c4ea7894600f2c618f 3 | folderAsset: yes 4 | timeCreated: 1471300328 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2ce5727b8e3cfb40b2a72fdec612847 3 | folderAsset: yes 4 | timeCreated: 1472899571 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Auto Stone.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Basic Example/Auto Stone.asset -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Auto Stone.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d6d823f9ba7ed9459d5bfc8975fb5d4 3 | timeCreated: 1471800303 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Basic Example.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Basic Example/Basic Example.unity -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Basic Example.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1cc2e61cef3400144b2a25983ee099b7 3 | timeCreated: 1471300328 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Random Flower.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Basic Example/Random Flower.asset -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Random Flower.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 365dfe1feb343e643b537bbf6dd71249 3 | timeCreated: 1471885321 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Rock.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Basic Example/Rock.asset -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/Rock.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2caf168ae7231dc44b8a5fdc2b3226fd 3 | timeCreated: 1472854040 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Basic Example/tileset.png -------------------------------------------------------------------------------- /Assets/Examples/Basic Example/tileset.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf1e0d7b33e02a74baa4426f7dd04665 3 | timeCreated: 1472855014 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: 7 | 21300000: tileset_0 8 | 21300002: tileset_1 9 | 21300004: tileset_2 10 | 21300006: tileset_3 11 | 21300008: tileset_4 12 | 21300010: tileset_5 13 | 21300012: tileset_6 14 | 21300014: tileset_7 15 | 21300016: tileset_8 16 | 21300018: tileset_9 17 | 21300020: tileset_10 18 | 21300022: tileset_11 19 | 21300024: tileset_12 20 | 21300026: tileset_13 21 | 21300028: tileset_14 22 | 21300030: tileset_15 23 | 21300032: tileset_16 24 | 21300034: tileset_17 25 | 21300036: tileset_18 26 | 21300038: tileset_19 27 | 21300040: tileset_20 28 | 21300042: tileset_21 29 | 21300044: tileset_22 30 | serializedVersion: 2 31 | mipmaps: 32 | mipMapMode: 0 33 | enableMipMap: 0 34 | linearTexture: 0 35 | correctGamma: 0 36 | fadeOut: 0 37 | borderMipMap: 0 38 | mipMapFadeDistanceStart: 1 39 | mipMapFadeDistanceEnd: 3 40 | bumpmap: 41 | convertToNormalMap: 0 42 | externalNormalMap: 0 43 | heightScale: 0.25 44 | normalMapFilter: 0 45 | isReadable: 1 46 | grayScaleToAlpha: 0 47 | generateCubemap: 0 48 | cubemapConvolution: 0 49 | cubemapConvolutionSteps: 7 50 | cubemapConvolutionExponent: 1.5 51 | seamlessCubemap: 0 52 | textureFormat: -3 53 | maxTextureSize: 256 54 | textureSettings: 55 | filterMode: 0 56 | aniso: 16 57 | mipBias: -1 58 | wrapMode: 1 59 | nPOTScale: 0 60 | lightmap: 0 61 | rGBM: 0 62 | compressionQuality: 50 63 | allowsAlphaSplitting: 0 64 | spriteMode: 2 65 | spriteExtrude: 1 66 | spriteMeshType: 1 67 | alignment: 6 68 | spritePivot: {x: 0.5, y: 0.5} 69 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 70 | spritePixelsToUnits: 16 71 | alphaIsTransparency: 1 72 | spriteTessellationDetail: -1 73 | textureType: 5 74 | buildTargetSettings: [] 75 | spriteSheet: 76 | serializedVersion: 2 77 | sprites: 78 | - serializedVersion: 2 79 | name: tileset_0 80 | rect: 81 | serializedVersion: 2 82 | x: 0 83 | y: 16 84 | width: 16 85 | height: 16 86 | alignment: 6 87 | pivot: {x: 0, y: 0} 88 | border: {x: 0, y: 0, z: 0, w: 0} 89 | outline: [] 90 | tessellationDetail: 0 91 | - serializedVersion: 2 92 | name: tileset_1 93 | rect: 94 | serializedVersion: 2 95 | x: 16 96 | y: 16 97 | width: 16 98 | height: 16 99 | alignment: 6 100 | pivot: {x: 0, y: 0} 101 | border: {x: 0, y: 0, z: 0, w: 0} 102 | outline: [] 103 | tessellationDetail: 0 104 | - serializedVersion: 2 105 | name: tileset_2 106 | rect: 107 | serializedVersion: 2 108 | x: 32 109 | y: 16 110 | width: 16 111 | height: 16 112 | alignment: 6 113 | pivot: {x: 0, y: 0} 114 | border: {x: 0, y: 0, z: 0, w: 0} 115 | outline: [] 116 | tessellationDetail: 0 117 | - serializedVersion: 2 118 | name: tileset_3 119 | rect: 120 | serializedVersion: 2 121 | x: 48 122 | y: 16 123 | width: 16 124 | height: 16 125 | alignment: 6 126 | pivot: {x: 0, y: 0} 127 | border: {x: 0, y: 0, z: 0, w: 0} 128 | outline: [] 129 | tessellationDetail: 0 130 | - serializedVersion: 2 131 | name: tileset_4 132 | rect: 133 | serializedVersion: 2 134 | x: 64 135 | y: 16 136 | width: 16 137 | height: 16 138 | alignment: 6 139 | pivot: {x: 0, y: 0} 140 | border: {x: 0, y: 0, z: 0, w: 0} 141 | outline: [] 142 | tessellationDetail: 0 143 | - serializedVersion: 2 144 | name: tileset_5 145 | rect: 146 | serializedVersion: 2 147 | x: 80 148 | y: 16 149 | width: 16 150 | height: 16 151 | alignment: 6 152 | pivot: {x: 0, y: 0} 153 | border: {x: 0, y: 0, z: 0, w: 0} 154 | outline: [] 155 | tessellationDetail: 0 156 | - serializedVersion: 2 157 | name: tileset_6 158 | rect: 159 | serializedVersion: 2 160 | x: 96 161 | y: 16 162 | width: 16 163 | height: 16 164 | alignment: 6 165 | pivot: {x: 0, y: 0} 166 | border: {x: 0, y: 0, z: 0, w: 0} 167 | outline: [] 168 | tessellationDetail: 0 169 | - serializedVersion: 2 170 | name: tileset_7 171 | rect: 172 | serializedVersion: 2 173 | x: 112 174 | y: 16 175 | width: 16 176 | height: 16 177 | alignment: 6 178 | pivot: {x: 0, y: 0} 179 | border: {x: 0, y: 0, z: 0, w: 0} 180 | outline: [] 181 | tessellationDetail: 0 182 | - serializedVersion: 2 183 | name: tileset_8 184 | rect: 185 | serializedVersion: 2 186 | x: 128 187 | y: 16 188 | width: 16 189 | height: 16 190 | alignment: 6 191 | pivot: {x: 0, y: 0} 192 | border: {x: 0, y: 0, z: 0, w: 0} 193 | outline: [] 194 | tessellationDetail: 0 195 | - serializedVersion: 2 196 | name: tileset_9 197 | rect: 198 | serializedVersion: 2 199 | x: 144 200 | y: 16 201 | width: 16 202 | height: 16 203 | alignment: 6 204 | pivot: {x: 0, y: 0} 205 | border: {x: 0, y: 0, z: 0, w: 0} 206 | outline: [] 207 | tessellationDetail: 0 208 | - serializedVersion: 2 209 | name: tileset_10 210 | rect: 211 | serializedVersion: 2 212 | x: 160 213 | y: 16 214 | width: 16 215 | height: 16 216 | alignment: 6 217 | pivot: {x: 0, y: 0} 218 | border: {x: 0, y: 0, z: 0, w: 0} 219 | outline: [] 220 | tessellationDetail: 0 221 | - serializedVersion: 2 222 | name: tileset_11 223 | rect: 224 | serializedVersion: 2 225 | x: 176 226 | y: 16 227 | width: 16 228 | height: 16 229 | alignment: 6 230 | pivot: {x: 0, y: 0} 231 | border: {x: 0, y: 0, z: 0, w: 0} 232 | outline: [] 233 | tessellationDetail: 0 234 | - serializedVersion: 2 235 | name: tileset_12 236 | rect: 237 | serializedVersion: 2 238 | x: 192 239 | y: 16 240 | width: 16 241 | height: 16 242 | alignment: 6 243 | pivot: {x: 0, y: 0} 244 | border: {x: 0, y: 0, z: 0, w: 0} 245 | outline: [] 246 | tessellationDetail: 0 247 | - serializedVersion: 2 248 | name: tileset_13 249 | rect: 250 | serializedVersion: 2 251 | x: 208 252 | y: 16 253 | width: 16 254 | height: 16 255 | alignment: 6 256 | pivot: {x: 0, y: 0} 257 | border: {x: 0, y: 0, z: 0, w: 0} 258 | outline: [] 259 | tessellationDetail: 0 260 | - serializedVersion: 2 261 | name: tileset_14 262 | rect: 263 | serializedVersion: 2 264 | x: 224 265 | y: 16 266 | width: 16 267 | height: 16 268 | alignment: 6 269 | pivot: {x: 0, y: 0} 270 | border: {x: 0, y: 0, z: 0, w: 0} 271 | outline: [] 272 | tessellationDetail: 0 273 | - serializedVersion: 2 274 | name: tileset_15 275 | rect: 276 | serializedVersion: 2 277 | x: 240 278 | y: 16 279 | width: 16 280 | height: 16 281 | alignment: 6 282 | pivot: {x: 0, y: 0} 283 | border: {x: 0, y: 0, z: 0, w: 0} 284 | outline: [] 285 | tessellationDetail: 0 286 | - serializedVersion: 2 287 | name: tileset_16 288 | rect: 289 | serializedVersion: 2 290 | x: 0 291 | y: 0 292 | width: 16 293 | height: 16 294 | alignment: 6 295 | pivot: {x: 0, y: 0} 296 | border: {x: 0, y: 0, z: 0, w: 0} 297 | outline: [] 298 | tessellationDetail: 0 299 | - serializedVersion: 2 300 | name: tileset_17 301 | rect: 302 | serializedVersion: 2 303 | x: 16 304 | y: 0 305 | width: 16 306 | height: 16 307 | alignment: 6 308 | pivot: {x: 0, y: 0} 309 | border: {x: 0, y: 0, z: 0, w: 0} 310 | outline: [] 311 | tessellationDetail: 0 312 | - serializedVersion: 2 313 | name: tileset_18 314 | rect: 315 | serializedVersion: 2 316 | x: 32 317 | y: 0 318 | width: 16 319 | height: 16 320 | alignment: 6 321 | pivot: {x: 0, y: 0} 322 | border: {x: 0, y: 0, z: 0, w: 0} 323 | outline: [] 324 | tessellationDetail: 0 325 | - serializedVersion: 2 326 | name: tileset_22 327 | rect: 328 | serializedVersion: 2 329 | x: 48 330 | y: 0 331 | width: 16 332 | height: 16 333 | alignment: 6 334 | pivot: {x: 0, y: 0} 335 | border: {x: 0, y: 0, z: 0, w: 0} 336 | outline: [] 337 | tessellationDetail: 0 338 | outline: [] 339 | spritePackingTag: 340 | userData: 341 | assetBundleName: 342 | assetBundleVariant: 343 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa260e831f413c54b936fb311059920a 3 | folderAsset: yes 4 | timeCreated: 1472899592 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Floor.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Runtime Example/Floor.asset -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Floor.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65c87dbbeefda694cb4dc321765f3d57 3 | timeCreated: 1472984875 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/RandomWalk.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using toinfiniityandbeyond.Tilemapping; 4 | 5 | public class RandomWalk : MonoBehaviour 6 | { 7 | [SerializeField] 8 | private int maxSize = 60; 9 | [SerializeField] 10 | private int steps = 20; 11 | [SerializeField] 12 | private ScriptableTile floor, wall; 13 | 14 | private TileMap tileMap; 15 | 16 | private void Start() 17 | { 18 | tileMap = GetComponent(); 19 | StartCoroutine("Generate"); 20 | } 21 | private IEnumerator Generate() 22 | { 23 | int width = 50;//andom.Range(10, maxSize); 24 | int height = 50;//Random.Range(10, maxSize); 25 | tileMap.Resize(width, height); 26 | for (int x = 0; x <= width; x++) 27 | { 28 | for (int y = 0; y <= height; y++) 29 | { 30 | tileMap.SetTileAt(x, y, wall); 31 | } 32 | } 33 | Point midPoint = new Point(width / 2, height / 2); 34 | Point currentPoint = midPoint; 35 | for (int i = 0; i < steps; i++) 36 | { 37 | Point lastPoint = currentPoint; 38 | tileMap.SetTileAt(currentPoint, floor); 39 | while (lastPoint == currentPoint || !tileMap.IsInBounds(currentPoint)) 40 | { 41 | int randomIndex = Random.Range(0, 4); 42 | switch (randomIndex) 43 | { 44 | case 0: 45 | currentPoint = currentPoint.Left; 46 | break; 47 | case 1: 48 | currentPoint = currentPoint.Up; 49 | break; 50 | case 2: 51 | currentPoint = currentPoint.Right; 52 | break; 53 | case 3: 54 | currentPoint = currentPoint.Down; 55 | break; 56 | default: 57 | Debug.Log("uh oh!"); 58 | break; 59 | } 60 | } 61 | yield return null; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/RandomWalk.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e80bd136cdd10e43815be8b8f7cc351 3 | timeCreated: 1472902330 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Runtime Example.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Runtime Example/Runtime Example.unity -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Runtime Example.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 884972591f6bfc44294de73eb2a381a9 3 | timeCreated: 1472899844 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Wall.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Runtime Example/Wall.asset -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/Wall.asset.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a1ec9a5c9e034874fa3c988fbc474534 3 | timeCreated: 1472984349 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/dungeon tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/Examples/Runtime Example/dungeon tileset.png -------------------------------------------------------------------------------- /Assets/Examples/Runtime Example/dungeon tileset.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d83e2b6d203c5154c8dadc2257a42e21 3 | timeCreated: 1472986149 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: 7 | 21300000: floor 8 | 21300002: soundsheett_vFinal (1)_1 9 | 21300004: soundsheett_vFinal (1)_2 10 | 21300006: soundsheett_vFinal (1)_3 11 | 21300008: empty space 12 | 21300010: wall 13 | 21300012: soundsheett_vFinal (1)_6 14 | 21300014: soundsheett_vFinal (1)_7 15 | 21300016: soundsheett_vFinal (1)_8 16 | 21300018: soundsheett_vFinal (1)_9 17 | 21300020: wall1 18 | 21300022: soundsheett_vFinal (1)_11 19 | 21300024: soundsheett_vFinal (1)_12 20 | 21300026: soundsheett_vFinal (1)_13 21 | 21300028: soundsheett_vFinal (1)_14 22 | 21300030: soundsheett_vFinal (1)_15 23 | 21300032: soundsheett_vFinal (1)_16 24 | 21300034: soundsheett_vFinal (1)_17 25 | 21300036: soundsheett_vFinal (1)_18 26 | 21300038: soundsheett_vFinal (1)_19 27 | 21300040: soundsheett_vFinal (1)_20 28 | 21300042: soundsheett_vFinal (1)_21 29 | 21300044: soundsheett_vFinal (1)_22 30 | 21300046: soundsheett_vFinal (1)_23 31 | 21300048: soundsheett_vFinal (1)_24 32 | 21300050: soundsheett_vFinal (1)_25 33 | 21300052: soundsheett_vFinal (1)_26 34 | 21300054: soundsheett_vFinal (1)_27 35 | 21300056: soundsheett_vFinal (1)_28 36 | 21300058: soundsheett_vFinal (1)_29 37 | 21300060: soundsheett_vFinal (1)_30 38 | 21300062: soundsheett_vFinal (1)_31 39 | 21300064: soundsheett_vFinal (1)_32 40 | 21300066: soundsheett_vFinal (1)_33 41 | 21300068: soundsheett_vFinal (1)_34 42 | 21300070: soundsheett_vFinal (1)_35 43 | 21300072: soundsheett_vFinal (1)_36 44 | 21300074: soundsheett_vFinal (1)_37 45 | 21300076: soundsheett_vFinal (1)_38 46 | 21300078: soundsheett_vFinal (1)_39 47 | 21300080: soundsheett_vFinal (1)_40 48 | 21300082: soundsheett_vFinal (1)_41 49 | 21300084: soundsheett_vFinal (1)_42 50 | 21300086: soundsheett_vFinal (1)_43 51 | 21300088: soundsheett_vFinal (1)_44 52 | 21300090: soundsheett_vFinal (1)_45 53 | 21300092: soundsheett_vFinal (1)_46 54 | 21300094: soundsheett_vFinal (1)_47 55 | 21300096: soundsheett_vFinal (1)_48 56 | 21300098: soundsheett_vFinal (1)_49 57 | 21300100: soundsheett_vFinal (1)_50 58 | 21300102: soundsheett_vFinal (1)_51 59 | 21300104: soundsheett_vFinal (1)_52 60 | 21300106: soundsheett_vFinal (1)_53 61 | 21300108: soundsheett_vFinal (1)_54 62 | 21300110: soundsheett_vFinal (1)_55 63 | 21300112: soundsheett_vFinal (1)_56 64 | 21300114: soundsheett_vFinal (1)_57 65 | 21300116: soundsheett_vFinal (1)_58 66 | 21300118: soundsheett_vFinal (1)_59 67 | 21300120: soundsheett_vFinal (1)_60 68 | 21300122: soundsheett_vFinal (1)_61 69 | 21300124: soundsheett_vFinal (1)_62 70 | 21300126: soundsheett_vFinal (1)_63 71 | 21300128: soundsheett_vFinal (1)_64 72 | 21300130: soundsheett_vFinal (1)_65 73 | 21300132: soundsheett_vFinal (1)_66 74 | 21300134: soundsheett_vFinal (1)_67 75 | 21300136: soundsheett_vFinal (1)_68 76 | 21300138: soundsheett_vFinal (1)_69 77 | 21300140: soundsheett_vFinal (1)_70 78 | 21300142: soundsheett_vFinal (1)_71 79 | 21300144: soundsheett_vFinal (1)_72 80 | 21300146: soundsheett_vFinal (1)_73 81 | 21300148: soundsheett_vFinal (1)_74 82 | 21300150: soundsheett_vFinal (1)_75 83 | 21300152: soundsheett_vFinal (1)_76 84 | 21300154: soundsheett_vFinal (1)_77 85 | 21300156: soundsheett_vFinal (1)_78 86 | 21300158: soundsheett_vFinal (1)_79 87 | 21300160: soundsheett_vFinal (1)_80 88 | 21300162: soundsheett_vFinal (1)_81 89 | 21300164: soundsheett_vFinal (1)_82 90 | 21300166: soundsheett_vFinal (1)_83 91 | 21300168: soundsheett_vFinal (1)_84 92 | 21300170: soundsheett_vFinal (1)_85 93 | 21300172: soundsheett_vFinal (1)_86 94 | 21300174: soundsheett_vFinal (1)_87 95 | 21300176: soundsheett_vFinal (1)_88 96 | 21300178: soundsheett_vFinal (1)_89 97 | 21300180: soundsheett_vFinal (1)_90 98 | 21300182: soundsheett_vFinal (1)_91 99 | 21300184: soundsheett_vFinal (1)_92 100 | 21300186: soundsheett_vFinal (1)_93 101 | 21300188: soundsheett_vFinal (1)_94 102 | 21300190: soundsheett_vFinal (1)_95 103 | 21300192: soundsheett_vFinal (1)_96 104 | 21300194: soundsheett_vFinal (1)_97 105 | 21300196: soundsheett_vFinal (1)_98 106 | 21300198: soundsheett_vFinal (1)_99 107 | 21300200: soundsheett_vFinal (1)_100 108 | 21300202: soundsheett_vFinal (1)_101 109 | 21300204: soundsheett_vFinal (1)_102 110 | 21300206: soundsheett_vFinal (1)_103 111 | 21300208: soundsheett_vFinal (1)_104 112 | 21300210: soundsheett_vFinal (1)_105 113 | 21300212: soundsheett_vFinal (1)_106 114 | 21300214: soundsheett_vFinal (1)_107 115 | 21300216: soundsheett_vFinal (1)_108 116 | 21300218: soundsheett_vFinal (1)_109 117 | 21300220: soundsheett_vFinal (1)_110 118 | 21300222: soundsheett_vFinal (1)_111 119 | 21300224: soundsheett_vFinal (1)_112 120 | 21300226: soundsheett_vFinal (1)_113 121 | 21300228: soundsheett_vFinal (1)_114 122 | 21300230: soundsheett_vFinal (1)_115 123 | 21300232: soundsheett_vFinal (1)_116 124 | 21300234: soundsheett_vFinal (1)_117 125 | 21300236: soundsheett_vFinal (1)_118 126 | 21300238: soundsheett_vFinal (1)_119 127 | 21300240: soundsheett_vFinal (1)_120 128 | 21300242: soundsheett_vFinal (1)_121 129 | 21300244: soundsheett_vFinal (1)_122 130 | 21300246: soundsheett_vFinal (1)_123 131 | 21300248: soundsheett_vFinal (1)_124 132 | 21300250: soundsheett_vFinal (1)_125 133 | 21300252: soundsheett_vFinal (1)_126 134 | 21300254: soundsheett_vFinal (1)_127 135 | 21300256: soundsheett_vFinal (1)_128 136 | 21300258: soundsheett_vFinal (1)_129 137 | 21300260: soundsheett_vFinal (1)_130 138 | 21300262: soundsheett_vFinal (1)_131 139 | 21300264: soundsheett_vFinal (1)_132 140 | 21300266: soundsheett_vFinal (1)_133 141 | 21300268: soundsheett_vFinal (1)_134 142 | 21300270: soundsheett_vFinal (1)_135 143 | 21300272: soundsheett_vFinal (1)_136 144 | 21300274: soundsheett_vFinal (1)_137 145 | 21300276: Wall Full 146 | 21300278: Wall 147 | 21300280: Floor 148 | serializedVersion: 2 149 | mipmaps: 150 | mipMapMode: 0 151 | enableMipMap: 0 152 | linearTexture: 0 153 | correctGamma: 0 154 | fadeOut: 0 155 | borderMipMap: 0 156 | mipMapFadeDistanceStart: 1 157 | mipMapFadeDistanceEnd: 3 158 | bumpmap: 159 | convertToNormalMap: 0 160 | externalNormalMap: 0 161 | heightScale: 0.25 162 | normalMapFilter: 0 163 | isReadable: 1 164 | grayScaleToAlpha: 0 165 | generateCubemap: 0 166 | cubemapConvolution: 0 167 | cubemapConvolutionSteps: 7 168 | cubemapConvolutionExponent: 1.5 169 | seamlessCubemap: 0 170 | textureFormat: -3 171 | maxTextureSize: 256 172 | textureSettings: 173 | filterMode: 0 174 | aniso: 16 175 | mipBias: -1 176 | wrapMode: 0 177 | nPOTScale: 0 178 | lightmap: 0 179 | rGBM: 0 180 | compressionQuality: 50 181 | allowsAlphaSplitting: 0 182 | spriteMode: 2 183 | spriteExtrude: 1 184 | spriteMeshType: 0 185 | alignment: 0 186 | spritePivot: {x: 0.5, y: 0.5} 187 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 188 | spritePixelsToUnits: 8 189 | alphaIsTransparency: 1 190 | spriteTessellationDetail: -1 191 | textureType: 5 192 | buildTargetSettings: [] 193 | spriteSheet: 194 | serializedVersion: 2 195 | sprites: 196 | - serializedVersion: 2 197 | name: Wall Full 198 | rect: 199 | serializedVersion: 2 200 | x: 40 201 | y: 176 202 | width: 8 203 | height: 8 204 | alignment: 6 205 | pivot: {x: 0, y: 0} 206 | border: {x: 0, y: 0, z: 0, w: 0} 207 | outline: [] 208 | tessellationDetail: 0 209 | - serializedVersion: 2 210 | name: Wall 211 | rect: 212 | serializedVersion: 2 213 | x: 32 214 | y: 168 215 | width: 8 216 | height: 8 217 | alignment: 6 218 | pivot: {x: 0, y: 0} 219 | border: {x: 0, y: 0, z: 0, w: 0} 220 | outline: [] 221 | tessellationDetail: 0 222 | - serializedVersion: 2 223 | name: Floor 224 | rect: 225 | serializedVersion: 2 226 | x: 0 227 | y: 176 228 | width: 8 229 | height: 8 230 | alignment: 6 231 | pivot: {x: 0, y: 0} 232 | border: {x: 0, y: 0, z: 0, w: 0} 233 | outline: [] 234 | tessellationDetail: 0 235 | outline: [] 236 | spritePackingTag: 237 | userData: 238 | assetBundleName: 239 | assetBundleVariant: 240 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87084aa4abe4ca144ba2380f238098fc 3 | folderAsset: yes 4 | timeCreated: 1471540543 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 026110ab79f725e49929d6409e77e900 3 | folderAsset: yes 4 | timeCreated: 1471538937 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89a0fa5c323ab644688acd39b44cf5f7 3 | folderAsset: yes 4 | timeCreated: 1471308203 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/AnimatedTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [CustomEditor (typeof (AnimatedTile))] 8 | public class AnimatedTileEditor : ScriptableTileEditor 9 | { 10 | public void OnEnable() 11 | { 12 | 13 | } 14 | 15 | public override void OnInspectorGUI() 16 | { 17 | 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/AnimatedTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e76c5b615461aa4439fe97b0d603a977 3 | timeCreated: 1471912553 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/AutoTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using toinfiniityandbeyond.Utillity; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping { 6 | [CustomEditor (typeof (AutoTile))] 7 | public class AutoTileEditor : ScriptableTileEditor 8 | { 9 | private AutoTile autoTile; 10 | 11 | private int [,] indexLookup = new int [,] 12 | { 13 | { 4, 6, 14 ,12 }, 14 | { 5 ,7 ,15, 13 }, 15 | { 1 ,3 ,11, 9 }, 16 | { 0 ,2 ,10, 8 }, 17 | }; 18 | private string [,] symbolLookup = new string [,] 19 | { 20 | { "╻", "┏", "┳", "┓" }, 21 | { "┃", "┣", "╋", "┫" }, 22 | { "╹", "┗", "┻", "┛" }, 23 | { "▪", "╺", "━", "╸" }, 24 | }; 25 | private void OnEnable() 26 | { 27 | autoTile = (AutoTile)target; 28 | if (autoTile.bitmaskSprites.Length != 16) 29 | autoTile.bitmaskSprites = new Sprite [16]; 30 | } 31 | public override void OnInspectorGUI () 32 | { 33 | EditorGUILayout.HelpBox ("Fill the grid below with tiles in the '4x4' layout. Click the help button for more info.", MessageType.Info); 34 | GUILayout.Label ("Sprites:", MyStyles.leftBoldLabel); 35 | 36 | int size = 4; 37 | float sizePerButton = EditorGUIUtility.currentViewWidth / size - 15; 38 | GUILayout.BeginHorizontal(); 39 | for (int x = 0; x < size; x++) 40 | { 41 | GUILayout.BeginVertical (); 42 | for (int y = 0; y < size; y++) 43 | { 44 | GUILayout.BeginHorizontal (); 45 | 46 | int index = indexLookup [y, x]; 47 | 48 | string labelText = index.ToString(); 49 | 50 | if (!autoTile.bitmaskSprites [index]) 51 | { 52 | if (index == 15) { 53 | GUI.color = new Color (1, 0.5f, 0.5f); 54 | labelText = "Tile not valid!"; 55 | } 56 | else { 57 | GUI.color = new Color (1, 0.9f, 0.5f); 58 | labelText = "Empty"; 59 | } 60 | } else if (!autoTile.IsElementValid (index)) 61 | { 62 | GUI.color = new Color (1, 0.5f, 0.5f); 63 | labelText = "Enable read/write"; 64 | } 65 | if (GUILayout.Button (GUIContent.none, MyStyles.centerWhiteBoldLabel, GUILayout.Width (sizePerButton), GUILayout.Height (sizePerButton))) 66 | { 67 | EditorGUIUtility.ShowObjectPicker (autoTile.bitmaskSprites [index], false, "", index); 68 | } 69 | Rect r = GUILayoutUtility.GetLastRect (); 70 | 71 | Texture2D texture = autoTile.IsElementValid (index) ? autoTile.bitmaskSprites [index].ToTexture2D() : new Texture2D(16, 16); 72 | GUI.DrawTexture (r, texture); 73 | GUI.color = Color.white; 74 | 75 | GUIStyle labelStyle = new GUIStyle(MyStyles.centerWhiteBoldLabel); 76 | 77 | GUI.Label (r, labelText, labelStyle); 78 | 79 | GUIStyle symbolStyle = new GUIStyle(MyStyles.centerWhiteBoldLabel); 80 | symbolStyle.fontSize = 60; 81 | symbolStyle.normal.textColor = new Color(1, 1, 1, 0.3f); 82 | GUI.Label (r, symbolLookup[y, x], symbolStyle); 83 | 84 | GUILayout.EndHorizontal (); 85 | } 86 | GUILayout.EndVertical (); 87 | } 88 | GUILayout.EndHorizontal (); 89 | 90 | GUILayout.Label ("Settings:", MyStyles.leftBoldLabel); 91 | autoTile.edgesAreFull = EditorGUILayout.Toggle ("Edges are full", autoTile.edgesAreFull); 92 | autoTile.mode = (AutoTile.AutoTileMode)EditorGUILayout.EnumPopup("Tiling Mode", autoTile.mode); 93 | 94 | int controlID = EditorGUIUtility.GetObjectPickerControlID (); 95 | if (Event.current.commandName == "ObjectSelectorUpdated") 96 | { 97 | autoTile.bitmaskSprites [controlID] = EditorGUIUtility.GetObjectPickerObject () as Sprite; 98 | } 99 | if(GUI.changed) 100 | { 101 | EditorUtility.SetDirty (this); 102 | } 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/AutoTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3596036a89ab1de4f82ec16a8cd0c638 3 | timeCreated: 1471817335 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/RandomTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using toinfiniityandbeyond.Utillity; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [CustomEditor(typeof(RandomTile))] 8 | public class RandomTileEditor : ScriptableTileEditor 9 | { 10 | private RandomTile tile; 11 | 12 | private void OnEnable() 13 | { 14 | tile = (RandomTile)target; 15 | } 16 | public override void OnInspectorGUI() 17 | { 18 | GUILayout.Space(10); 19 | EditorGUILayout.HelpBox("This tile randomly chooses a sprite from the list below to render. It is based on position and the seed.", MessageType.Info); 20 | tile.globalSeed = EditorGUILayout.IntField("Global Seed:", tile.globalSeed); 21 | GUILayout.Space(10); 22 | 23 | GUILayout.BeginHorizontal(); 24 | GUILayout.Label("Sprites:", MyStyles.leftBoldLabel); 25 | GUILayout.FlexibleSpace(); 26 | GUI.color = new Color(0.5f, 1, 0.5f); 27 | if (GUILayout.Button("Add New")) 28 | { 29 | tile.sprites.Add(tile.sprites[tile.sprites.Count-1]); 30 | } 31 | GUI.color = Color.white; 32 | GUILayout.EndHorizontal(); 33 | GUILayout.Space(10); 34 | float width = EditorGUIUtility.labelWidth / 3; 35 | for (int i = 0; i < tile.sprites.Count; i++) 36 | { 37 | GUILayout.BeginHorizontal(); 38 | if (!tile.IsValid) 39 | { 40 | GUI.color = new Color(1, 0.5f, 0.5f); 41 | } 42 | if (GUILayout.Button(GUIContent.none, MyStyles.centerWhiteBoldLabel, GUILayout.Width(width), GUILayout.Height(width))) 43 | { 44 | EditorGUIUtility.ShowObjectPicker(tile.sprites[i], false, "", i); 45 | } 46 | Rect r = GUILayoutUtility.GetLastRect(); 47 | 48 | Texture2D texture = tile.IsValid ? tile.sprites[i].ToTexture2D() : new Texture2D(16, 16); 49 | GUI.DrawTexture(r, texture); 50 | GUI.color = Color.white; 51 | 52 | GUIStyle labelStyle = new GUIStyle(MyStyles.centerWhiteBoldLabel); 53 | if (!tile.sprites[i]) 54 | GUI.Label(r, "Tile not valid!\nSprite cannot be left empty", labelStyle); 55 | else if (!tile.IsValid) 56 | GUI.Label(r, "Tile not valid!\nEnable Read/Write in import settings", labelStyle); 57 | 58 | GUILayout.FlexibleSpace(); 59 | GUI.color = new Color(1, 0.5f, 0.5f); 60 | if (GUILayout.Button("Delete")) 61 | { 62 | tile.sprites.RemoveAt(i); 63 | } 64 | GUI.color = Color.white; 65 | GUILayout.EndHorizontal(); 66 | MyGUILayout.Splitter(); 67 | } 68 | 69 | /* 70 | if (!tile.sprite) 71 | EditorGUILayout.HelpBox ("This tile is not valid, main sprite (15) cannot be left empty.", MessageType.Error); 72 | else if (!tile.IsValid) 73 | EditorGUILayout.HelpBox ("This tile is not valid, please check that Read/Write is enabled in the main sprite (15)'s import settings", MessageType.Error); 74 | */ 75 | if (Event.current.commandName == "ObjectSelectorUpdated") 76 | { 77 | int index = EditorGUIUtility.GetObjectPickerControlID(); 78 | tile.sprites[index] = EditorGUIUtility.GetObjectPickerObject() as Sprite; 79 | } 80 | 81 | if (GUI.changed) 82 | { 83 | EditorUtility.SetDirty(this); 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/RandomTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa60338cec5dc1242bc41714b8958bec 3 | timeCreated: 1472853992 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/ScriptFactory.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using System.IO; 3 | 4 | public class ScriptFactory 5 | { 6 | [MenuItem ("Assets/Create/Tilemap/New C# Tool Script")] 7 | private static void CreatScriptableToolScript () 8 | { 9 | string name = "NewScriptableTool"; 10 | string filename = name + ".cs"; 11 | 12 | string path; 13 | try 14 | { 15 | // Private implementation of a filenaming function which puts the file at the selected path. 16 | System.Type assetdatabase = typeof (UnityEditor.AssetDatabase); 17 | path = (string)assetdatabase.GetMethod ("GetUniquePathNameAtSelectedPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke (assetdatabase, new object [] { filename }); 18 | } 19 | catch 20 | { 21 | // Protection against implementation changes. 22 | path = UnityEditor.AssetDatabase.GenerateUniqueAssetPath ("Assets/" + filename); 23 | } 24 | 25 | if (File.Exists (path) == false) 26 | { 27 | using (StreamWriter outfile = new StreamWriter (path)) 28 | { 29 | outfile.WriteLine ("using UnityEngine;"); 30 | outfile.WriteLine (""); 31 | outfile.WriteLine ("namespace toinfiniityandbeyond.Tilemapping"); 32 | outfile.WriteLine ("{"); 33 | outfile.WriteLine (" "); 34 | outfile.WriteLine (" [System.Serializable]"); 35 | outfile.WriteLine (" public class " + name + " : ScriptableTool"); 36 | outfile.WriteLine (" {"); 37 | outfile.WriteLine (" //Public variables automatically get exposed in the tile editor"); 38 | outfile.WriteLine (" "); 39 | outfile.WriteLine (" public "+name+"() : base()"); 40 | outfile.WriteLine (" {"); 41 | outfile.WriteLine (" //You can set any defaults for variables here"); 42 | outfile.WriteLine (" }"); 43 | outfile.WriteLine (" "); 44 | outfile.WriteLine (" /*"); 45 | outfile.WriteLine (" //If you want this ScriptableTool to have a shortcut set it here"); 46 | outfile.WriteLine (" public override KeyCode Shortcut"); 47 | outfile.WriteLine (" {"); 48 | outfile.WriteLine (" get { return KeyCode.None; }"); 49 | outfile.WriteLine (" }"); 50 | outfile.WriteLine (" "); 51 | outfile.WriteLine (" //If you want this ScriptableTool to have a description set it here"); 52 | outfile.WriteLine (" public override string Description"); 53 | outfile.WriteLine (" {"); 54 | outfile.WriteLine (" get { return string.Empty; }"); 55 | outfile.WriteLine (" }"); 56 | outfile.WriteLine (" */"); 57 | outfile.WriteLine (" "); 58 | outfile.WriteLine (" //"); 59 | outfile.WriteLine (" //Called when LMB is held down"); 60 | outfile.WriteLine (" public override void OnClick (Point point, ScriptableTile tile, TileMap map)"); 61 | outfile.WriteLine (" {"); 62 | outfile.WriteLine (" if (tile == null && map == null)"); 63 | outfile.WriteLine (" return;"); 64 | outfile.WriteLine (" "); 65 | outfile.WriteLine (" map.SetTileAt (point, tile);"); 66 | outfile.WriteLine (" }"); 67 | outfile.WriteLine (" /*"); 68 | outfile.WriteLine (" //Called when LMB is clicked down"); 69 | outfile.WriteLine (" public override void OnClickDown (Point point, ScriptableTile tile, TileMap map)"); 70 | outfile.WriteLine (" {"); 71 | outfile.WriteLine (" base.OnClickDown(point, tile, map);"); 72 | outfile.WriteLine (" }"); 73 | outfile.WriteLine (" //Called when LMB is released"); 74 | outfile.WriteLine (" public override void OnClickUp (Point point, ScriptableTile tile, TileMap map)"); 75 | outfile.WriteLine (" {"); 76 | outfile.WriteLine (" base.OnClickUp(point, tile, map);"); 77 | outfile.WriteLine (" }"); 78 | outfile.WriteLine (" //The region to draw a tool preview for"); 79 | outfile.WriteLine (" public override List GetRegion (Point point, ScriptableTile tile, TileMap map)"); 80 | outfile.WriteLine (" {"); 81 | outfile.WriteLine (" base.GetRegion(point, tile, map);"); 82 | outfile.WriteLine (" }"); 83 | outfile.WriteLine (" */"); 84 | outfile.WriteLine (" }"); 85 | outfile.WriteLine ("}"); 86 | 87 | outfile.Close (); 88 | } 89 | } 90 | AssetDatabase.Refresh (); 91 | 92 | Selection.activeObject = AssetDatabase.LoadMainAssetAtPath (path); 93 | EditorGUIUtility.PingObject (Selection.activeObject); 94 | } 95 | 96 | [MenuItem ("Assets/Create/Tilemap/New C# Tile Script")] 97 | private static void CreateTileScript () 98 | { 99 | string name = "NewTileScript"; 100 | string filename = name + ".cs"; 101 | 102 | string path; 103 | try 104 | { 105 | // Private implementation of a filenaming function which puts the file at the selected path. 106 | System.Type assetdatabase = typeof (UnityEditor.AssetDatabase); 107 | path = (string)assetdatabase.GetMethod ("GetUniquePathNameAtSelectedPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke (assetdatabase, new object [] { filename }); 108 | } 109 | catch 110 | { 111 | // Protection against implementation changes. 112 | path = UnityEditor.AssetDatabase.GenerateUniqueAssetPath ("Assets/" + filename); 113 | } 114 | 115 | if (File.Exists (path) == false) 116 | { 117 | using (StreamWriter outfile = new StreamWriter (path)) 118 | { 119 | outfile.WriteLine ("using UnityEngine;"); 120 | outfile.WriteLine (" "); 121 | outfile.WriteLine ("namespace toinfiniityandbeyond.Tilemapping"); 122 | outfile.WriteLine ("{"); 123 | outfile.WriteLine (" //Remember to change these names to something more meaningful!"); 124 | outfile.WriteLine (@" [CreateAssetMenu (fileName = ""New Script Tile"", menuName = ""Tilemap/Tiles/NewTileScript"")]"); 125 | outfile.WriteLine (" public class " + name + " : ScriptableTile"); 126 | outfile.WriteLine (" {"); 127 | outfile.WriteLine (" [SerializeField]"); 128 | outfile.WriteLine (" private Sprite sprite;"); 129 | outfile.WriteLine (" "); 130 | outfile.WriteLine (" //Returns if this tile is okay to be used in the tile map"); 131 | outfile.WriteLine (" //For example: if this tile doesn't have a Read/Write enabled sprite it will return false"); 132 | outfile.WriteLine (" public override bool IsValid"); 133 | outfile.WriteLine (" {"); 134 | outfile.WriteLine (" get"); 135 | outfile.WriteLine (" {"); 136 | outfile.WriteLine (" if(sprite == null)"); 137 | outfile.WriteLine (" return false;"); 138 | outfile.WriteLine (" "); 139 | outfile.WriteLine (" try"); 140 | outfile.WriteLine (" {"); 141 | outfile.WriteLine (" sprite.texture.GetPixel(0, 0);"); 142 | outfile.WriteLine (" }"); 143 | outfile.WriteLine (" catch(UnityException e)"); 144 | outfile.WriteLine (" {"); 145 | outfile.WriteLine (" return false;"); 146 | outfile.WriteLine (" }"); 147 | outfile.WriteLine (" return true;"); 148 | outfile.WriteLine (" }"); 149 | outfile.WriteLine (" }"); 150 | outfile.WriteLine (" "); 151 | outfile.WriteLine (" public override Sprite GetSprite (TileMap tilemap, Point position = default (Point))"); 152 | outfile.WriteLine (" {"); 153 | outfile.WriteLine (" return sprite;"); 154 | outfile.WriteLine (" }"); 155 | outfile.WriteLine (" public override Texture2D GetIcon ()"); 156 | outfile.WriteLine (" {"); 157 | outfile.WriteLine (" if (!IsValid) return null;"); 158 | outfile.WriteLine (" return sprite.ToTexture2D();"); 159 | outfile.WriteLine (" }"); 160 | outfile.WriteLine (" //Called when the inspector has been edited"); 161 | outfile.WriteLine (" private void OnValidate ()"); 162 | outfile.WriteLine (" {"); 163 | outfile.WriteLine (" //Can be used to check if variables are valid"); 164 | outfile.WriteLine (" }"); 165 | outfile.WriteLine (" "); 166 | outfile.WriteLine (" }"); 167 | outfile.WriteLine ("}"); 168 | 169 | outfile.Close (); 170 | } 171 | } 172 | AssetDatabase.Refresh (); 173 | 174 | Selection.activeObject = AssetDatabase.LoadMainAssetAtPath (path); 175 | EditorGUIUtility.PingObject (Selection.activeObject); 176 | } 177 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/ScriptFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76750cc0e23217a4a92aa983f56346f0 3 | timeCreated: 1471375843 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/ScriptableTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEditor.Callbacks; 4 | using UnityEditorInternal; 5 | 6 | using toinfiniityandbeyond.Utillity; 7 | 8 | namespace toinfiniityandbeyond.Tilemapping 9 | { 10 | public class ScriptableTileEditor : Editor 11 | { 12 | protected ScriptableTile scriptableTile; 13 | 14 | public override void OnInspectorGUI () 15 | { 16 | base.OnInspectorGUI (); 17 | } 18 | protected override void OnHeaderGUI () 19 | { 20 | scriptableTile = target as ScriptableTile; 21 | 22 | Rect headerRect = new Rect (0, 0, Screen.width, 50); 23 | GUILayout.BeginArea (headerRect, new GUIStyle("IN ThumbnailShadow")); 24 | Rect contentRect = new Rect (10, 10, Screen.width - 20, 30); 25 | GUI.DrawTexture (new Rect(contentRect.x, contentRect.y, contentRect.height, contentRect.height), scriptableTile.GetIcon (), ScaleMode.ScaleAndCrop); 26 | contentRect.x += contentRect.height + 10; 27 | contentRect.width -= contentRect.x; 28 | GUI.Label (new Rect (contentRect.x, contentRect.y, contentRect.width, contentRect.height / 2), scriptableTile.name, MyStyles.leftBoldLabel); 29 | GUI.Label (new Rect (contentRect.x, contentRect.y + contentRect.height / 2, contentRect.width, contentRect.height / 2), "Tile Type: " + scriptableTile.GetType ().Name, MyStyles.leftMiniLabel); 30 | GUIContent content = new GUIContent (EditorGUIUtility.FindTexture ("_Help"), "Open Reference for " + scriptableTile.GetType ().Name); 31 | if (GUI.Button (new Rect(contentRect.x + contentRect.width - 10, contentRect.y, 20, contentRect.height), content, MyStyles.centerBoldLabel)) { 32 | Application.OpenURL ("https://github.com/toinfiniityandbeyond/Tilemap/wiki/" + scriptableTile.GetType ().Name); 33 | } 34 | 35 | GUILayout.EndArea (); 36 | GUILayout.Space (headerRect.height + 10); 37 | } 38 | /* 39 | [DidReloadScripts] 40 | static ScriptableTileEditor () 41 | { 42 | EditorApplication.projectWindowItemOnGUI = ItemOnGUI; 43 | } 44 | 45 | static void ItemOnGUI (string guid, Rect rect) 46 | { 47 | string assetPath = AssetDatabase.GUIDToAssetPath (guid); 48 | 49 | ScriptableTile obj = AssetDatabase.LoadAssetAtPath (assetPath, typeof (ScriptableTile)) as ScriptableTile; 50 | 51 | if (obj != null) 52 | { 53 | rect.width = rect.height; 54 | GUI.DrawTexture (rect, new Texture2D(16, 16)); 55 | GUI.DrawTexture (rect, obj.GetTexture (null, Point.zero)); 56 | GUI.Label (rect, obj.Name, UI.CustomStyles.centerWhiteBoldLabel); 57 | } 58 | } 59 | */ 60 | } 61 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/ScriptableTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a283ac6b3cbdac48972e2c418a155b6 3 | timeCreated: 1471867019 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/SimpleTileEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using toinfiniityandbeyond.Utillity; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [CustomEditor (typeof (SimpleTile))] 8 | public class TileCustomEditor : ScriptableTileEditor 9 | { 10 | private SimpleTile tile; 11 | 12 | private void OnEnable () 13 | { 14 | tile = (SimpleTile)target; 15 | } 16 | public override void OnInspectorGUI () 17 | { 18 | GUILayout.Space (10); 19 | EditorGUILayout.HelpBox("As simple as it comes, renders the sprite selected", MessageType.Info); 20 | GUILayout.Space (10); 21 | 22 | GUILayout.Label ("Sprite:", MyStyles.leftBoldLabel); 23 | 24 | float width = EditorGUIUtility.labelWidth; 25 | if (!tile.IsValid) 26 | { 27 | GUI.color = new Color (1, 0.5f, 0.5f); 28 | } 29 | if (GUILayout.Button (GUIContent.none, MyStyles.centerWhiteBoldLabel, GUILayout.Width (width), GUILayout.Height (width))) 30 | { 31 | EditorGUIUtility.ShowObjectPicker (tile.sprite, false, "", 0); 32 | } 33 | Rect r = GUILayoutUtility.GetLastRect (); 34 | 35 | Texture2D texture = tile.IsValid ? tile.sprite.ToTexture2D() : new Texture2D (16, 16); 36 | GUI.DrawTexture (r, texture); 37 | GUI.color = Color.white; 38 | 39 | GUIStyle labelStyle = new GUIStyle (MyStyles.centerWhiteBoldLabel); 40 | if (!tile.sprite) 41 | GUI.Label (r, "Tile not valid!\nSprite cannot be left empty", labelStyle); 42 | else if (!tile.IsValid) 43 | GUI.Label (r, "Tile not valid!\nEnable Read/Write in import settings", labelStyle); 44 | 45 | 46 | /* 47 | if (!tile.sprite) 48 | EditorGUILayout.HelpBox ("This tile is not valid, main sprite (15) cannot be left empty.", MessageType.Error); 49 | else if (!tile.IsValid) 50 | EditorGUILayout.HelpBox ("This tile is not valid, please check that Read/Write is enabled in the main sprite (15)'s import settings", MessageType.Error); 51 | */ 52 | if (Event.current.commandName == "ObjectSelectorUpdated") 53 | { 54 | tile.sprite = EditorGUIUtility.GetObjectPickerObject () as Sprite; 55 | } 56 | 57 | if (GUI.changed) 58 | { 59 | EditorUtility.SetDirty (this); 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/SimpleTileEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6dca446d5c7cd2c45adda399b8daa13d 3 | timeCreated: 1471811202 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapContainerEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace toinfiniityandbeyond.Tilemapping 5 | { 6 | [CustomEditor(typeof(TileMapContainer))] 7 | public class TileMapContainerEditor : Editor 8 | { 9 | TileMapContainer container; 10 | 11 | public override void OnInspectorGUI() 12 | { 13 | container = (target as TileMapContainer); 14 | EditorGUILayout.HelpBox("This is just a container of tilemap data", MessageType.Info); 15 | 16 | Utillity.MyGUILayout.Splitter(); 17 | if (GUILayout.Button("Import as New TileMap")) 18 | { 19 | 20 | GameObject go = new GameObject(container.name); 21 | TileMap map = go.AddComponent(); 22 | map.Resize(container.width, container.height); 23 | for (int x = 0; x < container.width; x++) 24 | { 25 | for (int y = 0; y < container.height; y++) 26 | { 27 | map.SetTileAt(x, y, container.map[x + y * container.width]); 28 | } 29 | } 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapContainerEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1dab521b8ad26bc43ba25563bcedf014 3 | timeCreated: 1472832296 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | 7 | // For obtaining list of sorting layers. 8 | using UnityEditorInternal; 9 | using System.Reflection; 10 | 11 | namespace toinfiniityandbeyond.Tilemapping 12 | { 13 | [CustomEditor (typeof (TileMap)), CanEditMultipleObjects] 14 | partial class TileMapEditor : Editor 15 | { 16 | [MenuItem("GameObject/2D Object/TileMap")] 17 | private static void CreateTileMapGameObject() 18 | { 19 | GameObject tileObject = new GameObject ("New TileMap", typeof(TileMap)); 20 | } 21 | 22 | private TileMap tileMap; 23 | 24 | partial void OnInspectorEnable (); 25 | partial void OnInspectorDisable (); 26 | partial void OnSceneEnable (); 27 | partial void OnSceneDisable (); 28 | 29 | private void OnEnable () 30 | { 31 | tileMap = (TileMap)target; 32 | 33 | OnInspectorEnable (); 34 | OnSceneEnable (); 35 | } 36 | 37 | private void OnDisable () 38 | { 39 | OnInspectorDisable (); 40 | OnSceneDisable (); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ad4814b42ea7884499ecd36f1db776c 3 | timeCreated: 1471353336 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapInspectorEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | using System.Reflection; 6 | using toinfiniityandbeyond.Utillity; 7 | 8 | namespace toinfiniityandbeyond.Tilemapping 9 | { 10 | partial class TileMapEditor : Editor 11 | { 12 | SerializedProperty spWidth; 13 | SerializedProperty spHeight; 14 | 15 | partial void OnInspectorEnable() 16 | { 17 | spWidth = serializedObject.FindProperty("width"); 18 | spHeight = serializedObject.FindProperty("height"); 19 | } 20 | 21 | partial void OnInspectorDisable() 22 | { 23 | 24 | } 25 | public override void OnInspectorGUI() 26 | { 27 | serializedObject.Update(); 28 | 29 | EditorGUILayout.Space(); 30 | TileRenderer renderer = tileMap.GetComponent(); 31 | if (renderer == null) 32 | { 33 | Texture2D tex = EditorGUIUtility.FindTexture("console.erroricon"); 34 | if (GUILayout.Button(new GUIContent("No TileRenderer attached! Click here to add one.", tex), EditorStyles.helpBox)) 35 | { 36 | GenericMenu menu = new GenericMenu(); 37 | foreach (Type type in Assembly.GetAssembly(typeof(TileRenderer)).GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(TileRenderer)))) 38 | { 39 | menu.AddItem(new GUIContent(type.Name), false, () => { tileMap.gameObject.AddComponent(type); }); 40 | } 41 | menu.ShowAsContext(); 42 | } 43 | } 44 | EditorGUILayout.Space(); 45 | EditorGUI.BeginChangeCheck(); 46 | tileMap.isInEditMode = GUILayout.Toggle(tileMap.isInEditMode, "", "Button", GUILayout.Height(EditorGUIUtility.singleLineHeight * 1.5f)); 47 | string toggleButtonText = (tileMap.isInEditMode ? "Exit" : "Enter") + " Edit Mode [TAB]"; 48 | GUI.Label(GUILayoutUtility.GetLastRect(), toggleButtonText, MyStyles.centerBoldLabel); 49 | 50 | if (EditorGUI.EndChangeCheck()) 51 | { 52 | if (tileMap.isInEditMode) 53 | OnEnterEditMode(); 54 | else 55 | OnExitEditMode(); 56 | } 57 | EditorGUILayout.Space(); 58 | 59 | GUILayout.Label("Settings", MyStyles.leftBoldLabel); 60 | 61 | int width = spWidth.intValue; 62 | width = EditorGUILayout.IntField(spWidth.displayName, width); 63 | int height = spHeight.intValue; 64 | height = EditorGUILayout.IntField(spHeight.displayName, height); 65 | 66 | if (width != spWidth.intValue || height != spHeight.intValue) 67 | { 68 | tileMap.Resize(width, height); 69 | OnSceneGUI(); 70 | } 71 | EditorGUILayout.Space(); 72 | 73 | GUILayout.Label("Tools", MyStyles.leftBoldLabel); 74 | GUILayout.BeginHorizontal(); 75 | if (GUILayout.Button("Force Refresh")) 76 | { 77 | tileMap.UpdateTileMap(); 78 | } 79 | GUI.color = new Color(1f, 0.5f, 0.5f); 80 | if (GUILayout.Button("Clear All Tiles")) 81 | { 82 | if (EditorUtility.DisplayDialog("Are you sure?", "Do you really want to clear this tilemap without saving?", "Okay", "Cancel")) 83 | { 84 | tileMap.Reset(); 85 | SetTileMapDirty(); 86 | } 87 | } 88 | GUI.color = Color.white; 89 | GUILayout.EndHorizontal(); 90 | GUILayout.BeginHorizontal(); 91 | if (GUILayout.Button("Import")) 92 | { 93 | string path = EditorUtility.OpenFilePanelWithFilters("Select .tilemap File", "Assets", new string[] { "ScriptableObject", "asset" }); 94 | if(path != string.Empty) { 95 | int cutoffFrom = path.IndexOf("Assets"); 96 | path = path.Substring(cutoffFrom); 97 | Debug.Log(path); 98 | TileMapContainer container = AssetDatabase.LoadAssetAtPath(path) as TileMapContainer; 99 | if (EditorUtility.DisplayDialog("Are you sure?", "Importing this tilemap will override the current one without saving it.", "Okay", "Cancel")) 100 | { 101 | tileMap.Resize(container.width, container.height); 102 | for(int x = 0; x < container.width; x++) 103 | { 104 | for(int y = 0; y < container.height; y++) 105 | { 106 | tileMap.SetTileAt(x, y, container.map[x + y * container.width]); 107 | } 108 | } 109 | } 110 | } 111 | } 112 | if (GUILayout.Button("Export")) 113 | { 114 | TileMapContainer container = ScriptableObjectUtility.CreateAsset(tileMap.name + ".asset"); 115 | container.map = tileMap.Map; 116 | container.width = tileMap.Width; 117 | container.height = tileMap.Height; 118 | } 119 | GUILayout.EndHorizontal(); 120 | if (Event.current.type == EventType.KeyDown && Event.current.isKey && Event.current.keyCode == KeyCode.Tab) 121 | { 122 | tileMap.isInEditMode = !tileMap.isInEditMode; 123 | } 124 | if (Event.current.type == EventType.KeyDown && Event.current.isKey && Event.current.keyCode == KeyCode.Escape) 125 | { 126 | tileMap.isInEditMode = false; 127 | } 128 | 129 | serializedObject.ApplyModifiedProperties(); 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapInspectorEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fe585b8240185b4a8b95af877dc0459 3 | timeCreated: 1471353336 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapSceneEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEditor.SceneManagement; 4 | 5 | using System; 6 | using System.Linq; 7 | using System.Reflection; 8 | using System.Collections.Generic; 9 | 10 | using toinfiniityandbeyond.Utillity; 11 | 12 | namespace toinfiniityandbeyond.Tilemapping 13 | { 14 | partial class TileMapEditor : Editor 15 | { 16 | Vector3 position; 17 | 18 | bool hasUndone; 19 | 20 | partial void OnSceneEnable () 21 | { 22 | RefreshScriptableToolCache (); 23 | RefreshScriptableTileCache (); 24 | EditorApplication.update += Update; 25 | } 26 | partial void OnSceneDisable () 27 | { 28 | EditorApplication.update -= Update; 29 | } 30 | private void Update () { 31 | if (tileMap.isInEditMode) { 32 | Selection.activeObject = tileMap; 33 | SceneView currentView = SceneView.lastActiveSceneView; 34 | if(currentView) 35 | currentView.in2DMode = true; 36 | 37 | Tools.current = Tool.None; 38 | SceneModeUtility.SearchForType (typeof(TileMap)); 39 | } 40 | } 41 | private void OnEnterEditMode() { 42 | // SceneView currentView = SceneView.lastActiveSceneView; 43 | // currentView.pivot = tileMap.tileMapPosition + new Vector3 (tileMap.Width / 2, tileMap.Height / 2, -10); 44 | // currentView.size = tileMap.Height + 2; 45 | 46 | Tools.hidden = true; 47 | Tools.current = Tool.None; 48 | OnSceneGUI (); 49 | } 50 | private void OnExitEditMode() { 51 | SceneModeUtility.SearchForType (null); 52 | if(!Application.isPlaying) 53 | EditorSceneManager.SaveOpenScenes(); 54 | Tools.hidden = false; 55 | Tools.current = Tool.Move; 56 | } 57 | 58 | private void OnSceneGUI () 59 | { 60 | if (tileMap.isInEditMode) 61 | { 62 | tileMap.toolbarWindowPosition = ClampToScreen (GUILayout.Window (GUIUtility.GetControlID (FocusType.Passive), tileMap.toolbarWindowPosition, ToolbarWindow, new GUIContent ("Toolbar"), GUILayout.Width (80))); 63 | 64 | if (tileMap.primaryTilePickerToggle) 65 | { 66 | if (tileMap.secondaryTilePickerToggle) 67 | tileMap.primaryTilePickerToggle = false; 68 | 69 | tileMap.tilePickerWindowPosition = ClampToScreen (GUILayout.Window (GUIUtility.GetControlID (FocusType.Passive), tileMap.tilePickerWindowPosition, (int id) => { TilepickerWindow (id, ref tileMap.primaryTile); }, new GUIContent ("Pick primary tile..."), GUILayout.Width (100))); 70 | } 71 | else if (tileMap.secondaryTilePickerToggle) 72 | { 73 | if (tileMap.primaryTilePickerToggle) 74 | tileMap.secondaryTilePickerToggle = false; 75 | 76 | tileMap.tilePickerWindowPosition = ClampToScreen (GUILayout.Window (GUIUtility.GetControlID (FocusType.Passive), tileMap.tilePickerWindowPosition, (int id) => { TilepickerWindow (id, ref tileMap.secondaryTile); }, new GUIContent ("Pick secondary tile..."), GUILayout.Width (100))); 77 | } 78 | if (!tileMap.secondaryTilePickerToggle && !tileMap.primaryTilePickerToggle) 79 | { 80 | Vector2 cursorPos = GUIUtility.ScreenToGUIPoint (Event.current.mousePosition); 81 | tileMap.tilePickerWindowPosition = new Rect (cursorPos + new Vector2 (20, 0), Vector2.zero); 82 | } 83 | 84 | DrawGrid (); 85 | 86 | HandleShortcutEvents (); 87 | HandleMouseEvents (); 88 | 89 | tileMap.transform.position = tileMap.tileMapPosition; 90 | tileMap.transform.rotation = tileMap.tileMapRotation; 91 | tileMap.transform.localScale = Vector3.one; 92 | 93 | HandleUtility.AddDefaultControl (GUIUtility.GetControlID (FocusType.Passive)); 94 | SceneView.RepaintAll (); 95 | } else 96 | { 97 | tileMap.tileMapPosition = tileMap.transform.position; 98 | tileMap.tileMapRotation = tileMap.transform.rotation; 99 | } 100 | DrawOutline (); 101 | } 102 | 103 | private void ToolbarWindow (int id) 104 | { 105 | string text = "None"; 106 | Rect secondaryTileRect = new Rect (tileMap.toolbarWindowPosition.width - 5 - tileMap.toolbarWindowPosition.width * 0.4f, 25 + tileMap.toolbarWindowPosition.width * 0.4f, tileMap.toolbarWindowPosition.width * 0.4f, tileMap.toolbarWindowPosition.width * 0.4f); 107 | tileMap.secondaryTilePickerToggle = GUI.Toggle (secondaryTileRect, tileMap.secondaryTilePickerToggle, GUIContent.none, "Label"); 108 | 109 | GUI.DrawTexture (secondaryTileRect, new Texture2D(16, 16)); 110 | GUI.contentColor = Color.black; 111 | if (tileMap.secondaryTile) 112 | { 113 | GUI.DrawTexture (secondaryTileRect, tileMap.secondaryTile.GetIcon ()); 114 | GUI.contentColor = Color.white; 115 | text = tileMap.secondaryTile.Name; 116 | } 117 | GUI.Label (secondaryTileRect, text, MyStyles.centerWhiteMiniLabel); 118 | 119 | Rect primaryTileRect = new Rect (5, 25, tileMap.toolbarWindowPosition.width * 0.6f, tileMap.toolbarWindowPosition.width * 0.6f); 120 | tileMap.primaryTilePickerToggle = GUI.Toggle (primaryTileRect, tileMap.primaryTilePickerToggle, GUIContent.none, "Label"); 121 | 122 | text = "None"; 123 | 124 | GUI.DrawTexture (primaryTileRect, new Texture2D(16, 16)); 125 | GUI.contentColor = Color.black; 126 | if (tileMap.primaryTile) 127 | { 128 | GUI.DrawTexture (primaryTileRect, tileMap.primaryTile.GetIcon ()); 129 | GUI.contentColor = Color.white; 130 | text = tileMap.primaryTile.Name; 131 | } 132 | GUI.Label (primaryTileRect, text, MyStyles.centerWhiteBoldLabel); 133 | GUI.contentColor = Color.white; 134 | 135 | float tileHeight = 10 + primaryTileRect.height + 0.5f * secondaryTileRect.height; 136 | 137 | GUILayout.Space (tileHeight); 138 | 139 | GUILayout.BeginHorizontal (); 140 | if (GUILayout.Button ("Swap [X]")) 141 | { 142 | Swap (ref tileMap.primaryTile, ref tileMap.secondaryTile); 143 | } 144 | GUI.color = new Color (1, 0.5f, 0.5f); 145 | if (GUILayout.Button ("Clear")) 146 | { 147 | tileMap.primaryTile = null; 148 | tileMap.secondaryTile = null; 149 | } 150 | 151 | GUI.color = Color.white; 152 | GUILayout.EndHorizontal (); 153 | 154 | MyGUILayout.Splitter(); 155 | 156 | GUILayout.BeginHorizontal (); 157 | 158 | GUI.enabled = tileMap.CanUndo; 159 | if (GUILayout.Button ("Undo [Z]")) 160 | { 161 | tileMap.Undo (); 162 | SetTileMapDirty(); 163 | } 164 | GUI.enabled = tileMap.CanRedo; 165 | if (GUILayout.Button ("Redo [R]")) 166 | { 167 | tileMap.Redo (); 168 | SetTileMapDirty(); 169 | } 170 | GUI.enabled = true; 171 | 172 | GUILayout.EndHorizontal (); 173 | MyGUILayout.Splitter(); 174 | 175 | 176 | GUILayout.Label ("Tools", MyStyles.leftBoldLabel); 177 | EditorGUILayout.HelpBox ("[RMB] to toggle tool", MessageType.Info, true); 178 | 179 | for (int i = 0; i < tileMap.scriptableToolCache.Count; i++) 180 | { 181 | bool selected = (i == tileMap.selectedScriptableTool); 182 | EditorGUI.BeginChangeCheck (); 183 | string labelName = tileMap.scriptableToolCache [i].Shortcut != KeyCode.None ? 184 | string.Format("{1} [{0}]", tileMap.scriptableToolCache [i].Shortcut.ToString(), tileMap.scriptableToolCache [i].Name) : 185 | tileMap.scriptableToolCache [i].Name; 186 | 187 | GUIContent content = new GUIContent (labelName, tileMap.scriptableToolCache [i].Description); 188 | GUILayout.Toggle (selected, content, EditorStyles.radioButton, GUILayout.Width (100)); 189 | if (EditorGUI.EndChangeCheck()) 190 | { 191 | tileMap.lastSelectedScriptableTool = tileMap.selectedScriptableTool; 192 | 193 | tileMap.selectedScriptableTool = i; 194 | 195 | if (selected) 196 | tileMap.selectedScriptableTool = -1; 197 | } 198 | } 199 | if (tileMap.selectedScriptableTool == -1) 200 | { 201 | EditorGUILayout.HelpBox ("No Tool selected, select one from above.", MessageType.Warning, true); 202 | } 203 | if(tileMap.selectedScriptableTool >= 0 && tileMap.selectedScriptableTool < tileMap.scriptableToolCache.Count) 204 | { 205 | const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; 206 | FieldInfo [] fields = tileMap.scriptableToolCache [tileMap.selectedScriptableTool].GetType ().GetFields (flags); 207 | 208 | if (fields.Length > 0) 209 | { 210 | GUILayout.Label ("Settings", MyStyles.leftBoldLabel, GUILayout.Width (100)); 211 | for (int i = 0; i < fields.Length; i++) 212 | { 213 | FieldInfo field = fields [i]; 214 | Type type = field.FieldType; 215 | string fieldName = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase (field.Name); 216 | 217 | GUILayout.BeginHorizontal (GUILayout.Width (100)); 218 | GUILayout.Label (fieldName, EditorStyles.miniLabel); 219 | if (type == typeof (bool)) 220 | { 221 | bool v = (bool)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 222 | bool nv = EditorGUILayout.Toggle (v); 223 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 224 | } 225 | else if (type == typeof (float)) 226 | { 227 | float v = (float)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 228 | float nv = EditorGUILayout.FloatField (v); 229 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 230 | } 231 | else if (type == typeof (int)) 232 | { 233 | int v = (int)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 234 | int nv = EditorGUILayout.IntField (v); 235 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 236 | } 237 | else if (type == typeof (Enum)) 238 | { 239 | int v = (int)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 240 | int nv = EditorGUILayout.IntField (v); 241 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 242 | } 243 | else if (type == typeof (Vector2)) 244 | { 245 | Vector2 v = (Vector2)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 246 | Vector2 nv = Vector2.zero; 247 | nv.x = EditorGUILayout.FloatField (v.x); 248 | nv.y = EditorGUILayout.FloatField (v.y); 249 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 250 | } 251 | else if (type == typeof (Vector3)) 252 | { 253 | Vector3 v = (Vector3)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 254 | Vector3 nv = Vector3.zero; 255 | nv.x = EditorGUILayout.FloatField (v.x); 256 | nv.y = EditorGUILayout.FloatField (v.y); 257 | nv.z = EditorGUILayout.FloatField (v.z); 258 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 259 | } 260 | else if (type == typeof (Color)) 261 | { 262 | Color v = (Color)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 263 | Color nv = EditorGUILayout.ColorField (v); 264 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 265 | } 266 | else if (type == typeof (AnimationCurve)) 267 | { 268 | AnimationCurve v = (AnimationCurve)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 269 | AnimationCurve nv = EditorGUILayout.CurveField (v); 270 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 271 | } 272 | else if (type == typeof (GameObject)) 273 | { 274 | GameObject v = (GameObject)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 275 | GameObject nv = EditorGUILayout.ObjectField (v, typeof(GameObject), false) as GameObject; 276 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 277 | } 278 | else if (type == typeof (Texture2D)) 279 | { 280 | Texture2D v = (Texture2D)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 281 | Texture2D nv = EditorGUILayout.ObjectField (v, typeof (Texture2D), false) as Texture2D; 282 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 283 | } 284 | else if (type == typeof (Sprite)) 285 | { 286 | Sprite v = (Sprite)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 287 | Sprite nv = EditorGUILayout.ObjectField (v, typeof (Sprite), false) as Sprite; 288 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 289 | } 290 | else if (type == typeof (UnityEngine.Object)) 291 | { 292 | UnityEngine.Object v = (UnityEngine.Object)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 293 | UnityEngine.Object nv = EditorGUILayout.ObjectField (v, typeof (UnityEngine.Object), false) as UnityEngine.Object; 294 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 295 | } 296 | else if (type.IsEnum) 297 | { 298 | int v = (int)field.GetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool]); 299 | int nv = EditorGUILayout.Popup (v, Enum.GetNames (type)); 300 | field.SetValue (tileMap.scriptableToolCache [tileMap.selectedScriptableTool], nv); 301 | } 302 | else 303 | { 304 | Debug.LogErrorFormat ("Exposing public variable type '{0}' is currently not supported by Tooles \n Feel free to add support for it though!", type.Name); 305 | } 306 | GUILayout.EndHorizontal (); 307 | 308 | } 309 | } 310 | else 311 | { 312 | EditorGUILayout.HelpBox ("Tool has no public variables to edit.", MessageType.Info, true); 313 | } 314 | } 315 | 316 | 317 | GUI.DragWindow (); 318 | } 319 | private void TilepickerWindow (int id, ref ScriptableTile tileToChange) 320 | { 321 | GUI.BringWindowToFront (id); 322 | 323 | if (tileMap.scriptableTileCache.Count > 0) 324 | { 325 | int columns = 4; 326 | int rows = Mathf.CeilToInt (1 + (tileMap.scriptableTileCache.Count) / columns); 327 | float tileWidth = (tileMap.tilePickerWindowPosition.width - 50) / columns; 328 | 329 | tileMap.tilePickerScrollView = GUILayout.BeginScrollView (tileMap.tilePickerScrollView, false, true, GUILayout.Height(tileWidth * 4)); 330 | 331 | GUILayout.BeginVertical (); 332 | for (int y = 0; y < rows; y++) 333 | { 334 | GUILayout.BeginHorizontal (); 335 | for (int x = 0; x < columns; x++) 336 | { 337 | int index = x + y * columns - 1; 338 | 339 | 340 | if (index < 0) 341 | { 342 | if (GUILayout.Button (GUIContent.none, "Label", GUILayout.Height (tileWidth), GUILayout.Width (tileWidth))) 343 | { 344 | tileToChange = null; 345 | tileMap.primaryTilePickerToggle = tileMap.secondaryTilePickerToggle = false; 346 | } 347 | GUI.DrawTexture (GUILayoutUtility.GetLastRect (), new Texture2D(16, 16)); 348 | GUI.Label (GUILayoutUtility.GetLastRect(), "None", MyStyles.centerBoldLabel); 349 | } 350 | 351 | if (index >= tileMap.scriptableTileCache.Count ||index < 0) 352 | continue; 353 | 354 | GUI.color = tileMap.scriptableTileCache [index].IsValid ? Color.white : new Color(1, 0.5f, 0.5f); 355 | 356 | if (GUILayout.Button (GUIContent.none, "Label", GUILayout.Height (tileWidth), GUILayout.Width (tileWidth))) 357 | { 358 | if (tileMap.scriptableTileCache [index].IsValid) 359 | { 360 | tileToChange = tileMap.scriptableTileCache [index]; 361 | tileMap.primaryTilePickerToggle = tileMap.secondaryTilePickerToggle = false; 362 | } 363 | else 364 | { 365 | Type pt = Assembly.GetAssembly (typeof (Editor)).GetType ("UnityEditor.ProjectBrowser"); 366 | EditorWindow.GetWindow (pt).Show (); 367 | EditorGUIUtility.PingObject (tileMap.scriptableTileCache [index]); 368 | } 369 | } 370 | 371 | 372 | Rect buttonRect = GUILayoutUtility.GetLastRect (); 373 | string tileText = "..."; 374 | GUI.DrawTexture (buttonRect, new Texture2D(16, 16)); 375 | if (tileMap.scriptableTileCache [index].IsValid) 376 | { 377 | GUI.DrawTexture (buttonRect, tileMap.scriptableTileCache [index].GetIcon ()); 378 | tileText = tileMap.scriptableTileCache [index].Name; 379 | } 380 | GUI.color = Color.white; 381 | 382 | GUI.Label (buttonRect, tileText, MyStyles.centerWhiteBoldLabel); 383 | } 384 | GUILayout.EndHorizontal (); 385 | } 386 | GUILayout.EndVertical (); 387 | GUILayout.EndScrollView (); 388 | } 389 | else 390 | { 391 | EditorGUILayout.HelpBox ("No Tiles found. Try force refresh or \nIn the project window, 'Create > Tilemap > Tiles > ...' to create one", MessageType.Warning); 392 | } 393 | GUILayout.BeginHorizontal (); 394 | if(GUILayout.Button("Force Refresh")) 395 | { 396 | RefreshScriptableTileCache (); 397 | } 398 | GUI.color = new Color (1f, 0.5f, 0.5f); 399 | if (GUILayout.Button ("Close Tile Picker")) 400 | { 401 | tileMap.primaryTilePickerToggle = tileMap.secondaryTilePickerToggle = false; 402 | } 403 | GUI.color = Color.white; 404 | 405 | GUILayout.EndHorizontal (); 406 | 407 | GUI.DragWindow (); 408 | } 409 | private void Swap(ref T a, ref T b) 410 | { 411 | T t = a; 412 | a = b; 413 | b = t; 414 | } 415 | 416 | private void RefreshScriptableToolCache() 417 | { 418 | List toRemove = new List (); 419 | for (int i = 0; i < tileMap.scriptableToolCache.Count; i++) { 420 | if (tileMap.scriptableToolCache [i] == null) 421 | toRemove.Add (tileMap.scriptableToolCache [i]); 422 | } 423 | tileMap.scriptableToolCache = tileMap.scriptableToolCache.Except (toRemove).ToList (); 424 | foreach (Type type in Assembly.GetAssembly (typeof (ScriptableTool)).GetTypes () 425 | .Where (myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf (typeof (ScriptableTool)))) 426 | { 427 | bool containsType = false; 428 | for (int i = 0; i < tileMap.scriptableToolCache.Count; i++) 429 | { 430 | if (tileMap.scriptableToolCache [i].GetType () == type) 431 | { 432 | containsType = true; 433 | break; 434 | } 435 | } 436 | if(!containsType) 437 | tileMap.scriptableToolCache.Add ((ScriptableTool)Activator.CreateInstance (type)); 438 | } 439 | } 440 | private void RefreshScriptableTileCache () 441 | { 442 | List toRemove = new List (); 443 | for (int i = 0; i < tileMap.scriptableTileCache.Count; i++) { 444 | if (tileMap.scriptableTileCache [i] == null) 445 | toRemove.Add (tileMap.scriptableTileCache [i]); 446 | } 447 | AssetDatabase.Refresh (); 448 | tileMap.scriptableTileCache = tileMap.scriptableTileCache.Except (toRemove).ToList (); 449 | string [] guids = AssetDatabase.FindAssets (string.Format ("t:{0}", typeof (ScriptableTile))); 450 | for (int i = 0; i < guids.Length; i++) 451 | { 452 | string assetPath = AssetDatabase.GUIDToAssetPath (guids [i]); 453 | ScriptableTile asset = AssetDatabase.LoadAssetAtPath (assetPath); 454 | if (asset != null && !tileMap.scriptableTileCache.Contains(asset)) 455 | { 456 | tileMap.scriptableTileCache.Add (asset); 457 | } 458 | } 459 | } 460 | 461 | private void DrawGrid () 462 | { 463 | float width = tileMap.Width; 464 | float height = tileMap.Height; 465 | 466 | Vector3 position = tileMap.tileMapPosition; 467 | 468 | Handles.color = Color.gray; 469 | for (float i = 1; i < width; i++) 470 | { 471 | Handles.DrawLine (new Vector3 (i + position.x, position.y), new Vector3 (i + position.x, height + position.y)); 472 | } 473 | for (float i = 1; i < height; i++) 474 | { 475 | Handles.DrawLine (new Vector3 (position.x, i + position.y), new Vector3 (width + position.x, i + position.y)); 476 | } 477 | } 478 | private void DrawOutline() 479 | { 480 | float width = tileMap.Width; 481 | float height = tileMap.Height; 482 | 483 | Vector3 position = tileMap.tileMapPosition; 484 | 485 | Handles.color = Color.white; 486 | Handles.DrawLine (position, new Vector3 (width + position.x, position.y)); 487 | Handles.DrawLine (position, new Vector3 (position.x, height + position.y)); 488 | Handles.DrawLine (new Vector3 (width + position.x, position.y), new Vector3 (width + position.x, height + position.y)); 489 | Handles.DrawLine (new Vector3 (position.x, height + position.y), new Vector3 (width + position.x, height + position.y)); 490 | } 491 | private void HandleShortcutEvents() 492 | { 493 | if (Event.current.type == EventType.KeyDown && Event.current.isKey && Event.current.keyCode == KeyCode.Z) 494 | { 495 | tileMap.Undo (); 496 | SetTileMapDirty(); 497 | } 498 | 499 | if (Event.current.type == EventType.KeyDown && Event.current.isKey && Event.current.keyCode == KeyCode.R) 500 | { 501 | tileMap.Redo (); 502 | SetTileMapDirty(); 503 | } 504 | 505 | if (Event.current.type == EventType.KeyDown && Event.current.isKey && Event.current.keyCode == KeyCode.X) 506 | { 507 | Swap (ref tileMap.primaryTile, ref tileMap.secondaryTile); 508 | } 509 | 510 | for (int i = 0; i < tileMap.scriptableToolCache.Count; i++) 511 | { 512 | if (Event.current.isKey && Event.current.keyCode == tileMap.scriptableToolCache [i].Shortcut) 513 | { 514 | Event.current.Use (); 515 | tileMap.lastSelectedScriptableTool = tileMap.selectedScriptableTool; 516 | tileMap.selectedScriptableTool = i; 517 | } 518 | } 519 | } 520 | private void HandleMouseEvents () 521 | { 522 | Event e = Event.current; 523 | Point point = new Point (0, 0); 524 | 525 | if (tileMap.selectedScriptableTool >= 0 && tileMap.selectedScriptableTool < tileMap.scriptableToolCache.Count) 526 | { 527 | if (e.button == 0) 528 | { 529 | bool isInBounds = GetMousePosition (ref point); 530 | 531 | if (e.type == EventType.MouseDrag) 532 | { 533 | tileMap.scriptableToolCache [tileMap.selectedScriptableTool].OnClick (point, tileMap.primaryTile, tileMap); 534 | } 535 | if (e.type == EventType.MouseDown) 536 | { 537 | tileMap.scriptableToolCache [tileMap.selectedScriptableTool].OnClickDown (point, tileMap.primaryTile, tileMap); 538 | } 539 | if(e.type == EventType.MouseUp) 540 | { 541 | tileMap.scriptableToolCache [tileMap.selectedScriptableTool].OnClickUp (point, tileMap.primaryTile, tileMap); 542 | 543 | SetTileMapDirty(); 544 | } 545 | List region = tileMap.scriptableToolCache [tileMap.selectedScriptableTool].GetRegion (point, tileMap.primaryTile, tileMap); 546 | GUIStyle style = new GUIStyle(MyStyles.centerWhiteBoldLabel); 547 | style.normal.textColor = Handles.color; 548 | Point cursorPoint = point + new Point(tileMap.transform.position); 549 | Handles.Label((Vector2)cursorPoint, point.ToString(), style); 550 | 551 | for(int i = 0; i < region.Count; i++) 552 | { 553 | point = region[i]; 554 | cursorPoint = point + new Point(tileMap.transform.position); 555 | Handles.color = tileMap.IsInBounds(point) ? new Color (0.5f, 1, 0.5f) : new Color (1, 0.5f, 0.5f); 556 | Handles.color = new Color (Handles.color.r, Handles.color.g, Handles.color.b, 0.3f); 557 | Handles.CubeCap (0, (Vector2)cursorPoint + Vector2.one * 0.5f, Quaternion.identity, 1f); 558 | } 559 | } 560 | } 561 | if ((e.type == EventType.MouseDown) && e.button == 1) 562 | { 563 | Swap (ref tileMap.selectedScriptableTool, ref tileMap.lastSelectedScriptableTool); 564 | } 565 | 566 | } 567 | private bool GetMousePosition (ref Point point) 568 | { 569 | if (SceneView.currentDrawingSceneView == null) 570 | return false; 571 | 572 | Plane plane = new Plane (tileMap.transform.TransformDirection (Vector3.forward), tileMap.tileMapPosition); 573 | Ray ray = HandleUtility.GUIPointToWorldRay (Event.current.mousePosition); 574 | Vector3 position = tileMap.tileMapPosition; 575 | 576 | float distance; 577 | if (plane.Raycast (ray, out distance)) 578 | point = (Point)(ray.origin + (ray.direction.normalized * distance) - position); 579 | 580 | bool result = (point.x >= 0 && point.x < tileMap.Width && point.y >= 0 && point.y < tileMap.Height); 581 | 582 | return result; 583 | } 584 | 585 | private Rect ClampToScreen (Rect r) 586 | { 587 | r.x = Mathf.Clamp (r.x, 5, Screen.width - r.width - 5); 588 | r.y = Mathf.Clamp (r.y, 25, Screen.height - r.height - 25); 589 | return r; 590 | } 591 | private void SetTileMapDirty() 592 | { 593 | if (!Application.isPlaying) 594 | { 595 | EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); 596 | EditorUtility.SetDirty(tileMap); 597 | } 598 | } 599 | } 600 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMapSceneEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b87a2b2b2c14c5c4484ba7c8308db6e3 3 | timeCreated: 1471353336 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMultipleQuadsRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [CustomEditor(typeof(TileMultipleQuadsRenderer))] 8 | public class TileMultipleQuadsRendererEditor : TileRendererEditor 9 | { 10 | TileMultipleQuadsRenderer renderer; 11 | 12 | public override void OnEnable() { 13 | base.OnEnable(); 14 | 15 | renderer = (target as TileMultipleQuadsRenderer); 16 | EditorUtility.SetSelectedWireframeHidden(renderer.meshRenderer, true); 17 | } 18 | public override void OnInspectorGUI() { 19 | base.OnInspectorGUI(); 20 | Utillity.MyGUILayout.Splitter(); 21 | GUILayout.Space(5); 22 | GUILayout.BeginHorizontal(); 23 | if(GUILayout.Button("Force Refresh Atlas")) { 24 | renderer.RefreshAtlas(); 25 | } 26 | GUILayout.Toggle(true, "Auto update atlas"); 27 | GUILayout.EndHorizontal(); 28 | EditorGUILayout.Space(); 29 | GUILayout.BeginHorizontal(); 30 | GUILayout.Label("Texture atlas: "); 31 | GUILayout.Label(renderer.Atlas); 32 | GUILayout.EndHorizontal(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileMultipleQuadsRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45d74644614049b41860afd744b45197 3 | timeCreated: 1472480008 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileRendererEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System; 4 | using System.Linq; 5 | 6 | namespace toinfiniityandbeyond.Tilemapping 7 | { 8 | [CustomEditor(typeof(TileRenderer))] 9 | public class TileRendererEditor : Editor 10 | { 11 | SerializedProperty spColor; 12 | SerializedProperty spMaterial; 13 | SerializedProperty spSortingLayer; 14 | SerializedProperty spOrderInLayer; 15 | 16 | public virtual void OnEnable() { 17 | spColor = serializedObject.FindProperty("color"); 18 | spMaterial = serializedObject.FindProperty("material"); 19 | spSortingLayer = serializedObject.FindProperty("sortingLayer"); 20 | spOrderInLayer = serializedObject.FindProperty("orderInLayer"); 21 | } 22 | 23 | public virtual void OnDisable() { 24 | 25 | } 26 | 27 | public override void OnInspectorGUI() { 28 | serializedObject.Update(); 29 | 30 | EditorGUILayout.Space(); 31 | 32 | EditorGUILayout.PropertyField(spColor); 33 | EditorGUILayout.PropertyField(spMaterial); 34 | 35 | var sortingLayerNames = SortingLayer.layers.Select(l => l.name).ToArray(); 36 | 37 | if (sortingLayerNames != null) { 38 | 39 | // Look up the layer name using the current layer ID 40 | string oldName = SortingLayer.IDToName(spSortingLayer.intValue); 41 | 42 | // Use the name to look up our array index into the names list 43 | int oldLayerIndex = Array.IndexOf(sortingLayerNames, oldName); 44 | 45 | // Show the popup for the names 46 | int newLayerIndex = EditorGUILayout.Popup(spSortingLayer.displayName, oldLayerIndex, sortingLayerNames); 47 | 48 | // If the index changes, look up the ID for the new index to store as the new ID 49 | if (newLayerIndex != oldLayerIndex) { 50 | spSortingLayer.intValue = SortingLayer.NameToID(sortingLayerNames[newLayerIndex]); 51 | } 52 | } 53 | else { 54 | int newValue = EditorGUILayout.IntField(spSortingLayer.displayName ,spSortingLayer.intValue); 55 | if (newValue != spSortingLayer.intValue) { 56 | spSortingLayer.intValue = newValue; 57 | } 58 | EditorGUI.EndProperty(); 59 | } 60 | 61 | EditorGUILayout.PropertyField(spOrderInLayer); 62 | 63 | serializedObject.ApplyModifiedProperties(); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileRendererEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45831a873f24d2a4eae5ec2654e18c27 3 | timeCreated: 1472479713 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileSpriteRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [CustomEditor(typeof(TileSpriteRenderer))] 8 | public class TileSpriteRendererEditor : TileRendererEditor 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Editor/TileSpriteRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21ee7ad559f1e274bb3f10ad9730daea 3 | timeCreated: 1472480008 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e51c64e2790850b419cfa37e6c95f2b6 3 | folderAsset: yes 4 | timeCreated: 1471343297 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06dd6b763924c7e4496d3d65196b76e3 3 | timeCreated: 1471348687 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Script Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Script Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tile Script Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c663e1c459ca64d47aa00995e3b621fd 3 | timeCreated: 1471543182 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMap Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/TileMap Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMap Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34fc8c5e21fecad47ba024e19eae0753 3 | timeCreated: 1471343118 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapContainer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapContainer.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapContainer.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5bde9b4257cc9c04a893a34e7a83cfce 3 | timeCreated: 1472832745 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapRenderer Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapRenderer Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/TileMapRenderer Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4fced3c2df4326646a1dd9444857649a 3 | timeCreated: 1471343118 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff5c9c7875ecafa4f8e2270073f9ef96 3 | timeCreated: 1471383669 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Script Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Script Icon.png -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Icons/Tool Script Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 582814557296ab547abdc4ca1dc8a9d5 3 | timeCreated: 1471542632 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 0 11 | linearTexture: 1 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -3 30 | maxTextureSize: 32 31 | textureSettings: 32 | filterMode: 0 33 | aniso: 1 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 0 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 1 49 | spriteTessellationDetail: -1 50 | textureType: 2 51 | buildTargetSettings: [] 52 | spriteSheet: 53 | serializedVersion: 2 54 | sprites: [] 55 | outline: [] 56 | spritePackingTag: 57 | userData: 58 | assetBundleName: 59 | assetBundleVariant: 60 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbce9dc1311c9c94cb2153799ccbb2d6 3 | folderAsset: yes 4 | timeCreated: 1471540559 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17f33ec9d622beb40a09d603a3e4dff4 3 | folderAsset: yes 4 | timeCreated: 1472479627 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileMultipleQuadsRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [AddComponentMenu("2D/Renderer/TileMultipleQuadsRenderer")] 8 | public class TileMultipleQuadsRenderer : TileRenderer 9 | { 10 | public enum TextureAtlasMode { Normal, Dynamic, SameFile } 11 | [SerializeField] 12 | List spriteList = new List(); 13 | [SerializeField] 14 | Rect[] rects = new Rect[0]; 15 | [SerializeField] 16 | private Texture2D atlas; 17 | [SerializeField] 18 | private MeshFilter meshFilter; 19 | public MeshRenderer meshRenderer; 20 | 21 | public Texture2D Atlas { 22 | get { return atlas; } 23 | } 24 | 25 | public override void OnEnable() { 26 | base.OnEnable(); 27 | } 28 | private void SetUpMesh() 29 | { 30 | if (meshRenderer == null || meshFilter == null) 31 | { 32 | ClearChildren(); 33 | meshFilter = new GameObject("_MESH").AddComponent(); 34 | meshFilter.transform.SetParent(parent); 35 | meshFilter.transform.localPosition = Vector2.zero; 36 | meshFilter.transform.localScale = Vector2.one; 37 | 38 | meshRenderer = meshFilter.gameObject.AddComponent(); 39 | meshRenderer.transform.SetParent(parent); 40 | meshRenderer.transform.localPosition = Vector2.zero; 41 | meshRenderer.transform.localScale = Vector2.one; 42 | } 43 | } 44 | public void RefreshAtlas() { 45 | spriteList = new List(); 46 | tileMap.UpdateTileMap(); 47 | } 48 | private bool AddSpriteToAtlas(Sprite sprite) 49 | { 50 | if (spriteList.Contains(sprite)) 51 | return false; 52 | 53 | spriteList.Add(sprite); 54 | atlas = new Texture2D(16, 16, TextureFormat.RGBA32, false); 55 | rects = atlas.PackTextures(spriteList.Select(x => x.ToTexture2D()).ToArray(), 0); 56 | atlas.filterMode = FilterMode.Point; 57 | atlas.wrapMode = TextureWrapMode.Clamp; 58 | atlas.Apply(); 59 | return true; 60 | } 61 | 62 | public override void Resize(int width, int height) 63 | { 64 | var quads = width * height; // one quad per tile 65 | 66 | var vertices = new Vector3[quads * 4]; 67 | var triangles = new int[quads * 6]; 68 | var normals = new Vector3[vertices.Length]; 69 | var uv = new Vector2[vertices.Length]; 70 | 71 | for (int y = 0; y < height; y++) 72 | { 73 | for (int x = 0; x < width; x++) 74 | { 75 | var i = (y * width) + x; // quad index 76 | 77 | var qi = i * 4; // vertex index 78 | var ti = i * 6; 79 | 80 | // vertices going clockwise 81 | // 2 -- 3 82 | // | / | 83 | // 0 -- 1 84 | vertices[qi] = new Vector3(x, y, 0); 85 | vertices[qi + 1] = new Vector3(x + 1, y, 0); 86 | vertices[qi + 2] = new Vector3(x, y + 1, 0); 87 | vertices[qi + 3] = new Vector3(x + 1, y + 1, 0); 88 | 89 | triangles[ti] = qi; 90 | triangles[ti + 1] = qi + 2; 91 | triangles[ti + 2] = qi + 3; 92 | 93 | triangles[ti + 3] = qi; 94 | triangles[ti + 4] = qi + 3; 95 | triangles[ti + 5] = qi + 1; 96 | } 97 | } 98 | for (int i = 0; i < vertices.Length; i++) 99 | { 100 | normals[i] = Vector3.forward; 101 | uv[i] = Vector2.zero; // uv are set by assigning a tile 102 | } 103 | 104 | var mesh = new Mesh 105 | { 106 | vertices = vertices, 107 | triangles = triangles, 108 | normals = normals, 109 | uv = uv, 110 | name = "mesh" 111 | }; 112 | SetUpMesh(); 113 | meshFilter.sharedMesh = mesh; 114 | UpdateTileMap(); 115 | } 116 | 117 | public override void UpdateTileMap() 118 | { 119 | base.UpdateTileMap(); 120 | 121 | meshRenderer.sharedMaterial = material; 122 | meshRenderer.sharedMaterial.SetTexture("_MainTex", atlas); 123 | meshRenderer.sharedMaterial.color = color; 124 | meshRenderer.sortingLayerID = sortingLayer; 125 | meshRenderer.sortingOrder = orderInLayer; 126 | } 127 | public override void UpdateTileAt(int x, int y) 128 | { 129 | //var currentTexture = textureAtlas; 130 | ScriptableTile tile = tileMap.GetTileAt(x, y); 131 | 132 | int quadIndex = x + y * tileMap.Width; 133 | 134 | quadIndex *= 4; 135 | var uv = meshFilter.sharedMesh.uv; 136 | if (tile == null) 137 | { 138 | uv[quadIndex] = uv[quadIndex + 1] = uv[quadIndex + 2] = uv[quadIndex + 3] = Vector2.zero; 139 | 140 | meshFilter.sharedMesh.uv = uv; 141 | return; 142 | } 143 | 144 | Vector2[] prevUVs = new Vector2[] { 145 | uv[quadIndex], 146 | uv[quadIndex + 1], 147 | uv[quadIndex + 2], 148 | uv[quadIndex + 3] 149 | }; 150 | 151 | Sprite sprite = tile.GetSprite(tileMap, new Point(x, y)); 152 | bool atlasUpdated = AddSpriteToAtlas(sprite); 153 | 154 | // assign four uv coordinates to change the texture of one tile (one quad, two triangels) 155 | Rect spriteRect = rects[spriteList.IndexOf(sprite)]; 156 | Vector2[] newUVs = new Vector2[] { 157 | new Vector2(spriteRect.xMin, spriteRect.yMin), 158 | new Vector2(spriteRect.xMax, spriteRect.yMin), 159 | new Vector2(spriteRect.xMin, spriteRect.yMax), 160 | new Vector2(spriteRect.xMax, spriteRect.yMax) 161 | }; 162 | 163 | if(!newUVs.SequenceEqual(prevUVs)) 164 | { 165 | uv[quadIndex] = newUVs[0]; 166 | uv[quadIndex + 1] = newUVs[1]; 167 | uv[quadIndex + 2] = newUVs[2]; 168 | uv[quadIndex + 3] = newUVs[3]; 169 | meshFilter.sharedMesh.uv = uv; 170 | 171 | if(atlasUpdated) 172 | //FIXME so that it only updates tiles who have changed uvs 173 | tileMap.UpdateType(tile); 174 | } 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileMultipleQuadsRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a37f09db2c1191469cc687b761f2b6b 3 | timeCreated: 1472571101 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: 4fced3c2df4326646a1dd9444857649a, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | [ExecuteInEditMode, DisallowMultipleComponent, RequireComponent(typeof(TileMap)), HelpURL("https://github.com/toinfiniityandbeyond/Tilemap/wiki/TileRenderer-Component")] 6 | public abstract class TileRenderer : MonoBehaviour 7 | { 8 | public Color color; 9 | public Material material; 10 | 11 | public int sortingLayer; 12 | public int orderInLayer; 13 | 14 | [SerializeField] 15 | protected TileMap tileMap; 16 | [SerializeField] 17 | protected Transform parent; 18 | 19 | public virtual void Reset () 20 | { 21 | if(!tileMap) 22 | tileMap = GetComponent (); 23 | 24 | color = Color.white; 25 | material = new Material (Shader.Find ("Sprites/Default")); 26 | 27 | parent = transform.FindChild("_TILERENDERER"); 28 | if(parent == null) { 29 | parent = new GameObject("_TILERENDERER").GetComponent(); 30 | parent.SetParent(transform); 31 | parent.localPosition = Vector2.zero; 32 | parent.localScale = Vector2.one; 33 | parent.gameObject.hideFlags = HideFlags.HideInHierarchy; 34 | } 35 | 36 | Resize (tileMap.Width, tileMap.Height); 37 | UpdateTileMap (); 38 | } 39 | public virtual void OnEnable () 40 | { 41 | if(!tileMap) 42 | tileMap = GetComponent (); 43 | 44 | tileMap.OnUpdateTileAt += UpdateTileAt; 45 | tileMap.OnUpdateTileMap += UpdateTileMap; 46 | tileMap.OnResize += Resize; 47 | } 48 | public virtual void OnDisable () 49 | { 50 | tileMap.OnUpdateTileAt -= UpdateTileAt; 51 | tileMap.OnUpdateTileMap -= UpdateTileMap; 52 | tileMap.OnResize -= Resize; 53 | } 54 | public virtual void OnValidate() 55 | { 56 | UpdateTileMap(); 57 | } 58 | public void ClearChildren() { 59 | if(parent.childCount > 0) { 60 | if (!Application.isPlaying) 61 | { 62 | while (parent.childCount > 0) 63 | { 64 | Object.DestroyImmediate(parent.GetChild(0).gameObject); 65 | } 66 | } 67 | else 68 | { 69 | foreach (Transform child in parent) 70 | { 71 | Object.Destroy(child.gameObject); 72 | } 73 | } 74 | } 75 | } 76 | public void OnDestroy() 77 | { 78 | ClearChildren(); 79 | } 80 | public abstract void Resize(int width, int height); 81 | 82 | public virtual void UpdateTileMap() { 83 | for (int x = 0; x < tileMap.Width; x++) 84 | { 85 | for (int y = 0; y < tileMap.Height; y++) 86 | { 87 | UpdateTileAt(x, y); 88 | } 89 | } 90 | } 91 | 92 | public abstract void UpdateTileAt(int x, int y); 93 | } 94 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c2b4ab8cee32bc498039d7bae73a0ba 3 | timeCreated: 1471543562 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: 8 | - material: {instanceID: 0} 9 | - tileMap: {instanceID: 0} 10 | executionOrder: 0 11 | icon: {fileID: 2800000, guid: 4fced3c2df4326646a1dd9444857649a, type: 3} 12 | userData: 13 | assetBundleName: 14 | assetBundleVariant: 15 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileSpriteRenderer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | [AddComponentMenu("2D/Renderer/TileSpriteRenderer")] 6 | public class TileSpriteRenderer : TileRenderer 7 | { 8 | [SerializeField] 9 | private SpriteRenderer[] spriteMap = new SpriteRenderer[0]; 10 | 11 | public override void Resize(int width, int height) 12 | { 13 | if(width * height == spriteMap.Length) 14 | return; 15 | 16 | ClearChildren(); 17 | 18 | spriteMap = new SpriteRenderer[width * height]; 19 | } 20 | 21 | public override void UpdateTileAt(int x, int y) 22 | { 23 | int index = x + y * tileMap.Width; 24 | SpriteRenderer current = spriteMap[index]; 25 | if (current == null) 26 | { 27 | current = new GameObject(string.Format("[{0}, {1}]", x, y)).AddComponent(); 28 | current.transform.SetParent(parent); 29 | 30 | spriteMap[index] = current; 31 | } 32 | ScriptableTile tile = tileMap.GetTileAt(x, y); 33 | current.sprite = tile ? tile.GetSprite(tileMap, new Point(x, y)) : null; 34 | 35 | current.transform.localPosition = new Vector2(x, y) + (tile ? 36 | new Vector2(current.sprite.pivot.x / current.sprite.rect.width, 37 | current.sprite.pivot.y / current.sprite.rect.height) : Vector2.zero); 38 | 39 | current.transform.localScale = Vector2.one; 40 | current.sharedMaterial = material; 41 | current.color = color; 42 | current.sortingLayerID = sortingLayer; 43 | current.sortingOrder = orderInLayer; 44 | 45 | current.gameObject.SetActive(tile != null); 46 | 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Renderers/TileSpriteRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9b20a181af3610488992b6e11e29f7f 3 | timeCreated: 1472571093 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: 8 | - material: {instanceID: 0} 9 | - tileMap: {instanceID: 0} 10 | executionOrder: 0 11 | icon: {fileID: 2800000, guid: 4fced3c2df4326646a1dd9444857649a, type: 3} 12 | userData: 13 | assetBundleName: 14 | assetBundleVariant: 15 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/TileMap.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [ExecuteInEditMode, AddComponentMenu("2D/TileMap"), DisallowMultipleComponent, HelpURL("https://github.com/toinfiniityandbeyond/Tilemap/wiki/TileMap-Component")] 8 | public class TileMap : MonoBehaviour 9 | { 10 | [SerializeField] 11 | private int width = 25, height = 25; 12 | [SerializeField] 13 | private ScriptableTile[] map = new ScriptableTile[0]; 14 | 15 | private bool CurrentOperation = false; 16 | private List CurrentEdit; 17 | private Timeline timeline; 18 | 19 | public Action OnUpdateTileAt = (x, y) => { }; 20 | public Action OnUpdateTileMap = () => { }; 21 | public Action OnResize = (width, height) => { }; 22 | 23 | public ScriptableTile[] Map { get { return map; } } 24 | public int Width { get { return width; } } 25 | public int Height { get { return height; } } 26 | 27 | private void Update() 28 | { 29 | for (int x = 0; x < Width; x++) 30 | { 31 | for (int y = 0; y < Height; y++) 32 | { 33 | ScriptableTile tile = GetTileAt(x, y); 34 | if (tile && tile.CheckIfCanTick()) 35 | UpdateTileAt(x, y); 36 | } 37 | } 38 | } 39 | 40 | private Point WorldPositionToPoint(Vector2 worldPosition, bool clamp = false) 41 | { 42 | Point offset = (Point)transform.position; 43 | Point point = (Point)worldPosition; 44 | 45 | int x = point.x - offset.x; 46 | int y = point.y - offset.y; 47 | 48 | if (clamp) 49 | { 50 | x = Mathf.Clamp(x, 0, width - 1); 51 | y = Mathf.Clamp(y, 0, height - 1); 52 | } 53 | return new Point(x, y); 54 | } 55 | 56 | public void Reset() 57 | { 58 | map = new ScriptableTile[width * height]; 59 | timeline = new Timeline(); 60 | CurrentEdit = new List(); 61 | 62 | UpdateTileMap(); 63 | } 64 | 65 | public void Resize(int newWidth, int newHeight) 66 | { 67 | if ((newWidth <= 0 || newHeight <= 0) || (width == newWidth && height == newHeight)) 68 | return; 69 | 70 | int oldWidth = width, oldHeight = height; 71 | ScriptableTile[] oldMap = map; 72 | 73 | map = new ScriptableTile[newWidth * newHeight]; 74 | width = newWidth; 75 | height = newHeight; 76 | OnResize.Invoke(newWidth, newHeight); 77 | 78 | for (int i = 0; i < oldMap.Length; i++) 79 | { 80 | int x = i % oldWidth; 81 | int y = i / oldWidth; 82 | ScriptableTile tile = oldMap[i]; 83 | if (tile && IsInBounds(x, y)) 84 | SetTileAt(x, y, tile); 85 | } 86 | } 87 | public bool IsInBounds(Point point) 88 | { 89 | return IsInBounds(point.x, point.y); 90 | } 91 | public bool IsInBounds(int x, int y) 92 | { 93 | return (x >= 0 && x < width && y >= 0 && y < height); 94 | } 95 | 96 | public ScriptableTile GetTileAt(Vector2 worldPosition) 97 | { 98 | return GetTileAt(WorldPositionToPoint(worldPosition)); 99 | } 100 | public ScriptableTile GetTileAt(Point point) 101 | { 102 | return GetTileAt(point.x, point.y); 103 | } 104 | public ScriptableTile GetTileAt(int x, int y) 105 | { 106 | if (!IsInBounds(x, y)) 107 | return null; 108 | 109 | int index = x + y * width; 110 | 111 | return map[x + y * width]; 112 | } 113 | 114 | public bool SetTileAt(Vector2 worldPosition, ScriptableTile to) 115 | { 116 | return SetTileAt(WorldPositionToPoint(worldPosition), to); 117 | } 118 | public bool SetTileAt(Point point, ScriptableTile to) 119 | { 120 | return SetTileAt(point.x, point.y, to); 121 | } 122 | public bool SetTileAt(int x, int y, ScriptableTile to) 123 | { 124 | ScriptableTile from = GetTileAt(x, y); 125 | //Conditions for returning 126 | if (IsInBounds(x, y) && 127 | !(from == null && to == null) && 128 | (((from == null || to == null) && (from != null || to != null)) || 129 | from.ID != to.ID)) 130 | { 131 | map[x + y * width] = to; 132 | 133 | if (CurrentEdit == null) 134 | CurrentEdit = new List(); 135 | CurrentEdit.Add(new ChangeElement(x, y, from, to)); 136 | 137 | UpdateTileAt(x, y); 138 | UpdateNeighbours(x, y, true); 139 | 140 | return true; 141 | } 142 | return false; 143 | } 144 | public void UpdateTileAt(Point point) 145 | { 146 | UpdateTileAt(point.x, point.y); 147 | } 148 | public void UpdateTileAt(int x, int y) 149 | { 150 | OnUpdateTileAt.Invoke(x, y); 151 | } 152 | public void UpdateTilesAt(Point[] points) 153 | { 154 | for (int i = 0; i < points.Length; i++) 155 | { 156 | UpdateTileAt(points[i]); 157 | } 158 | } 159 | public void UpdateNeighbours(int x, int y, bool incudeCorners = false) 160 | { 161 | for (int xx = -1; xx <= 1; xx++) 162 | { 163 | for (int yy = -1; yy <= 1; yy++) 164 | { 165 | if (xx == 0 && yy == 0) 166 | continue; 167 | 168 | if (!incudeCorners && !(xx == 0 || yy == 0)) 169 | continue; 170 | 171 | if (IsInBounds(x + xx, y + yy)) 172 | UpdateTileAt(x + xx, y + yy); 173 | } 174 | } 175 | } 176 | public void UpdateType(ScriptableTile type) 177 | { 178 | for (int x = 0; x <= Width; x++) 179 | { 180 | for (int y = 0; y <= Height; y++) 181 | { 182 | if(GetTileAt(x, y) == type) { 183 | UpdateTileAt(x, y); 184 | } 185 | } 186 | } 187 | } 188 | public List GetAllTileTypes() 189 | { 190 | List result = new List(); 191 | for (int x = 0; x <= Width; x++) 192 | { 193 | for (int y = 0; y <= Height; y++) 194 | { 195 | ScriptableTile tile = GetTileAt(x, y); 196 | if(!result.Contains(tile) && tile != null) 197 | { 198 | result.Add(tile); 199 | } 200 | } 201 | } 202 | return result; 203 | } 204 | public void UpdateTileMap() 205 | { 206 | OnUpdateTileMap.Invoke(); 207 | } 208 | 209 | public bool CanUndo 210 | { 211 | get { return (timeline != null && timeline.CanUndo); } 212 | } 213 | public bool CanRedo 214 | { 215 | get { return (timeline != null && timeline.CanRedo); } 216 | } 217 | 218 | public void Undo() 219 | { 220 | if (timeline == null) 221 | return; 222 | List changesToRevert = timeline.Undo(); 223 | 224 | foreach (var c in changesToRevert) 225 | { 226 | map[c.x + c.y * width] = c.from; 227 | UpdateTileAt(c.x, c.y); 228 | UpdateNeighbours(c.x, c.y, true); 229 | } 230 | } 231 | 232 | public void Redo() 233 | { 234 | if (timeline == null) 235 | return; 236 | List changesToRevert = timeline.Redo(); 237 | 238 | foreach (var c in changesToRevert) 239 | { 240 | map[c.x + c.y * width] = c.to; 241 | UpdateTileAt(c.x, c.y); 242 | UpdateNeighbours(c.x, c.y, true); 243 | } 244 | } 245 | 246 | public void BeginOperation() 247 | { 248 | CurrentOperation = true; 249 | CurrentEdit = new List(); 250 | } 251 | 252 | public void FinishOperation() 253 | { 254 | CurrentOperation = false; 255 | if (timeline == null) 256 | timeline = new Timeline(); 257 | timeline.PushChanges(CurrentEdit); 258 | } 259 | 260 | public bool OperationInProgress() 261 | { 262 | return CurrentOperation; 263 | } 264 | 265 | //A cheat-y way of serialising editor variables in the Unity Editor 266 | #if UNITY_EDITOR 267 | public bool isInEditMode = false; 268 | 269 | public ScriptableTile primaryTile, secondaryTile; 270 | 271 | public Rect toolbarWindowPosition, tilePickerWindowPosition; 272 | public Vector2 tilePickerScrollView; 273 | 274 | public int selectedScriptableTool = -1, lastSelectedScriptableTool = -1; 275 | 276 | public bool primaryTilePickerToggle = false, secondaryTilePickerToggle = false; 277 | 278 | public List scriptableToolCache = new List(); 279 | public List scriptableTileCache = new List(); 280 | 281 | public Vector3 tileMapPosition; 282 | public Quaternion tileMapRotation; 283 | #endif 284 | } 285 | } 286 | 287 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/TileMap.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 695945d64fb3e0145870df86dcc11990 3 | timeCreated: 1471343190 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: 34fc8c5e21fecad47ba024e19eae0753, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/TileMapContainer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping { 4 | public class TileMapContainer : ScriptableObject { 5 | public int width, height; 6 | public ScriptableTile[] map; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/TileMapContainer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7336105b2f2666418ae1b81ab658244 3 | timeCreated: 1472832814 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: 5bde9b4257cc9c04a893a34e7a83cfce, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13205065c50564944940f5ff3f6bf1b8 3 | folderAsset: yes 4 | timeCreated: 1471538982 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/AnimatedTile.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace toinfiniityandbeyond.Tilemapping 5 | { 6 | //[CreateAssetMenu(fileName = "AnimatedTile", menuName = "Tilemap/Tiles/AnimatedTile")] 7 | public class AnimatedTile : ScriptableTile 8 | { 9 | [System.Serializable] 10 | public struct TileKeyframe { 11 | public float time; 12 | public Sprite sprite; 13 | public TileKeyframe(float k, Sprite v) { 14 | time = k; 15 | sprite = v; 16 | } 17 | } 18 | public float playbackSpeed = 1; 19 | public bool globalAnimation = false; 20 | public List keyframes = new List(); 21 | private int lastIndex = -1; 22 | 23 | public override bool IsValid 24 | { 25 | get 26 | { 27 | // if (dopesheet[0] == null) 28 | // return false; 29 | 30 | // try 31 | // { 32 | // dopesheet[0].Value.texture.GetPixel(0, 0); 33 | // } 34 | // catch (UnityException e) 35 | // { 36 | // return false; 37 | // } 38 | return true; 39 | } 40 | } 41 | public void AddKeyframe(float time, Sprite sprite) { 42 | for(int i = 0; i < keyframes.Count; i++) { 43 | if(keyframes[i].time == time) { 44 | time += 0.1f; 45 | break; 46 | } 47 | } 48 | keyframes.Add(new TileKeyframe(time, sprite)); 49 | } 50 | public override Sprite GetSprite(TileMap tilemap = null, Point position = default(Point)) 51 | { 52 | //Get a unique number for the 2D position 53 | int positionSeed = position.x >= position.y ? position.x * position.x + position.x + position.y : position.x + position.y * position.y; 54 | System.Random prng = new System.Random(positionSeed); 55 | //Set the index = to the current time * animation speed 56 | int index = (int)(Time.time * playbackSpeed); 57 | //If it is a global animation (ie all instances play at the same time) then skip this 58 | //if (!globalAnimation) 59 | // index += prng.Next(0, keyframes.Count); 60 | //Modolo to get the remainder. so 0 <= index < amount of keyframes 61 | index %= keyframes.Count; 62 | if(index != lastIndex) 63 | lastIndex = index; 64 | return keyframes[lastIndex].sprite; 65 | } 66 | public override Texture2D GetIcon() 67 | { 68 | if (!IsValid) return null; 69 | return keyframes[0].sprite.ToTexture2D(); 70 | } 71 | 72 | public override float TickRate { get { return 0.1f; } } 73 | protected override bool Tick() 74 | { 75 | return true; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/AnimatedTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e4dfd246588b654cbfddeb01d160807 3 | timeCreated: 1471891345 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/AutoTile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | //Remember to change these names to something more meaningful! 6 | [CreateAssetMenu (fileName = "AutoTile", menuName = "Tilemap/Tiles/AutoTile")] 7 | public class AutoTile : ScriptableTile 8 | { 9 | public Sprite [] bitmaskSprites = new Sprite[16]; 10 | public enum AutoTileMode { Everything, SameTile, None} 11 | public AutoTileMode mode; 12 | public bool edgesAreFull = false; 13 | 14 | //Returns if this tile is okay to be used in the tile map 15 | //For example: if this tile doesn't have a Read/Write enabled sprite it will return false 16 | public override bool IsValid 17 | { 18 | get 19 | { 20 | if(bitmaskSprites[15] == null) 21 | return false; 22 | 23 | try 24 | { 25 | bitmaskSprites [15].texture.GetPixel(0, 0); 26 | } 27 | catch(UnityException e) 28 | { 29 | return false; 30 | } 31 | return true; 32 | } 33 | } 34 | public bool IsElementValid(int index) 35 | { 36 | if (bitmaskSprites == null || bitmaskSprites [index] == null) 37 | return false; 38 | 39 | try 40 | { 41 | bitmaskSprites [index].texture.GetPixel (0, 0); 42 | } 43 | catch (UnityException e) 44 | { 45 | return false; 46 | } 47 | return true; 48 | } 49 | 50 | 51 | public override Sprite GetSprite (TileMap tilemap = null, Point position = default (Point)) 52 | { 53 | if (tilemap == null) 54 | return bitmaskSprites[15]; 55 | 56 | ScriptableTile[] tiles = new ScriptableTile[] { 57 | tilemap.GetTileAt (position.Up), 58 | tilemap.GetTileAt (position.Left), 59 | tilemap.GetTileAt (position.Down), 60 | tilemap.GetTileAt (position.Right), 61 | }; 62 | int[] bitmasks = new int[] { 63 | 1, 2, 4, 8 64 | }; 65 | Point[] points = new Point[] { 66 | position.Up, 67 | position.Left, 68 | position.Down, 69 | position.Right, 70 | }; 71 | 72 | int index = 0; 73 | for(int i = 0; i < 4; i++) { 74 | bool exists = tiles[i] != null; 75 | bool isSame = exists && tiles[i].ID == this.ID; 76 | bool isEdge = !tilemap.IsInBounds (points[i]); 77 | 78 | if((isEdge && edgesAreFull) || (exists && mode == AutoTileMode.Everything) || (exists && (mode == AutoTileMode.SameTile && isSame))) 79 | index += bitmasks[i]; 80 | } 81 | 82 | if (index < bitmaskSprites.Length && bitmaskSprites [index]) 83 | return bitmaskSprites [index]; 84 | 85 | return bitmaskSprites [15]; 86 | } 87 | public override Texture2D GetIcon () 88 | { 89 | if (!IsValid) return null; 90 | return bitmaskSprites[15].ToTexture2D(); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/AutoTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af7895dc728ea924c98f2dd322558cde 3 | timeCreated: 1471799579 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/RandomTile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | namespace toinfiniityandbeyond.Tilemapping 5 | { 6 | //Remember to change these names to something more meaningful! 7 | [CreateAssetMenu (fileName = "New RandomTile", menuName = "Tilemap/Tiles/RandomTile")] 8 | public class RandomTile : ScriptableTile 9 | { 10 | public int globalSeed = 0; 11 | public List sprites; 12 | 13 | //Returns if this tile is okay to be used in the tile map 14 | //For example: if this tile doesn't have a Read/Write enabled sprite it will return false 15 | public override bool IsValid 16 | { 17 | get 18 | { 19 | if(sprites == null || sprites.Count == 0) 20 | return false; 21 | 22 | try 23 | { 24 | sprites[0].texture.GetPixel(0, 0); 25 | } 26 | catch(UnityException e) 27 | { 28 | return false; 29 | } 30 | return true; 31 | } 32 | } 33 | 34 | public override Sprite GetSprite (TileMap tilemap, Point position = default (Point)) 35 | { 36 | //Get a unique seed based on position 37 | int positionSeed = position.x >= position.y ? position.x * position.x + position.x + position.y : position.x + position.y * position.y; 38 | //Use it alongside the global seed 39 | System.Random prng = new System.Random (globalSeed + positionSeed); 40 | //Get a pseudo random index based on position 41 | int index = prng.Next (0, sprites.Count); 42 | return sprites[index]; 43 | } 44 | public override Texture2D GetIcon () 45 | { 46 | if (!IsValid) return null; 47 | return sprites[0].ToTexture2D(); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/RandomTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 76612b7051d36064189c0d01249cc037 3 | timeCreated: 1471885087 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/ScriptableTile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | public abstract class ScriptableTile : ScriptableObject 6 | { 7 | public string Name { get { return this.name; } } 8 | public int ID { get { return GetInstanceID(); } } 9 | public abstract bool IsValid { get; } 10 | 11 | public abstract Sprite GetSprite (TileMap tilemap = null, Point position = default (Point)); 12 | public abstract Texture2D GetIcon (); 13 | 14 | //Handle Ticking 15 | private float timeOffset = 0; 16 | public virtual float TickRate { get { return 0; } } 17 | 18 | //Yeah, this is a bad name :/ rename asap 19 | public bool CheckIfCanTick () 20 | { 21 | //Clearly can't tick 22 | if(TickRate <= 0) 23 | return false; 24 | //If the time it has left till next tick is more than the TickRate, reset the timeOffset 25 | if(timeOffset - Time.realtimeSinceStartup > TickRate) 26 | timeOffset = 0; 27 | //If the current time is more than the (time + TickRate) 28 | if(Time.realtimeSinceStartup >= timeOffset) 29 | { 30 | //Then call Tick and reset the timeOffset 31 | timeOffset = Time.time + TickRate; 32 | return Tick (); 33 | } 34 | //By default return false 35 | return false; 36 | } 37 | //Override this function to add global behaviour to a tile type 38 | protected virtual bool Tick() 39 | { 40 | //Make it return true if you want it to visually update 41 | return false; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/ScriptableTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b149bb90f68df84b9edc29ec8cd8d9f 3 | timeCreated: 1471543193 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: c663e1c459ca64d47aa00995e3b621fd, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/SimpleTile.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | [CreateAssetMenu (fileName = "New SimpleTile", menuName = "Tilemap/Tiles/SimpleTile")] 6 | public class SimpleTile : ScriptableTile 7 | { 8 | public Sprite sprite; 9 | 10 | public override bool IsValid 11 | { 12 | get 13 | { 14 | if (sprite == null) 15 | return false; 16 | 17 | try 18 | { 19 | sprite.texture.GetPixel(0, 0); 20 | } 21 | catch (UnityException e) 22 | { 23 | return false; 24 | } 25 | return true; 26 | } 27 | } 28 | 29 | public override Sprite GetSprite (TileMap tilemap = null, Point position = default (Point)) 30 | { 31 | return sprite; 32 | } 33 | public override Texture2D GetIcon () 34 | { 35 | if (!IsValid) return null; 36 | return sprite.ToTexture2D(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tiles/SimpleTile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9c4d6717b82da340ac064406e31d42b 3 | timeCreated: 1471867419 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Timeline.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace toinfiniityandbeyond.Tilemapping 4 | { 5 | public class Timeline 6 | { 7 | #region Variables 8 | private List> changes; 9 | private int current = -1; 10 | #endregion 11 | #region Methods 12 | public bool CanUndo 13 | { 14 | get { return !(current == -1); } 15 | } 16 | public bool CanRedo 17 | { 18 | get { return !(current + 1 == changes.Count); } 19 | } 20 | #endregion 21 | #region Constructor 22 | public Timeline() 23 | { 24 | changes = new List>(); 25 | } 26 | #endregion 27 | #region Functions 28 | public List Undo() 29 | { 30 | if (CanUndo) 31 | { 32 | //current--; 33 | return changes[current--]; 34 | } 35 | //At oldest revision, nothing to Undo 36 | //Return empty list 37 | return new List(); 38 | } 39 | 40 | public List Redo() 41 | { 42 | if (CanRedo) 43 | { 44 | //current++; 45 | return changes[++current]; 46 | } 47 | //At newest revision, nothing to redo 48 | //Return empty list 49 | return new List(); 50 | } 51 | 52 | public void PushChanges(List change) 53 | { 54 | //Any tiles changed? 55 | if (change == null || change.Count == 0) 56 | return; 57 | 58 | //Are we at the newest revision? 59 | //If not, all future changes must be erased 60 | if (current - 1 != changes.Count) 61 | changes.RemoveRange(current + 1, changes.Count - current - 1); 62 | 63 | changes.Add(change); 64 | current++; 65 | } 66 | #endregion 67 | } 68 | 69 | public class ChangeElement 70 | { 71 | public int x; 72 | public int y; 73 | 74 | public ScriptableTile from; 75 | public ScriptableTile to; 76 | 77 | public ChangeElement(int _x, int _y, ScriptableTile _from, ScriptableTile _to) 78 | { 79 | x = _x; 80 | y = _y; 81 | from = _from; 82 | to = _to; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Timeline.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e720050925751d54e9c69ea7254df971 3 | timeCreated: 1471965690 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 84cbbd0badf665d46b81ab6951add8ba 3 | folderAsset: yes 4 | timeCreated: 1471476042 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Brush.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [Serializable] 8 | // The Brush tool inherits from the abstract class ScriptableTool. 9 | // This means that it is automatically included in the tilemap editor 10 | public class Brush : ScriptableTool 11 | { 12 | public int radius; 13 | public enum BrushShape { Square, Circle, } 14 | public BrushShape shape; 15 | 16 | // The default constructor where you can set up default variable values 17 | public Brush () : base () 18 | { 19 | radius = 1; 20 | shape = BrushShape.Square; 21 | } 22 | 23 | // Optional override to set a shortcut used in the tile editor 24 | public override KeyCode Shortcut { get { return KeyCode.B; } } 25 | 26 | // Optional override to set a description for the tool 27 | public override string Description { get { return "A simple brush"; } } 28 | 29 | // Called by the tilemap editor to paint tiles 30 | public override void OnClick (Point point, ScriptableTile tile, TileMap map) 31 | { 32 | if (map == null) 33 | return; 34 | 35 | //If we haven't already started an operation, start one now 36 | //This is for undo/ redo support 37 | if (!map.OperationInProgress()) 38 | map.BeginOperation (); 39 | 40 | for(int i = 0; i < region.Count; i ++) { 41 | Point offsetPoint = region[i]; 42 | 43 | map.SetTileAt (offsetPoint, tile); 44 | } 45 | } 46 | 47 | public override void OnClickDown (Point point, ScriptableTile tile, TileMap map) 48 | { 49 | OnClick(point, tile, map); 50 | } 51 | public override List GetRegion (Point point, ScriptableTile tile, TileMap map) 52 | { 53 | region = new List(); 54 | //Arbitrary clamping of brush size 55 | radius = Mathf.Clamp(radius, 1, 64); 56 | int correctedRadius = radius - 1; 57 | for (int x = -correctedRadius; x <= correctedRadius; x++) 58 | { 59 | for (int y = -correctedRadius; y <= correctedRadius; y++) 60 | { 61 | Point offsetPoint = point + new Point (x, y); 62 | if(shape == BrushShape.Square || ((Vector2)(offsetPoint-point)).sqrMagnitude <= correctedRadius * correctedRadius) 63 | region.Add(offsetPoint); 64 | } 65 | } 66 | return region; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Brush.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9d41404294863849a90ca7e395daf8f 3 | timeCreated: 1471475998 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Elipse.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [Serializable] 8 | public class Ellipse : ScriptableTool 9 | { 10 | public bool filled; 11 | private Point start; 12 | private Point end; 13 | 14 | //An empty constructor 15 | public Ellipse() : base() 16 | { 17 | filled = true; 18 | } 19 | //Sets the shortcut key to 'P' 20 | public override KeyCode Shortcut 21 | { 22 | get { return KeyCode.W; } 23 | } 24 | //Sets the tooltip description 25 | public override string Description 26 | { 27 | get { return "Draws a rectangle"; } 28 | } 29 | //Called when the left mouse button is held down 30 | public override void OnClick(Point point, ScriptableTile tile, TileMap map) 31 | { 32 | //Return if the tilemap is null/empty 33 | if (map == null) 34 | return; 35 | 36 | //If we haven't already started an operation, start one now 37 | //This is for undo/ redo support 38 | if (!map.OperationInProgress()) 39 | map.BeginOperation(); 40 | 41 | end = point; 42 | //Set the tile at the specified point to the specified tile 43 | } 44 | //Called when the left mouse button is initially held down 45 | public override void OnClickDown(Point point, ScriptableTile tile, TileMap map) 46 | { 47 | base.OnClickDown(point, tile, map); 48 | start = end = point; 49 | } 50 | public override void OnClickUp(Point point, ScriptableTile tile, TileMap map) 51 | { 52 | base.OnClickUp(point, tile, map); 53 | for (int i = 0; i < region.Count; i++) 54 | { 55 | map.SetTileAt(region[i], tile); 56 | } 57 | start = end = point; 58 | region = new List(); 59 | } 60 | public override List GetRegion(Point point, ScriptableTile tile, TileMap map) 61 | { 62 | region = new List(); 63 | if (end == start) 64 | return base.GetRegion(point, tile, map); 65 | 66 | int x0 = Mathf.Min(start.x, end.x), 67 | x1 = Mathf.Max(start.x, end.x), 68 | y0 = Mathf.Min(start.y, end.y), 69 | y1 = Mathf.Max(start.y, end.y); 70 | 71 | int xc = Mathf.FloorToInt(x0 + (x1 - x0) / 2f); 72 | int yc = Mathf.FloorToInt(y0 + (y1 - y0) / 2f); 73 | int rx = x1 - xc; 74 | int ry = y1 - yc; 75 | 76 | 77 | int rxSq = rx * rx; 78 | int rySq = ry * ry; 79 | int x = 0, y = ry, p; 80 | int px = 0, py = 2 * rxSq * y; 81 | 82 | DrawQuadrants(xc, yc, x, y); 83 | 84 | //Region 1 85 | p = (int)(rySq - (rxSq * ry) + (0.25f * rxSq)); 86 | while (px < py) 87 | { 88 | x++; 89 | px = px + 2 * rySq; 90 | if (p < 0) 91 | p = p + rySq + px; 92 | else 93 | { 94 | y--; 95 | py = py - 2 * rxSq; 96 | p = p + rySq + px - py; 97 | } 98 | DrawQuadrants(xc, yc, x, y); 99 | } 100 | 101 | //Region 2 102 | p = (int)(rySq * (x + 0.5f) * (x + 0.5f) + rxSq * (y - 1) * (y - 1) - rxSq * rySq); 103 | while (y > 0) 104 | { 105 | y--; 106 | py = py - 2 * rxSq; 107 | if (p > 0) 108 | p = p + rxSq - py; 109 | else 110 | { 111 | x++; 112 | px = px + 2 * rySq; 113 | p = p + rxSq - py + px; 114 | } 115 | DrawQuadrants(xc, yc, x, y); 116 | } 117 | 118 | return region; 119 | } 120 | void DrawQuadrants(int xc, int yc, int x, int y) 121 | { 122 | /*This function plots a pixel at coordinates(x,y) specified by first 2 arguments and third argument specifies the color of the pixel*/ 123 | if (filled) 124 | { 125 | for (int xd = xc - x; xd <= xc + x; xd++) 126 | { 127 | for (int yd = yc - y; yd <= yc + y; yd++) 128 | { 129 | Point p = new Point(xd, yd); 130 | if (!region.Contains(p)) 131 | region.Add(p); 132 | } 133 | } 134 | } 135 | else 136 | { 137 | region.Add(new Point(xc + x, yc + y)); 138 | region.Add(new Point(xc - x, yc + y)); 139 | region.Add(new Point(xc + x, yc - y)); 140 | region.Add(new Point(xc - x, yc - y)); 141 | } 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Elipse.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c8d42c0dfe0015541bca034f8a5a9bcb 3 | timeCreated: 1471475988 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Eraser.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System; 5 | 6 | namespace toinfiniityandbeyond.Tilemapping 7 | { 8 | [Serializable] 9 | public class Eraser : Brush 10 | { 11 | public Eraser () : base () 12 | { 13 | radius = 1; 14 | } 15 | public override KeyCode Shortcut { get { return KeyCode.E; } } 16 | public override string Description { get { return "Sets the painted tile to nothing"; } } 17 | 18 | public override void OnClick (Point point, ScriptableTile tile, TileMap map) 19 | { 20 | base.OnClick(point, null, map); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Eraser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7f8b0e56596a1914a9c4687cc63bd77e 3 | timeCreated: 1471476025 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Eyedropper.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | 4 | namespace toinfiniityandbeyond.Tilemapping 5 | { 6 | [Serializable] 7 | public class Eyedropper : ScriptableTool 8 | { 9 | public Eyedropper() : base() 10 | { 11 | 12 | } 13 | public override KeyCode Shortcut { get { return KeyCode.I; } } 14 | public override string Description { get { return "Sets the primary tile to whatever you click"; } } 15 | 16 | public override void OnClickDown(Point point, ScriptableTile tile, TileMap map) 17 | { 18 | } 19 | public override void OnClick(Point point, ScriptableTile tile, TileMap map) 20 | { 21 | 22 | } 23 | public override void OnClickUp(Point point, ScriptableTile tile, TileMap map) 24 | { 25 | map.primaryTile = map.GetTileAt(point); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Eyedropper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e8a25299295bed4ab66ce5a00eaf81e 3 | timeCreated: 1471476158 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Fill.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | 4 | namespace toinfiniityandbeyond.Tilemapping 5 | { 6 | 7 | [System.Serializable] 8 | public class Fill : ScriptableTool 9 | { 10 | //An empty constructor 11 | public Fill () : base() 12 | { 13 | 14 | } 15 | //Sets the shortcut key to 'F' 16 | public override KeyCode Shortcut 17 | { 18 | get { return KeyCode.F; } 19 | } 20 | //Sets the tooltip description 21 | public override string Description 22 | { 23 | get { return "A flood fill tool"; } 24 | } 25 | //Called when the left mouse button is held down 26 | public override void OnClick (Point point, ScriptableTile tile, TileMap map) 27 | { 28 | } 29 | //Called when the left mouse button is initially held down 30 | public override void OnClickDown (Point point, ScriptableTile tile, TileMap map) 31 | { 32 | //Return if the tilemap is null/empty 33 | if (map == null) 34 | return; 35 | 36 | base.OnClickDown(point, tile, map); 37 | 38 | for(int i = 0; i < region.Count; i ++) { 39 | Point offsetPoint = region[i]; 40 | map.SetTileAt (offsetPoint, tile); 41 | } 42 | region = new List(); 43 | 44 | } 45 | public override List GetRegion (Point point, ScriptableTile tile, TileMap map) 46 | { 47 | if(region.Contains(point)) 48 | return region; 49 | 50 | region = new List(); 51 | 52 | //Gets the tile where you clicked 53 | ScriptableTile start = map.GetTileAt(point); 54 | //Return if there tile specified is null 55 | if (tile == null) 56 | return region; 57 | 58 | //The queue of points that need to be changed to the specified tile 59 | Queue open = new Queue (); 60 | //The list of points already changed to the specified tile 61 | List closed = new List (); 62 | //A number larger than the amount of tiles available 63 | int maxLoops = map.Width * map.Height * 10; 64 | 65 | //Add the specified point to the open queue 66 | open.Enqueue (point); 67 | //As long as there are items in the queue, keep this running 68 | while(open.Count > 0) 69 | { 70 | //Decrement the max loops value 71 | maxLoops--; 72 | //If we've executed this code more than the max loops then we've done something wrong :/ 73 | if (maxLoops <= 0) { 74 | Debug.LogError ("Fill tool, max loops reached!"); 75 | return region; 76 | } 77 | 78 | Point p = open.Dequeue (); 79 | if (closed.Contains (p)) 80 | continue; 81 | 82 | closed.Add (p); 83 | ScriptableTile t = map.GetTileAt(p); 84 | 85 | if (!map.IsInBounds (p) || t != start) 86 | continue; 87 | 88 | open.Enqueue (p.Up); 89 | open.Enqueue (p.Right); 90 | open.Enqueue (p.Down); 91 | open.Enqueue (p.Left); 92 | 93 | region.Add(p); 94 | } 95 | return region; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Fill.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 329e9eed9bde8ce46944c26fa0fbc68e 3 | timeCreated: 1471563156 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Line.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [Serializable] 8 | public class Line : ScriptableTool 9 | { 10 | private Point start; 11 | private Point end; 12 | 13 | //An empty constructor 14 | public Line() : base() 15 | { 16 | 17 | } 18 | //Sets the shortcut key to 'P' 19 | public override KeyCode Shortcut 20 | { 21 | get { return KeyCode.L; } 22 | } 23 | //Sets the tooltip description 24 | public override string Description 25 | { 26 | get { return "Draws a line"; } 27 | } 28 | //Called when the left mouse button is held down 29 | public override void OnClick(Point point, ScriptableTile tile, TileMap map) 30 | { 31 | //Return if the tilemap is null/empty 32 | if (map == null) 33 | return; 34 | 35 | //If we haven't already started an operation, start one now 36 | //This is for undo/ redo support 37 | if (!map.OperationInProgress()) 38 | map.BeginOperation(); 39 | 40 | end = point; 41 | //Set the tile at the specified point to the specified tile 42 | } 43 | //Called when the left mouse button is initially held down 44 | public override void OnClickDown(Point point, ScriptableTile tile, TileMap map) 45 | { 46 | base.OnClickDown(point, tile, map); 47 | start = end = point; 48 | } 49 | public override void OnClickUp(Point point, ScriptableTile tile, TileMap map) 50 | { 51 | base.OnClickUp(point, tile, map); 52 | for (int i = 0; i < region.Count; i++) 53 | { 54 | map.SetTileAt(region[i], tile); 55 | } 56 | start = end = point; 57 | region = new List(); 58 | } 59 | public override List GetRegion(Point point, ScriptableTile tile, TileMap map) 60 | { 61 | region = new List(); 62 | if (end == start) 63 | return base.GetRegion(point, tile, map); 64 | 65 | int x0 = start.x, 66 | x1 = end.x, 67 | y0 = start.y, 68 | y1 = end.y; 69 | 70 | int w = x1 - x0; 71 | int h = y1 - y0; 72 | 73 | int dx0 = 0, dy0 = 0, dx1 = 0, dy1 = 0; 74 | 75 | if (w < 0) dx0 = -1; else if (w > 0) dx0 = 1; 76 | if (h < 0) dy0 = -1; else if (h > 0) dy0 = 1; 77 | if (w < 0) dx1 = -1; else if (w > 0) dx1 = 1; 78 | int longest = Mathf.Abs(w); 79 | int shortest = Mathf.Abs(h); 80 | if (!(longest > shortest)) 81 | { 82 | longest = Mathf.Abs(h); 83 | shortest = Math.Abs(w); 84 | if (h < 0) dy1 = -1; else if (h > 0) dy1 = 1; 85 | dx1 = 0; 86 | } 87 | int numerator = longest >> 1; 88 | for (int i = 0; i <= longest; i++) 89 | { 90 | region.Add(new Point(x0, y0)); 91 | numerator += shortest; 92 | if (!(numerator < longest)) 93 | { 94 | numerator -= longest; 95 | x0 += dx0; 96 | y0 += dy0; 97 | } 98 | else 99 | { 100 | x0 += dx1; 101 | y0 += dy1; 102 | } 103 | } 104 | return region; 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Line.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 724fc6a7bee04e347be22cc46fdec9c5 3 | timeCreated: 1471475988 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Pencil.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [Serializable] 8 | public class Pencil : ScriptableTool 9 | { 10 | //An empty constructor 11 | public Pencil () : base () 12 | { 13 | 14 | } 15 | //Sets the shortcut key to 'P' 16 | public override KeyCode Shortcut 17 | { 18 | get { return KeyCode.P; } 19 | } 20 | //Sets the tooltip description 21 | public override string Description 22 | { 23 | get { return "The simplest brush"; } 24 | } 25 | //Called when the left mouse button is held down 26 | public override void OnClick (Point point, ScriptableTile tile, TileMap map) 27 | { 28 | //Return if the tilemap is null/empty 29 | if (map == null) 30 | return; 31 | 32 | //If we haven't already started an operation, start one now 33 | //This is for undo/ redo support 34 | if (!map.OperationInProgress()) 35 | map.BeginOperation (); 36 | 37 | //Set the tile at the specified point to the specified tile 38 | map.SetTileAt (point, tile); 39 | } 40 | //Called when the left mouse button is initially held down 41 | public override void OnClickDown (Point point, ScriptableTile tile, TileMap map) 42 | { 43 | OnClick(point, tile, map); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Pencil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8536242e6e483f24e97cafdeb0ff7ee9 3 | timeCreated: 1471475988 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | [Serializable] 8 | public class Rectangle : ScriptableTool 9 | { 10 | public bool filled; 11 | private Point start; 12 | private Point end; 13 | 14 | //An empty constructor 15 | public Rectangle() : base() 16 | { 17 | filled = true; 18 | } 19 | //Sets the shortcut key to 'P' 20 | public override KeyCode Shortcut 21 | { 22 | get { return KeyCode.W; } 23 | } 24 | //Sets the tooltip description 25 | public override string Description 26 | { 27 | get { return "Draws a rectangle"; } 28 | } 29 | //Called when the left mouse button is held down 30 | public override void OnClick(Point point, ScriptableTile tile, TileMap map) 31 | { 32 | //Return if the tilemap is null/empty 33 | if (map == null) 34 | return; 35 | 36 | //If we haven't already started an operation, start one now 37 | //This is for undo/ redo support 38 | if (!map.OperationInProgress()) 39 | map.BeginOperation(); 40 | 41 | end = point; 42 | //Set the tile at the specified point to the specified tile 43 | } 44 | //Called when the left mouse button is initially held down 45 | public override void OnClickDown(Point point, ScriptableTile tile, TileMap map) 46 | { 47 | base.OnClickDown(point, tile, map); 48 | start = end = point; 49 | } 50 | public override void OnClickUp(Point point, ScriptableTile tile, TileMap map) 51 | { 52 | base.OnClickUp(point, tile, map); 53 | for (int i = 0; i < region.Count; i++) 54 | { 55 | map.SetTileAt(region[i], tile); 56 | } 57 | start = end = point; 58 | region = new List(); 59 | } 60 | public override List GetRegion(Point point, ScriptableTile tile, TileMap map) 61 | { 62 | region = new List(); 63 | if (end == start) 64 | return base.GetRegion(point, tile, map); 65 | 66 | int x0 = Mathf.Min(start.x, end.x), 67 | x1 = Mathf.Max(start.x, end.x), 68 | y0 = Mathf.Min(start.y, end.y), 69 | y1 = Mathf.Max(start.y, end.y); 70 | 71 | for (int x = x0; x <= x1; x++) 72 | { 73 | for (int y = y0; y <= y1; y++) 74 | { 75 | if(filled || (x == x0 || x == x1 || y == y0 || y == y1)) 76 | region.Add(new Point(x, y)); 77 | } 78 | } 79 | 80 | return region; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/Rectangle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45d81f091c9865944bffec642c1210c6 3 | timeCreated: 1471475988 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/ScriptableTool.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace toinfiniityandbeyond.Tilemapping 6 | { 7 | // The base class for a ScriptableTool 8 | [Serializable] 9 | public abstract class ScriptableTool 10 | { 11 | //Public variables will automatically be exposed in the tile editor 12 | //This can be very useful, however it only works with some Types including: 13 | // 14 | // - bool - AnimationCurve 15 | // - float - Color 16 | // - int - Sprite, Texture2D 17 | // - Vector2, Vector3 - GameObject, Object 18 | // - Enum 19 | 20 | protected List region = new List(); 21 | 22 | // The default constructor where you can set up default variable values 23 | public ScriptableTool () 24 | { 25 | 26 | } 27 | 28 | // The name (which is the class name) 29 | public string Name { get { return this.GetType ().Name; } } 30 | // Unique ID of this ScriptableBrush 31 | public int ID { get { return Animator.StringToHash (Name); } } 32 | // The shortcut used in the tile editor 33 | public virtual KeyCode Shortcut { get { return KeyCode.None; } } 34 | // Small summary on what the ScriptableTool does 35 | public virtual string Description { get { return string.Empty; } } 36 | 37 | //Called when LMB is held down 38 | public abstract void OnClick (Point point, ScriptableTile tile, TileMap map); 39 | //Called when LMB is clicked down 40 | public virtual void OnClickDown (Point point, ScriptableTile tile, TileMap map) 41 | { 42 | map.BeginOperation (); 43 | } 44 | //Called when LMB is released 45 | public virtual void OnClickUp (Point point, ScriptableTile tile, TileMap map) 46 | { 47 | map.FinishOperation (); 48 | } 49 | //The region to draw a tool preview for 50 | public virtual List GetRegion (Point point, ScriptableTile tile, TileMap map) 51 | { 52 | region = new List { point }; 53 | return region; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Tilemap/Scripts/Tools/ScriptableTool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 505c77760963fdc4ebd405828cbcf4f5 3 | timeCreated: 1471542664 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {fileID: 2800000, guid: 582814557296ab547abdc4ca1dc8a9d5, type: 3} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ec4e14f826cf504fb25256fd52aa7eb 3 | folderAsset: yes 4 | timeCreated: 1471540740 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5567ddccd611aca49b255f4f5c7660fe 3 | folderAsset: yes 4 | timeCreated: 1472680288 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/EditorStyleViewer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using System.Collections; 5 | 6 | public class EditorStyleViewer : EditorWindow 7 | { 8 | private Vector2 scrollPos; 9 | private int lSize = 0; 10 | private int countSize = 0; 11 | private int initialCount = 0; 12 | private GUIStyle[] eStyles; 13 | private int selSearchParam = 2; 14 | private int selOption = 0; 15 | public GenericMenu optionsMenu = new GenericMenu(); 16 | public StylePref[] stylePrefs; 17 | public int totalSizeofView = 0; 18 | 19 | public class StylePref 20 | { 21 | public int H = 0; 22 | public int W = 0; 23 | public bool npActive = false; 24 | public bool pActive = false; 25 | public bool enabled = true; 26 | public Color bgColor = Color.white; 27 | public Color cColor = Color.white; 28 | public bool displayText = false; 29 | public string text = "ABC"; 30 | } 31 | 32 | public string[] SearchParams = new string[] 33 | { 34 | "StartsWith", 35 | "EndsWith", 36 | "Contains" 37 | }; 38 | 39 | private GUIStyle aStyle = new GUIStyle(); 40 | private int totalSizeOfStyles = 0; 41 | private string lastCopy = ""; 42 | private string searchText = ""; 43 | 44 | 45 | [MenuItem("Window/Editor Style Viewer")] 46 | public static void Init() 47 | { 48 | EditorStyleViewer w = EditorWindow.GetWindow(); 49 | w.title = "Editor Styles"; 50 | w.minSize = new Vector2(335,400); 51 | w.totalSizeOfStyles = 0; 52 | w.stylePrefs = new StylePref[EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).customStyles.Length]; 53 | w.initialCount = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).customStyles.Length; 54 | w.eStyles = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).customStyles; 55 | w.optionsMenu.AddItem(new GUIContent("Copy"), false, w.CopyItem); 56 | w.optionsMenu.AddItem(new GUIContent("Display Sample Text"), false, w.ShowSampleText); 57 | w.optionsMenu.AddItem(new GUIContent("Enable or Disable"), false, w.ToggleDisabled); 58 | w.UpdateListSize(); 59 | Debug.Log("View Size : "+w.totalSizeofView); 60 | 61 | } 62 | 63 | public void ShowSampleText() 64 | { 65 | stylePrefs[selOption].displayText = !stylePrefs[selOption].displayText; 66 | } 67 | 68 | public void CopyItem() 69 | { 70 | GUIStyle s = eStyles[selOption]; 71 | EditorGUIUtility.systemCopyBuffer = '"' + s.name + '"'; 72 | lastCopy = '"' + s.name + '"'; 73 | Repaint(); 74 | } 75 | 76 | public void ToggleDisabled() 77 | { 78 | stylePrefs[selOption].enabled = !stylePrefs[selOption].enabled; 79 | Repaint(); 80 | } 81 | 82 | public void UpdateListSize() 83 | { 84 | int lastY = 0; 85 | int newY = 0; 86 | int count = 0; 87 | for (int i = 0; i < initialCount; i++) 88 | { 89 | GUIStyle s = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).customStyles[i]; 90 | 91 | if (CanShow(s.name)) 92 | { 93 | stylePrefs[i] = new StylePref(); 94 | int height = 16; 95 | int width = 16; 96 | newY = lastY + 5 * count; 97 | if (s.active.background != null) 98 | { 99 | height = s.active.background.height; 100 | width = s.active.background.width; 101 | } 102 | 103 | if (s.hover.background != null) 104 | { 105 | height = s.hover.background.height; 106 | width = s.hover.background.width; 107 | } 108 | 109 | if (s.normal.background != null) 110 | { 111 | height = s.normal.background.height; 112 | width = s.normal.background.width; 113 | } 114 | 115 | if (height < 8 || width < 8) 116 | { 117 | height = 8; 118 | width = 8; 119 | } 120 | 121 | totalSizeOfStyles += height; 122 | stylePrefs[i].H = height; 123 | stylePrefs[i].W = width; 124 | lastY = 125 | newY - 5*count 126 | + 127 | (stylePrefs[i].H + 54); 128 | count++; 129 | } 130 | } 131 | totalSizeofView = lastY + ((count-1) * 5); 132 | lSize = count * totalSizeOfStyles; 133 | countSize = count; 134 | } 135 | 136 | bool CanShow(string s) 137 | { 138 | bool canShow = false; 139 | 140 | switch (selSearchParam) 141 | { 142 | case 0: 143 | if (s.ToLower().StartsWith(searchText.ToLower())) 144 | canShow = true; 145 | break; 146 | 147 | case 1: 148 | if (s.ToLower().EndsWith(searchText.ToLower())) 149 | canShow = true; 150 | break; 151 | 152 | case 2: 153 | if (s.ToLower().Contains(searchText.ToLower())) 154 | canShow = true; 155 | break; 156 | } 157 | 158 | return canShow; 159 | } 160 | 161 | Color InvertColor(Color color) 162 | { 163 | return new Color (1.0f-color.r, 1.0f-color.g, 1.0f-color.b); 164 | } 165 | 166 | void OnGUI() 167 | { 168 | wantsMouseMove = true; 169 | GUI.Box(new Rect(0, 0, position.width, 17), "", "toolbar"); 170 | GUI.Label(new Rect(5, 0, 500, 14), "Count : " + countSize); 171 | searchText = GUI.TextField(new Rect(position.width - 158, 2, 142, 14), searchText, "ToolbarSeachTextField"); 172 | selSearchParam = EditorGUI.Popup(new Rect(position.width - 238, 0, 76, 16), selSearchParam, SearchParams, "ToolbarDropDown"); 173 | if (GUI.Button(new Rect(position.width - 16, 2, 16, 14), "", "ToolbarSeachCancelButton")) 174 | { 175 | searchText = ""; 176 | Repaint(); 177 | } 178 | if (GUI.changed) 179 | { 180 | UpdateListSize(); 181 | } 182 | GUI.Box(new Rect(0, position.height - 17, position.width, 17), "", "OL Title"); 183 | float lastY = 0; 184 | int count = 0; 185 | 186 | scrollPos = GUI.BeginScrollView(new Rect(0, 18, position.width, position.height - 35), scrollPos, new Rect(0, 0, position.width - 16, totalSizeofView+10)); 187 | for (int i = 0; i < initialCount; i++) 188 | { 189 | GUIStyle s = eStyles[i]; 190 | if (CanShow(s.name)) 191 | { 192 | StylePref sP = stylePrefs[i]; 193 | float aHeight = sP.H; 194 | float newY = lastY + 5 * count; 195 | GUI.Box(new Rect(5, newY + 5, position.width - 26, aHeight + 54), "", "helpbox"); 196 | Rect area = new Rect(5, newY + 5, position.width - 26, aHeight + 50); 197 | GUI.BeginGroup(area); 198 | GUI.Box(new Rect(0,0,area.width-1,17), "", "CN Box"); 199 | GUI.Box(new Rect(0, 18, area.width - 1, 17), "", "OL Title"); 200 | 201 | GUI.Label(new Rect(0, 2, area.width - 10, 16), 202 | i + " : " + s.name); 203 | 204 | if (GUI.Button(new Rect(0, 18, 60, 14), "Options", "OL Title")) 205 | { 206 | selOption = i; 207 | optionsMenu.DropDown(new Rect(0, 22, 30, 14)); 208 | } 209 | if (stylePrefs[i].displayText) 210 | { 211 | stylePrefs[i].text = GUI.TextField(new Rect(62, 20, 40, 14), stylePrefs[i].text); 212 | Rect colorGroup = new Rect(new Rect(104, 20, position.width - 125, 14)); 213 | GUI.BeginGroup(colorGroup); 214 | stylePrefs[i].bgColor = EditorGUI.ColorField(new Rect(0, 0, colorGroup.width/2 - 5, 14), 215 | stylePrefs[i].bgColor); 216 | GUI.color = InvertColor(stylePrefs[i].bgColor); 217 | GUI.Label(new Rect(0, 0, 120, 14), "BG Color"); 218 | GUI.color = Color.white; 219 | 220 | stylePrefs[i].cColor = 221 | EditorGUI.ColorField(new Rect(colorGroup.width/2, 0, colorGroup.width/2 - 8, 14), 222 | stylePrefs[i].cColor); 223 | 224 | GUI.color = InvertColor(stylePrefs[i].cColor); 225 | GUI.Label(new Rect(colorGroup.width/2, 0, 120, 14), "Text Color"); 226 | GUI.color = Color.white; 227 | 228 | GUI.EndGroup(); 229 | GUI.enabled = stylePrefs[i].enabled; 230 | GUI.backgroundColor = stylePrefs[i].bgColor; 231 | GUI.contentColor = stylePrefs[i].cColor; 232 | Vector2 size = s.CalcSize(new GUIContent(stylePrefs[i].text)); 233 | stylePrefs[i].npActive = GUI.Toggle(new Rect(10, 41, sP.W/2 + size.x, size.y), stylePrefs[i].npActive, stylePrefs[i].text, s); 234 | 235 | if (EditorGUIUtility.isProSkin) 236 | { 237 | stylePrefs[i].pActive = GUI.Toggle(new Rect(30 + sP.W/2 + size.x, 41, sP.W + size.x, size.y), stylePrefs[i].pActive, 238 | stylePrefs[i].text, s.name); 239 | } 240 | GUI.contentColor = Color.white; 241 | GUI.backgroundColor = Color.white; 242 | } 243 | else 244 | { 245 | GUI.enabled = stylePrefs[i].enabled; 246 | stylePrefs[i].npActive = GUI.Toggle(new Rect(10, 41, sP.W, sP.H), stylePrefs[i].npActive, "", s); 247 | 248 | if (EditorGUIUtility.isProSkin) 249 | { 250 | stylePrefs[i].pActive = GUI.Toggle(new Rect(30 + sP.W, 41, sP.W, sP.H), stylePrefs[i].pActive, 251 | "", s.name); 252 | } 253 | } 254 | GUI.enabled = true; 255 | GUI.EndGroup(); 256 | lastY = 257 | newY - 5 * count 258 | + 259 | (aHeight + 54); 260 | count++; 261 | } 262 | } 263 | GUI.EndScrollView(); 264 | GUI.Label(new Rect(5,position.height-16,position.width,16), "Last style copied : " + lastCopy); 265 | Repaint(); 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/EditorStyleViewer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e7a89ec49b73ce4eb5ba9a912955bbc 3 | timeCreated: 1471941416 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/MyGUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | 4 | namespace toinfiniityandbeyond.Utillity 5 | { 6 | public static class MyGUILayout 7 | { 8 | private static readonly Color splitterColor = EditorGUIUtility.isProSkin ? new Color (0.157f, 0.157f, 0.157f) : new Color (0.5f, 0.5f, 0.5f); 9 | 10 | public static void Splitter (Color rgb, float thickness = 1) 11 | { 12 | Rect position = GUILayoutUtility.GetRect (GUIContent.none, MyStyles.splitter, GUILayout.Height (thickness)); 13 | 14 | if (Event.current.type == EventType.Repaint) 15 | { 16 | Color restoreColor = UnityEngine.GUI.color; 17 | GUI.color = rgb; 18 | MyStyles.splitter.Draw (position, false, false, false, false); 19 | GUI.color = restoreColor; 20 | } 21 | } 22 | 23 | public static void Splitter (float thickness, GUIStyle splitterStyle) 24 | { 25 | Rect position = GUILayoutUtility.GetRect (GUIContent.none, splitterStyle, GUILayout.Height (thickness)); 26 | 27 | if (Event.current.type == EventType.Repaint) 28 | { 29 | Color restoreColor = GUI.color; 30 | GUI.color = splitterColor; 31 | splitterStyle.Draw (position, false, false, false, false); 32 | GUI.color = restoreColor; 33 | } 34 | } 35 | 36 | public static void Splitter (float thickness = 1) 37 | { 38 | Splitter (thickness, MyStyles.splitter); 39 | } 40 | public static void Link (string text, string URL, params GUILayoutOption [] options) 41 | { 42 | GUILayout.Label (text, options); 43 | Rect r = GUILayoutUtility.GetLastRect (); 44 | if (Event.current.type == EventType.MouseUp && r.Contains (Event.current.mousePosition)) 45 | Application.OpenURL (URL); 46 | } 47 | 48 | public static void Link (string text, string URL, GUIStyle style, params GUILayoutOption [] options) 49 | { 50 | GUILayout.Label (text, style, options); 51 | Rect r = GUILayoutUtility.GetLastRect (); 52 | if (Event.current.type == EventType.MouseUp && r.Contains (Event.current.mousePosition)) 53 | Application.OpenURL (URL); 54 | } 55 | public static void Link (GUIContent content, string URL, params GUILayoutOption [] options) 56 | { 57 | GUILayout.Label (content, options); 58 | Rect r = GUILayoutUtility.GetLastRect (); 59 | if (Event.current.type == EventType.MouseUp && r.Contains (Event.current.mousePosition)) 60 | Application.OpenURL (URL); 61 | } 62 | public static void Link(GUIContent content, GUIStyle style,string URL, params GUILayoutOption[] options) 63 | { 64 | GUILayout.Label (content, style, options); 65 | Rect r = GUILayoutUtility.GetLastRect (); 66 | if (Event.current.type == EventType.MouseUp && r.Contains (Event.current.mousePosition)) 67 | Application.OpenURL (URL); 68 | } 69 | } 70 | 71 | public static class MyGUI { 72 | private static readonly Color splitterColor = EditorGUIUtility.isProSkin ? new Color (0.157f, 0.157f, 0.157f) : new Color (0.5f, 0.5f, 0.5f); 73 | // GUI Style 74 | public static void Splitter (Rect position) 75 | { 76 | if (Event.current.type == EventType.Repaint) 77 | { 78 | Color restoreColor = UnityEngine.GUI.color; 79 | UnityEngine.GUI.color = splitterColor; 80 | MyStyles.splitter.Draw (position, false, false, false, false); 81 | UnityEngine.GUI.color = restoreColor; 82 | } 83 | } 84 | 85 | } 86 | 87 | public static class MyStyles 88 | { 89 | public static readonly GUIStyle splitter; 90 | public static readonly GUIStyle wrappedLabel; 91 | public static readonly GUIStyle centerMiniLabel; 92 | public static readonly GUIStyle leftBoldLabel; 93 | public static readonly GUIStyle leftMiniLabel; 94 | public static readonly GUIStyle centerBoldLabel; 95 | public static readonly GUIStyle centerWhiteBoldLabel; 96 | public static readonly GUIStyle centerWhiteMiniLabel; 97 | 98 | static MyStyles () 99 | { 100 | splitter = new GUIStyle (); 101 | splitter.normal.background = EditorGUIUtility.whiteTexture; 102 | splitter.stretchWidth = true; 103 | splitter.margin = new RectOffset (0, 0, 7, 7); 104 | 105 | centerWhiteBoldLabel = new GUIStyle (EditorStyles.whiteBoldLabel); 106 | centerWhiteBoldLabel.alignment = TextAnchor.MiddleCenter; 107 | centerWhiteBoldLabel.wordWrap = true; 108 | 109 | centerWhiteMiniLabel = new GUIStyle (EditorStyles.whiteMiniLabel); 110 | centerWhiteMiniLabel.alignment = TextAnchor.MiddleCenter; 111 | centerWhiteMiniLabel.wordWrap = true; 112 | 113 | leftBoldLabel = new GUIStyle (EditorStyles.boldLabel); 114 | leftBoldLabel.alignment = TextAnchor.MiddleLeft; 115 | leftBoldLabel.wordWrap = true; 116 | 117 | leftMiniLabel = new GUIStyle (EditorStyles.miniLabel); 118 | leftMiniLabel.alignment = TextAnchor.MiddleLeft; 119 | leftMiniLabel.wordWrap = true; 120 | 121 | centerBoldLabel = new GUIStyle (EditorStyles.boldLabel); 122 | centerBoldLabel.alignment = TextAnchor.MiddleCenter; 123 | centerBoldLabel.wordWrap = true; 124 | 125 | wrappedLabel = new GUIStyle (EditorStyles.label); 126 | wrappedLabel.wordWrap = true; 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/MyGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17b5e5205fd05ab4e9d863d7b11c52f7 3 | timeCreated: 1471515814 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/ScriptableObjectUtility.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.IO; 4 | 5 | public static class ScriptableObjectUtility 6 | { 7 | //This makes it easy to create, name and place unique new ScriptableObject asset files. 8 | //Taken from here: http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset 9 | public static T CreateAsset (string assetName = "") where T : ScriptableObject 10 | { 11 | T asset = ScriptableObject.CreateInstance (); 12 | 13 | string path = AssetDatabase.GetAssetPath (Selection.activeObject); 14 | if (path == "") 15 | { 16 | path = "Assets"; 17 | } 18 | else if (Path.GetExtension (path) != "") 19 | { 20 | path = path.Replace (Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), ""); 21 | } 22 | assetName = assetName ?? "New " + typeof(T).ToString() + ".asset"; 23 | string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/" +assetName); 24 | 25 | AssetDatabase.CreateAsset (asset, assetPathAndName); 26 | 27 | AssetDatabase.SaveAssets (); 28 | AssetDatabase.Refresh(); 29 | EditorUtility.FocusProjectWindow (); 30 | Selection.activeObject = asset; 31 | return asset; 32 | } 33 | public static Object CreateAsset (System.Type type) 34 | { 35 | Object asset = ScriptableObject.CreateInstance(type); 36 | 37 | string path = AssetDatabase.GetAssetPath (Selection.activeObject); 38 | if (path == "") 39 | { 40 | path = "Assets"; 41 | } 42 | else if (Path.GetExtension (path) != "") 43 | { 44 | path = path.Replace (Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), ""); 45 | } 46 | 47 | string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/ New " + type.ToString() +".asset"); 48 | 49 | AssetDatabase.CreateAsset (asset, assetPathAndName); 50 | 51 | AssetDatabase.SaveAssets (); 52 | AssetDatabase.Refresh(); 53 | EditorUtility.FocusProjectWindow (); 54 | Selection.activeObject = asset; 55 | return asset; 56 | } 57 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/ScriptableObjectUtility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 19a788e64c819d64690d12a84c357e3e 3 | timeCreated: 1472680136 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Editor/UnityTextures.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5833c5a0e5c273543bcced702f4b7a64 3 | timeCreated: 1471944924 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Point.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | [System.Serializable] 4 | public struct Point 5 | { 6 | public static Point zero = new Point (0, 0); 7 | public static Point one = new Point (1, 1); 8 | 9 | public static Point north = new Point (0, 1); 10 | public static Point south = new Point (0, -1); 11 | public static Point west = new Point (1, 0); 12 | public static Point east = new Point (-1, 0); 13 | 14 | public int x; 15 | public int y; 16 | 17 | public Point (Vector2 v) 18 | { 19 | this.x = Mathf.RoundToInt(v.x); 20 | this.y = Mathf.RoundToInt(v.y); 21 | } 22 | public Point (Vector3 v) 23 | { 24 | this.x = Mathf.RoundToInt(v.x); 25 | this.y = Mathf.RoundToInt(v.y); 26 | } 27 | public Point (Point p) 28 | { 29 | this.x = p.x; 30 | this.y = p.y; 31 | } 32 | public Point (int x, int y) 33 | { 34 | this.x = x; 35 | this.y = y; 36 | } 37 | 38 | public Point Up { get { return this + north; }} 39 | public Point Down { get { return this + south; }} 40 | public Point Left { get { return this + west; }} 41 | public Point Right { get { return this + east; }} 42 | 43 | public override string ToString () 44 | { 45 | return "[" + x + "," + y + "]"; 46 | } 47 | public override bool Equals (object obj) 48 | { 49 | return obj is Point && this == (Point)obj; 50 | } 51 | public override int GetHashCode () 52 | { 53 | return x.GetHashCode () ^ y.GetHashCode (); 54 | } 55 | 56 | public static explicit operator Point (Vector2 v) 57 | { 58 | return new Point (Mathf.FloorToInt (v.x), Mathf.FloorToInt (v.y)); 59 | } 60 | public static explicit operator Point (Vector3 v) 61 | { 62 | return new Point (Mathf.FloorToInt(v.x), Mathf.FloorToInt (v.y)); 63 | } 64 | public static explicit operator Vector2 (Point c) 65 | { 66 | return new Vector2 (c.x, c.y); 67 | } 68 | public static explicit operator Vector3 (Point c) 69 | { 70 | return new Vector3 (c.x, c.y); 71 | } 72 | public static Point operator + (Point a, Point b) 73 | { 74 | return new Point (a.x + b.x, a.y + b.y); 75 | } 76 | public static Point operator - (Point a, Point b) 77 | { 78 | return new Point (a.x - b.x, a.y - b.y); 79 | } 80 | public static Point operator * (Point a, int b) 81 | { 82 | return new Point (a.x * b, a.y * b); 83 | } 84 | 85 | public static bool operator == (Point a, Point b) 86 | { 87 | return a.x == b.x && a.y == b.y; 88 | } 89 | public static bool operator != (Point a, Point b) 90 | { 91 | return !(a == b); 92 | } 93 | } -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/Point.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a6899bdf9175e142900cb0e964ec131 3 | timeCreated: 1471307766 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/SpriteExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public static class ExtensionMethods { 4 | 5 | public static Texture2D ToTexture2D(this Sprite sprite) 6 | { 7 | if(sprite.rect.width != sprite.texture.width) 8 | { 9 | Texture2D texture = new Texture2D((int)sprite.rect.width,(int)sprite.rect.height, TextureFormat.RGBA32, false); 10 | Color[] newColors = sprite.texture.GetPixels((int)sprite.textureRect.x, (int)sprite.textureRect.y, (int)sprite.textureRect.width, (int)sprite.textureRect.height ); 11 | texture.SetPixels(newColors); 12 | texture.filterMode = FilterMode.Point; 13 | texture.Apply(); 14 | return texture; 15 | } 16 | return sprite.texture; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Assets/toinfiniityandbeyond/Utility/SpriteExtensionMethods.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d214b3b1a81dec744b12f28a1a55c137 3 | timeCreated: 1472598665 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 toinfiniityandbeyond 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.4.0f3 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity Tilemap 2 | 3 | ![Tested on Unity 5.4.0f3](https://img.shields.io/badge/Tested%20on%20unity-5.4.0f3-blue.svg?style=flat-square)       4 | 5 | A simple yet highly customisable tile mapping tool made for the Unity Engine. 6 | 7 | [About](#about) 8 |       [Features](#features) 9 |       [Things I Would Like](#like) 10 | [Help](#help) 11 | [Contributing](#contributing) 12 | 13 | ![alt tag](https://github.com/toinfiniityandbeyond/unity-tilemap/blob/master/images/banner.gif) 14 | 15 | ## About 16 | This tilemap system is a robust system that allows users to customise the tile types and brushes to enable them to be able to easily paint tiles in the Unity Editor as well as in realtime. 17 | ### Features 18 | * Scriptable tiles, allows custom behaviour. Including: 19 | * SimpleTile 20 | * RandomTile 21 | * AutoTile 22 | * **TODO:** AnimatedTile 23 | * **TODO:** ConditionalTile 24 | * Tile Editor 25 | * Scriptable tools, allows custom behaviour. Including: 26 | * Pencil 27 | * Brush 28 | * Fill 29 | * Eraser 30 | * Eyedropper 31 | * Line 32 | * Rectangle 33 | * Ellipse 34 | * Proper Undo/Redo ([@nickgirardo](https://github.com/nickgirardo)) 35 | * Export/Import to ScriptableObject 36 | * Access the tilemap through a clean API 37 | 38 | ``` c# 39 | //Get tiles by using 40 | GetTileAt(Vector2 worldPosition); 41 | GetTileAt(int x, int y); 42 | //Set tiles by using 43 | SetTileAt(int x, int y, ScriptableTile to); 44 | //Invoke a callback to update tiles 45 | UpdateTileAt(int x, int y); 46 | UpdateTiles(); 47 | UpdateNeighbours(int x, int y); 48 | UpdateType(ScriptableTile type); 49 | [... and more] 50 | ``` 51 | * Different rendering modes 52 | * Single Sprites 53 | * Multiple Quads 54 | * **TODO:** TileMapCollider2D (Use PolygonCollider2D underneath) 55 | 56 | ### Things I Would Like (But have been put on the back burner) 57 | * Good documentation 58 | * More rendering modes 59 | * Single Quad 60 | * Chunked Quads 61 | * Infinite or limited tilemap size (only available on chunked quads?) 62 | * Layers 63 | * In-Game tilemap editor 64 | 65 | ## Help ([More on the wiki](../../wiki)) 66 | 67 | ### How do I make my own tiles? 68 | In the project window click on _Create > Tilemap > Tiles_ and select a scriptable tile type to create. You can edit the tiles variables by just clicking on it, like anyother asset. 69 | 70 | If you want to create your own scriptable tiles (Like the **RandomTile** or **AutoTile**) then click on _Create > Tilemap > Create C# Tile Script_ and edit like anyother script. Alternatively create a C# class that inherits **ScriptableTile** 71 | 72 | ### Can I make custom tools? 73 | Yes. If you want to create your own tools (Like the **Pencil** or **Eyedropper**) then click on _Create > Tilemap > Create C# Tool Script_ and edit like anyother script. Since all tools (even the included ones) inherit from **ScriptableTool** you can also simply create a C# class that inherits from **ScriptableTool**. Any class that inherits **ScriptableTool** will automatically be able to use in the Edit Mode tile editor, any public variables will also be exposed in the tile editor toolbar. 74 | 75 | ## Contributing 76 | Feel free to contribute, I will accept pull requests if I think it will benefit the tool. If you want to help but are not sure with what have a look at the **TODOs** as well as the **Things I Would Like** sections for ideas. 77 | 78 | Special thanks to the following for their contribution: 79 | * [@nickgirardo](https://github.com/nickgirardo) 80 | * [@Hammster](https://github.com/Hammster) 81 | -------------------------------------------------------------------------------- /images/banner.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/paullj/unity-tilemap/c08fad2fff7f91f081096e3d1f62b63dbdf17821/images/banner.gif --------------------------------------------------------------------------------