private void DrawToCell(CellData cellData) { for (var i = cellData.overlapTiles.Length - 1; i >= 0; i--) { Undo.DestroyObjectImmediate(cellData.overlapTiles[i].gameObject); } //var newTile = Instantiate(cellData.activeTilePrefab); var newTile = (GameObject)PrefabUtility.InstantiatePrefab(cellData.activeTilePrefab); newTile.isStatic = true; var tb = newTile.GetComponent <TileBounds>(); var cellBounds = TMEditorUtils.GetCellBounds(cellData.worldPosition, editorSettings.cellSize, out _); var tileXform = tb.BoxPointToWorldMatrix(TileBounds.BoundsCorner.BottomNearLeft).inverse; var boxPoint = tileXform.MultiplyPoint(Vector3.zero); Debug.DrawLine(Vector3.zero, boxPoint); newTile.transform.position = cellData.cell * editorSettings.cellSize + (float3)boxPoint; newTile.transform.RotateAround(tb.BoxPointToWorldMatrix(TileBounds.BoundsCorner.Center).MultiplyPoint(Vector3.zero), Vector3.up, cellData.rotation); owningEditor.SortTileObject(newTile); Undo.RegisterCreatedObjectUndo(newTile, "Draw"); }
internal override void OnMouseDrag(int button, CellData cellData) { if (math.any(cellData.cell != cellData.lastCell)) { // Debug.Log($"{cellData.cell} : {cellData.lastCell}"); // Debug.Log($"button:{button} Drag"); selectionBounds.Encapsulate(TMEditorUtils.GetCellBounds(cellData.cell, editorSettings.cellSize, out _)); } }
internal override void OnMouseDown(int button, CellData cellData) { GUIUtility.hotControl = TMEditor.BlockingID; // _selecting = true; selection.Clear(); Bounds bounds = TMEditorUtils.GetCellBounds(cellData.cell, editorSettings.cellSize, out _); selectionBounds = bounds; Event.current.Use(); }
//! private void FireToolEvents(SceneView sceneView) { var tool = _tilemapTools[_activeToolMode]; var workPlane = GetCurrentWorkPlane(); if (GetPlaneHit(workPlane, out Vector3 hitPoint)) { Bounds targetCellBounds = TMEditorUtils.GetCellBounds(hitPoint, editorSettings.cellSize, out int3 targetCell); var cellData = GetCellData(hitPoint); //draw the handles for the tool tool.OnDrawHandles(cellData, sceneView.camera, out Color toolBoundsColor); //draw the cell bounds with the color returned by the active tool Handles.color = toolBoundsColor; Handles.DrawWireCube(targetCellBounds.center, targetCellBounds.size); var floorPos = hitPoint; floorPos.y = 0; Handles.color = _drawHeight > 0 ? new Color(0f, 1f, 0f, 0.5f) : new Color(1f, 0f, 0f, 0.5f); Handles.DrawLine(hitPoint, floorPos); if (_inputDisabled) { return; } if (Event.current.isKey) { KeyCode eventKey = Event.current.keyCode; if (Event.current.type == EventType.KeyDown) { //only fire if the key is not already held down if (!downKeys.Contains(eventKey)) { downKeys.Add(eventKey); tool.OnKeyDown(cellData, eventKey); } } if (Event.current.type == EventType.KeyUp) { tool.OnKeyUp(cellData, eventKey); downKeys.Remove(eventKey); } } if (Event.current.isMouse) { if (Event.current.type == EventType.MouseDown) { tool.OnMouseDown(Event.current.button, cellData); } else if (Event.current.type == EventType.MouseUp) { tool.OnMouseUp(Event.current.button, cellData); } else if (Event.current.type == EventType.MouseDrag) { tool.OnMouseDrag(Event.current.button, cellData); } else if (Event.current.type == EventType.MouseMove) { tool.OnMouseMove(cellData); } _lastCell = cellData.cell; } } }