using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; namespace BITKit.UX { public class CellContainer : VisualElement { public new class UxmlFactory : UxmlFactory { } public int CellSize { get; set; } = 64; public CellContainer() { RegisterCallback(x => { MarkDirtyRepaint(); }); generateVisualContent += GenerateVisualContent; } private void GenerateVisualContent(MeshGenerationContext obj) { if(contentRect.height<=0 || contentRect.width<=0)return; var painter = obj.painter2D; painter.lineWidth = resolvedStyle.borderTopWidth; painter.strokeColor = resolvedStyle.borderTopColor; var yCount = contentRect.height / CellSize; var xCount = contentRect.width / CellSize; for (var x = 1; x < xCount; x++) { painter.BeginPath(); painter.MoveTo(new Vector2(x * CellSize, 0)); painter.LineTo(new Vector2(x * CellSize, contentRect.height)); painter.Stroke(); } for (var y = 1; y < yCount; y++) { painter.BeginPath(); painter.MoveTo(new Vector2(0, y * CellSize)); painter.LineTo(new Vector2(contentRect.width, y * CellSize)); painter.Stroke(); } } } }