private void DrawModifier(CellDataMin cellDataMin) { var cellPosition = cellDataMin.CellPosition; var prefab = GetCellFullConfig(cellDataMin.CellConfigMin).Prefab; var go = _grid.DrawModifier(cellPosition, prefab, CellInfoHelper.IsRotatableCell(cellDataMin.CellConfigMin.CellType, cellDataMin.CellConfigMin.CellSubType)); }
private void DrawCell(CellDataMin cellDataMin) { var cellConfigMin = cellDataMin.CellConfigMin; var cellPosition = cellDataMin.CellPosition; var prefab = GetCellFullConfig(cellConfigMin).Prefab; var go = _grid.DrawCell(cellPosition, prefab, CellInfoHelper.IsRotatableCell(cellConfigMin.CellType, cellConfigMin.CellSubType)); go.GetComponent <CellView>().SetDebugText(cellDataMin.CellPosition.x + "," + cellDataMin.CellPosition.y); }
private void SetupWalls(LevelConfig levelConfig) { var wallCellConfig = _configsProvider.CellConfigProvider.GetConfig(CellType.Wall, (CellSubType)_defaultWall).CellConfigMin; var groundCellConfig = _configsProvider.CellConfigProvider.GetConfig(CellType.Ground, (CellSubType)_defaultGround).CellConfigMin; (int start, int end) GetBoundCoords(int size) { var bigSize = (int)Math.Ceiling((float)size / 2); var smallSize = size - bigSize; return(-smallSize, bigSize - 1); } var horBounds = GetBoundCoords(!levelConfig.IsTransposed ? _numCellsHor : _numCellsVer); var verBounds = GetBoundCoords(!levelConfig.IsTransposed ? _numCellsVer : _numCellsHor); for (var i = horBounds.start; i <= horBounds.end; i++) { var topPoint = new Vector2Int(i, verBounds.end); var cell = new CellDataMin(topPoint, wallCellConfig); levelConfig.AddCell(cell); var bottomPoint = new Vector2Int(i, verBounds.start); cell = new CellDataMin(bottomPoint, wallCellConfig); levelConfig.AddCell(cell); } for (var i = verBounds.start; i < verBounds.end; i++) { var leftPoint = new Vector2Int(horBounds.start, i); var cell = new CellDataMin(leftPoint, wallCellConfig); levelConfig.AddCell(cell); var rightPoint = new Vector2Int(horBounds.end, i); cell = new CellDataMin(rightPoint, wallCellConfig); levelConfig.AddCell(cell); } for (var i = horBounds.start; i <= horBounds.end; i++) { for (var j = verBounds.start; j < verBounds.end; j++) { var point = new Vector2Int(i, j); var cell = new CellDataMin(point, groundCellConfig); levelConfig.AddCell(cell); } } }
private void DuringSceneGui(SceneView sceneView) { var currentEvent = Event.current; var isPaintKeyDown = currentEvent.control; var isEraseKeyDown = currentEvent.shift; var isUseBrushKeyHold = isPaintKeyDown || isEraseKeyDown; if (isUseBrushKeyHold) { HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); if (TryGetMouseHit(currentEvent, out var hit)) { Handles.color = Color.green; var brushSize = 2f; var normalRotation = Quaternion.LookRotation(hit.normal); var snappedPoint = _grid.CellToWorld(_grid.WorldToCell(hit.point)); Handles.ArrowHandleCap(2, snappedPoint, normalRotation, brushSize, EventType.Repaint); Handles.CircleHandleCap(3, snappedPoint, normalRotation, brushSize, EventType.Repaint); var gridPosition = GetGridPosition(hit.point); Handles.BeginGUI(); GUILayout.Label($"({gridPosition.x},{gridPosition.y})"); Handles.EndGUI(); } } if (isUseBrushKeyHold && currentEvent.type == EventType.MouseDown) { if (_isDrawing == false) { OnStartDrawing(); } _isDrawing = true; } if (_isDrawing && (!isUseBrushKeyHold || currentEvent.type == EventType.MouseUp)) { _isDrawing = false; } if (_isDrawing) { if (TryGetMouseHit(currentEvent, out var hit)) { var cellPosition = GetGridPosition(hit.point); var isGround = IsGround(cellPosition); if (isPaintKeyDown) { if (_currentBrushCellConfig != null && (_levelConfig.IsCellFree(cellPosition) || isGround)) { var isFree = _levelConfig.IsCellFree(cellPosition); var isBrushOfModifierType = _currentBrushCellConfig.CellConfigMin.CellType == CellType.Modifier; var cellDataMin = new CellDataMin(cellPosition, _currentBrushCellConfig.CellConfigMin); if (isBrushOfModifierType && isGround) { EraseModifier(cellPosition); _levelConfig.AddModifier(cellDataMin); DrawModifier(cellDataMin); } else { EraseCell(cellPosition); _levelConfig.AddCell(cellDataMin); DrawCell(cellDataMin); } } } else { if (!_levelConfig.IsCellFree(cellPosition) && !isGround) { EraseCell(cellPosition); var cellConfig = _configsProvider.CellConfigProvider.GetConfig(CellType.Ground); var cellDataMin = new CellDataMin(cellPosition, cellConfig.CellConfigMin); _levelConfig.AddCell(cellDataMin); DrawCell(cellDataMin); } else if (isGround) { EraseModifier(cellPosition); } } } } }