diff --git a/Assets/OkapiKit/Scripts/Systems/GridSystem.cs b/Assets/OkapiKit/Scripts/Systems/GridSystem.cs index 5f38542..217082d 100644 --- a/Assets/OkapiKit/Scripts/Systems/GridSystem.cs +++ b/Assets/OkapiKit/Scripts/Systems/GridSystem.cs @@ -110,6 +110,14 @@ protected override void CheckErrors() { _logs.Add(new LogEntry(LogEntry.Type.Error, "No grid in object", "Grid system need to be on an object with a Grid component!")); } + + if ((gridcolliders != null) && (gridcolliders.Length > 0)) + { + for (int i = 0; i < gridcolliders.Length; i++) + { + _logs.Add(new LogEntry(LogEntry.Type.Error, $"Invalid grid collider at index {i}", "There's a collider entry, but the object is invalid!")); + } + } } protected void Start() @@ -126,13 +134,14 @@ void UpdateColliders() if ((gridcolliders != null) && (gridcolliders.Length > 0)) { - bounds = gridcolliders[0].bounds; + bool init = false; - for (int i = 1; i < gridcolliders.Length; i++) + for (int i = 0; i < gridcolliders.Length; i++) { if (gridcolliders[i] == null) continue; - - bounds.Encapsulate(gridcolliders[i].bounds); + + if (!init) { bounds = gridcolliders[i].bounds; init = true; } + else bounds.Encapsulate(gridcolliders[i].bounds); } } @@ -144,28 +153,33 @@ void UpdateColliders() mapsByLayer.Clear(); // Compute collision masks - foreach (var collider in gridcolliders) + if ((gridcolliders != null) && (gridcolliders.Length > 0)) { - var map = GetMapByLayer(collider.gameObject.layer); - int idx; + foreach (var collider in gridcolliders) + { + if (collider == null) continue; - Vector2 worldPos = new Vector2(bounds.min.x + grid.cellSize.x * 0.5f, bounds.min.y + grid.cellSize.y * 0.5f); + var map = GetMapByLayer(collider.gameObject.layer); + int idx; - for (int y = 0; y < mapSizeY; y++) - { - for (int x = 0; x < mapSizeX; x++) + Vector2 worldPos = new Vector2(bounds.min.x + grid.cellSize.x * 0.5f, bounds.min.y + grid.cellSize.y * 0.5f); + + for (int y = 0; y < mapSizeY; y++) { - if (collider.OverlapPoint(worldPos)) + for (int x = 0; x < mapSizeX; x++) { - idx = y * stride + x / 8; - map[idx] |= (byte)(1 << (x % 8)); - - Debug.DrawLine(worldPos, worldPos + new Vector2(5.0f, 5.0f), Color.red, 5.0f); + if (collider.OverlapPoint(worldPos)) + { + idx = y * stride + x / 8; + map[idx] |= (byte)(1 << (x % 8)); + + Debug.DrawLine(worldPos, worldPos + new Vector2(5.0f, 5.0f), Color.red, 5.0f); + } + worldPos.x += grid.cellSize.x; } - worldPos.x += grid.cellSize.x; + worldPos.x = bounds.min.x + grid.cellSize.x * 0.5f; + worldPos.y += grid.cellSize.y; } - worldPos.x = bounds.min.x + grid.cellSize.x * 0.5f; - worldPos.y += grid.cellSize.y; } } diff --git a/Assets/OkapiKit/package.json b/Assets/OkapiKit/package.json index 92b1877..1d0d7bc 100644 --- a/Assets/OkapiKit/package.json +++ b/Assets/OkapiKit/package.json @@ -1,7 +1,7 @@ { "name": "com.videojogoslusofona.okapikit", "displayName": "OkapiKit", - "version": "1.17.1", + "version": "1.17.2", "unity": "6000.0", "description": "OkapiKit is a toolkit for creation of simple games without code.", "keywords": [ "kit" ], diff --git a/Assets/OkapiKitSamples/package.json b/Assets/OkapiKitSamples/package.json index cbc36d9..eb9030c 100644 --- a/Assets/OkapiKitSamples/package.json +++ b/Assets/OkapiKitSamples/package.json @@ -1,14 +1,14 @@ { "name": "com.videojogoslusofona.okapikit.samples", "displayName": "OkapiKit Samples", - "version": "1.17.1", + "version": "1.17.2", "unity": "6000.0", "description": "OkapiKit is a toolkit for creation of simple games without code. This package is just the samples for OkapiKit, they are not required to use Okapi Kit, and requires the Okapi Kit package.", "keywords": [ "okapi", "samples" ], "category": "samples", "dependencies": {}, "relatedPackages": { - "com.videojogoslusofona.okapikit": "1.17.1" + "com.videojogoslusofona.okapikit": "1.17.2" }, "author": { "name": "Videojogos ULHT", diff --git a/ReleaseNotes.md b/ReleaseNotes.md index ca11a68..eb49180 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,5 +1,9 @@ # Release Notes +## V1.17.2 + +- Added tests for lack of grid colliders on GridSystem + ## V1.17.1 - Fixed issues with builds (auto-added using clauses that stopped compilation in release mode)