Exemplo n.º 1
0
        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();
        }
Exemplo n.º 4
0
        private void DrawHandles(Vector3 hitPoint, Bounds targetCellBounds)
        {
            //hit point rectangle
            Handles.color = new Color(1f, 0f, 0f, 0.5f);
            Handles.DrawWireCube(hitPoint, Vector3.one * .1f);

            Handles.Label(hitPoint, TMEditorUtils.WorldToCell(hitPoint, editorSettings.cellSize).ToString());
            //
            // var yZeroPoint = hitPoint;
            // yZeroPoint.y = 0;
            //
            // float3 min = targetCellBounds.min;
            // min.y = 0;
            // float3 max = targetCellBounds.max;
            // max.y = 0;
            // var points = new Vector3[]
            // {
            //    min,
            //    new float3(min.x, 0, max.z),
            //    max,
            //    new float3(max.x, 0, min.z)
            // };
            //
            // Handles.zTest = CompareFunction.LessEqual;
            // Handles.color = new Color(1f, 1f, 1f, 0.25f);
            // Handles.DrawSolidRectangleWithOutline(points, new Color(0f, 0f, 0f, 1f), Color.red);
            //
            // Handles.zTest = CompareFunction.Always;
            // var delta = hitPoint - yZeroPoint;
            // int c = Mathf.FloorToInt(Mathf.Abs(delta.y / tmEditorSettings.cellSize.y)) + 1;
            // //height tick marks
            // for (int i = 0; i < c; i++)
            // {
            //    Handles.DrawWireCube(yZeroPoint + delta.normalized * (i * tmEditorSettings.cellSize.y),
            //       Vector3.one * .1f);
            // }
            //
            // //vertical line from hit point to zero plane
            // Handles.DrawLine(hitPoint, yZeroPoint);
            // Handles.Label(hitPoint + Vector3.up * .2f, $"{_drawHeight:f3}");
            // Handles.DrawLine(Vector3.zero, Vector3.up);
            //
            // //draw the targeted cell bounds
            // Handles.color = new Color(1f, 0f, 0f, 0.18f);
            // //Handles.DrawWireCube(targetCellBounds.center, targetCellBounds.size);
        }
Exemplo n.º 5
0
        private CellData GetCellData(Vector3 hitPoint)
        {
            CellData data = new CellData();

            data.cell             = TMEditorUtils.WorldToCell(hitPoint, editorSettings.cellSize);
            data.worldPosition    = hitPoint;
            data.activeTilePrefab = selectedTilePrefab;
            data.rotation         = activeRotation;
            data.lastCell         = _lastCell;
            data.overlapTiles     = GetOverlappedTiles(hitPoint);

            if (data.overlapTiles.Length > 0)
            {
                data.tile = data.overlapTiles[0];
            }
            return(data);
        }
Exemplo n.º 6
0
        //!
        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;
                }
            }
        }