public bool RuleMatches(TilingRule2 rule, Vector3Int position, ITilemap tilemap, int angle) { for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { //Out line if (!(x == 0 && y == 0)) { Vector3Int offset = new Vector3Int(x, y, 0); Vector3Int rotated = GetRotatedPos(offset, angle); int index = GetIndexOfOffset(rotated); TileBase tile = tilemap.GetTile(position + offset); if (rule.m_Neighbors [index] == TilingRule2.Neighbor.This && tile != this || rule.m_Neighbors [index] == TilingRule2.Neighbor.NotThis && tile == this) { return(false); } } } } return(true); }
public bool RuleMatches(TilingRule2 rule, Vector3Int position, ITilemap tilemap, ref Matrix4x4 transform) { //check rule against rotation of 0, 90, 180, 270 for (int angle = 0; angle <= (rule.m_RuleTransform == TilingRule2.Transform.Rotated ? 270 : 0); angle += 90) { if (RuleMatches(rule, position, tilemap, angle)) { transform = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, -angle), Vector3.one); return(true); } } //Check rule against x-axis mirror if ((rule.m_RuleTransform == TilingRule2.Transform.MirrorX) && RuleMatches(rule, position, tilemap, true, false)) { transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(-1f, 1f, 1f)); return(true); } //Check rule against y-axis mirror if ((rule.m_RuleTransform == TilingRule2.Transform.MirrorY) && RuleMatches(rule, position, tilemap, false, true)) { transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, -1f, 1f)); return(true); } return(false); }