From bedeb7dde0df7915792421c1960ae2bc1a61e6e4 Mon Sep 17 00:00:00 2001 From: Janis Date: Thu, 16 Feb 2023 18:14:52 +0100 Subject: [PATCH] add cillidable tm --- Assets/PlaceableObjects/house.asset | 2 +- Assets/Scenes/SampleScene.unity | 305 ++++++++++++++++++++++++++- Assets/Scripts/GridBuildingSystem.cs | 12 +- 3 files changed, 301 insertions(+), 18 deletions(-) diff --git a/Assets/PlaceableObjects/house.asset b/Assets/PlaceableObjects/house.asset index 556c1ce..54de63b 100644 --- a/Assets/PlaceableObjects/house.asset +++ b/Assets/PlaceableObjects/house.asset @@ -15,4 +15,4 @@ MonoBehaviour: objectName: house prefab: {fileID: 6244317213382018835, guid: 5eebe6599cdf53b4da6f656f81588cb8, type: 3} width: 4 - height: 5 + height: 2 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 774f293..de8c41d 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -347,8 +347,8 @@ CapsuleCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 - m_Offset: {x: 0, y: -0.85} - m_Size: {x: 0.25, y: 0.25} + m_Offset: {x: 0.005384445, y: -0.8123081} + m_Size: {x: 0.3146143, y: 0.3146143} m_Direction: 0 --- !u!1 &519420028 GameObject: @@ -1265,6 +1265,56 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: -14, y: 1, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 9 + m_TileSpriteIndex: 9 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -13, y: 1, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 10 + m_TileSpriteIndex: 10 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -12, y: 1, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 10 + m_TileSpriteIndex: 10 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -11, y: 1, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 10 + m_TileSpriteIndex: 10 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -10, y: 1, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 11 + m_TileSpriteIndex: 11 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: -6, y: 1, z: 0} second: serializedVersion: 2 @@ -1285,6 +1335,56 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: -14, y: 2, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 8 + m_TileSpriteIndex: 0 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -13, y: 2, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -12, y: 2, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -11, y: 2, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -10, y: 2, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 12 + m_TileSpriteIndex: 12 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: -6, y: 2, z: 0} second: serializedVersion: 2 @@ -1305,6 +1405,56 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: -14, y: 3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 8 + m_TileSpriteIndex: 0 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -13, y: 3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -12, y: 3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -11, y: 3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -10, y: 3, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 12 + m_TileSpriteIndex: 12 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: -6, y: 3, z: 0} second: serializedVersion: 2 @@ -1325,6 +1475,56 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: -14, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 8 + m_TileSpriteIndex: 0 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -13, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -12, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -11, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -10, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 12 + m_TileSpriteIndex: 12 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: -6, y: 4, z: 0} second: serializedVersion: 2 @@ -1345,6 +1545,56 @@ Tilemap: m_TileObjectToInstantiateIndex: 65535 dummyAlignment: 0 m_AllTileFlags: 1073741825 + - first: {x: -14, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 15 + m_TileSpriteIndex: 15 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -13, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 13 + m_TileSpriteIndex: 13 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -12, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 13 + m_TileSpriteIndex: 13 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -11, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 13 + m_TileSpriteIndex: 13 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: -10, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 14 + m_TileSpriteIndex: 14 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 - first: {x: -6, y: 5, z: 0} second: serializedVersion: 2 @@ -1563,11 +1813,27 @@ Tilemap: m_Data: {fileID: 11400000, guid: de375734846bed342be9a639619a3330, type: 2} - m_RefCount: 10 m_Data: {fileID: 11400000, guid: 6da882e9d668a874e8d8a4b0041f49f7, type: 2} - - m_RefCount: 0 - m_Data: {fileID: 0} + - m_RefCount: 3 + m_Data: {fileID: 11400000, guid: ec162940aee17f84f86d1120363e2d1e, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 4794884fc707d9240b3891ad1f4d922c, type: 2} + - m_RefCount: 3 + m_Data: {fileID: 11400000, guid: 0ba759b0abce8f4498e98312c253e60c, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 66bbdf60901481b48879991c4f497054, type: 2} + - m_RefCount: 3 + m_Data: {fileID: 11400000, guid: 6ffbd5f0e6914f54688dbc6808189358, type: 2} + - m_RefCount: 3 + m_Data: {fileID: 11400000, guid: a23ac6903163ce34f852b6f52729d7ed, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 4586dcb5a5678044ca2becbf7f75c03a, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 725cd5e9fc2938844aabf95dd02aa275, type: 2} + - m_RefCount: 9 + m_Data: {fileID: 11400000, guid: a1c63d5c10898c844a124202ac7c4276, type: 2} m_TileSpriteArray: - - m_RefCount: 0 - m_Data: {fileID: 0} + - m_RefCount: 3 + m_Data: {fileID: 1889832603, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} - m_RefCount: 1 m_Data: {fileID: 396640937, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} - m_RefCount: 1 @@ -1584,8 +1850,24 @@ Tilemap: m_Data: {fileID: 240297327, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} - m_RefCount: 1 m_Data: {fileID: 809146451, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 1 + m_Data: {fileID: -1209826814, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 3 + m_Data: {fileID: 204721436, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 61984042, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 3 + m_Data: {fileID: 765331772, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 3 + m_Data: {fileID: -434640523, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 1699634537, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 1 + m_Data: {fileID: -1569505189, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + - m_RefCount: 9 + m_Data: {fileID: 1169926726, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} m_TileMatrixArray: - - m_RefCount: 47 + - m_RefCount: 72 m_Data: e00: 1 e01: 0 @@ -1604,13 +1886,13 @@ Tilemap: e32: 0 e33: 1 m_TileColorArray: - - m_RefCount: 47 + - m_RefCount: 72 m_Data: {r: 1, g: 1, b: 1, a: 1} m_TileObjectToInstantiateArray: [] m_AnimationFrameRate: 1 m_Color: {r: 1, g: 1, b: 1, a: 1} - m_Origin: {x: -6, y: -3, z: 0} - m_Size: {x: 13, y: 13, z: 1} + m_Origin: {x: -14, y: -3, z: 0} + m_Size: {x: 21, y: 13, z: 1} m_TileAnchor: {x: 0.5, y: 0.5, z: 0} m_TileOrientation: 0 m_TileOrientationMatrix: @@ -56382,7 +56664,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: TESTPO: {fileID: 11400000, guid: 40437410555fcda43ab2ec4c9a4c2807, type: 2} - collisionTm: {fileID: 1579890810} + collisionTm: {fileID: 789509406} + occupiedTm: {fileID: 1579890810} occupiedTile: {fileID: 11400000, guid: 4815673d17e2b7246b5812e51b47cd6d, type: 2} --- !u!1 &1579890809 GameObject: diff --git a/Assets/Scripts/GridBuildingSystem.cs b/Assets/Scripts/GridBuildingSystem.cs index abc78f0..c96f55c 100644 --- a/Assets/Scripts/GridBuildingSystem.cs +++ b/Assets/Scripts/GridBuildingSystem.cs @@ -7,7 +7,9 @@ public class GridBuildingSystem : MonoBehaviour { public PlaceableObject TESTPO; //! DEBUG + public Tilemap collisionTm; + public Tilemap occupiedTm; public TileBase occupiedTile; private PlaceableObject placeableObject; @@ -117,7 +119,7 @@ public class GridBuildingSystem : MonoBehaviour tileArray[index] = occupiedTile; } - collisionTm.SetTilesBlock(area, tileArray); + occupiedTm.SetTilesBlock(area, tileArray); } @@ -130,16 +132,14 @@ public class GridBuildingSystem : MonoBehaviour tileArray[index] = null; } - collisionTm.SetTilesBlock(area, tileArray); + occupiedTm.SetTilesBlock(area, tileArray); } private bool IsOccupied(Vector3Int startPos, Vector3Int poSize) { - - BoundsInt area = new BoundsInt(startPos, poSize); - TileBase[] tileArray = collisionTm.GetTilesBlock(area); - + List tileArray = new List(occupiedTm.GetTilesBlock(area)); + tileArray.AddRange(collisionTm.GetTilesBlock(area)); foreach (TileBase tile in tileArray) { if (tile != null)