public virtual void RuleMatrixOnGUI(RuleTile tile, Rect rect, BoundsInt bounds, RuleTile.TilingRule tilingRule) { Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); float w = rect.width / bounds.size.x; float h = rect.height / bounds.size.y; for (int y = 0; y <= bounds.size.y; y++) { float top = rect.yMin + y * h; Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top)); } for (int x = 0; x <= bounds.size.x; x++) { float left = rect.xMin + x * w; Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax)); } Handles.color = Color.white; var neighbors = tilingRule.GetNeighbors(); for (int y = bounds.yMin; y < bounds.yMax; y++) { for (int x = bounds.xMin; x < bounds.xMax; x++) { Vector3Int pos = new Vector3Int(x, y, 0); Rect r = new Rect(rect.xMin + (x - bounds.xMin) * w, rect.yMin + (-y + bounds.yMax - 1) * h, w - 1, h - 1); if (x != 0 || y != 0) { if (neighbors.ContainsKey(pos)) { RuleOnGUI(r, pos, neighbors[pos]); RuleTooltipOnGUI(r, neighbors[pos]); } if (RuleNeighborUpdate(r, tilingRule, neighbors, pos)) { tile.UpdateNeighborPositions(); } } else { RuleTransformOnGUI(r, tilingRule.m_RuleTransform); if (RuleTransformUpdate(r, tilingRule)) { tile.UpdateNeighborPositions(); } } } } }
public override void RuleMatrixOnGUI(RuleTile tile, Rect rect, BoundsInt bounds, RuleTile.TilingRule tilingRule) { var hexTile = tile as HexagonalRuleTile; bool flatTop = hexTile.m_FlatTop; Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f); float w = rect.width / (flatTop ? bounds.size.y : bounds.size.x); float h = rect.height / (flatTop ? bounds.size.x : bounds.size.y); // Grid if (flatTop) { for (int y = 0; y <= bounds.size.y; y++) { float left = rect.xMin + y * w; float offset = 0; if (y == 0 && bounds.yMax % 2 == 0) { offset = h / 2; } else if (y == bounds.size.y && bounds.yMin % 2 != 0) { offset = h / 2; } Handles.DrawLine(new Vector3(left, rect.yMin + offset), new Vector3(left, rect.yMax - offset)); if (y < bounds.size.y) { bool noOffset = (y + bounds.yMax) % 2 != 0; for (int x = 0; x < (noOffset ? (bounds.size.x + 1) : bounds.size.x); x++) { float top = rect.yMin + x * h + (noOffset ? 0 : h / 2); Handles.DrawLine(new Vector3(left, top), new Vector3(left + w, top)); } } } } else { for (int y = 0; y <= bounds.size.y; y++) { float top = rect.yMin + y * h; float offset = 0; if (y == 0 && bounds.yMax % 2 == 0) { offset = w / 2; } else if (y == bounds.size.y && bounds.yMin % 2 != 0) { offset = w / 2; } Handles.DrawLine(new Vector3(rect.xMin + offset, top), new Vector3(rect.xMax - offset, top)); if (y < bounds.size.y) { bool noOffset = (y + bounds.yMax) % 2 != 0; for (int x = 0; x < (noOffset ? (bounds.size.x + 1) : bounds.size.x); x++) { float left = rect.xMin + x * w + (noOffset ? 0 : w / 2); Handles.DrawLine(new Vector3(left, top), new Vector3(left, top + h)); } } } } var neighbors = tilingRule.GetNeighbors(); // Icons Handles.color = Color.white; for (int y = bounds.yMin; y < bounds.yMax; y++) { int xMax = y % 2 == 0 ? bounds.xMax : (bounds.xMax - 1); for (int x = bounds.xMin; x < xMax; x++) { Vector3Int pos = new Vector3Int(x, y, 0); Vector2 offset = new Vector2(x - bounds.xMin, -y + bounds.yMax - 1); Rect r = flatTop ? new Rect(rect.xMin + offset.y * w, rect.yMax - offset.x * h - h, w - 1, h - 1) : new Rect(rect.xMin + offset.x * w, rect.yMin + offset.y * h, w - 1, h - 1); if (y % 2 != 0) { if (flatTop) { r.y -= h / 2; } else { r.x += w / 2; } } if (x != 0 || y != 0) { if (neighbors.ContainsKey(pos)) { RuleOnGUI(r, pos, neighbors[pos]); RuleTooltipOnGUI(r, neighbors[pos]); } if (RuleNeighborUpdate(r, tilingRule, neighbors, pos)) { tile.UpdateNeighborPositions(); } } else { RuleTransformOnGUI(r, tilingRule.m_RuleTransform); if (RuleTransformUpdate(r, tilingRule)) { tile.UpdateNeighborPositions(); } } } } }