private void CreateNewObject(Vector3 position)
        {
            // Get Floor height before generating a new Tile object
            position.y = GridUtility.FloorHeight(position);

            if (GridBase.Instance.alignY)
            {
                position.y = GridUtility.CheckVerticalAlignment(position.y);
            }
            AddTile(position);
        }
        private void MoveBrush()
        {
            RaycastHit hitInfo = RaycastGUIToFloor(Event.current.mousePosition);

            if (hitInfo.collider != null)
            {
                Vector3 position = GridUtility.GetAlignedPosition(hitInfo.point);
                position.y = GridUtility.FloorHeight(position);
                brush.transform.position = position + offset + BRUSH_OFFSET;

                float scale = gridBase.tileSize * brushScales[brushIndex.intValue];
                brush.transform.localScale = new Vector3(scale, scale, scale);
            }
        }
Example #3
0
        private void CreateTile(Vector3 position)
        {
            // Get Floor height before generating a new Tile object
            position.y = GridUtility.FloorHeight(position);

            if (GridBase.Instance.alignY)
            {
                position.y = GridUtility.CheckVerticalAlignment(position.y);
            }

            if (!gridBase.ContainsTileAt(position))
            {
                TilePositionsProperty.arraySize++;
                TilePositionsProperty.serializedObject.ApplyModifiedProperties();
                TilePositionsProperty.GetArrayElementAtIndex(gridBase.storage.tilePositions.Count - 1).vector3Value = position;
                TilePositionsProperty.serializedObject.ApplyModifiedProperties();
                meshPainter.DrawTile(position);
            }
        }
        private void OnSceneGUI()
        {
            if (!enableDesigner.boolValue)
            {
                return;
            }

            SerializedProperty checkTiles = TilePositionsProperty;

            Event current = Event.current;

            switch (current.type)
            {
            case EventType.MouseUp:

                Vector3    alignedPosition = Vector3.zero;
                RaycastHit hitInfo         = RaycastGUIToFloor(Event.current.mousePosition);
                if (hitInfo.collider == null)
                {
                    break;
                }

                alignedPosition = GridUtility.GetAlignedPosition(hitInfo.point);
                if (current.button == 0)
                {
                    if (controlDown)
                    {
                        Undo.RecordObject(target, "Delete Tiles");
                        DeleteTiles(alignedPosition);
                    }
                    else
                    {
                        Undo.RecordObject(target, "Create Tiles");
                        CreateTiles(alignedPosition);
                    }
                    current.Use();
                }
                break;

            case EventType.MouseMove:
                MoveBrush();
                break;

            case EventType.KeyDown:
                if (Event.current.keyCode == (KeyCode.LeftControl))
                {
                    controlDown = true;
                }
                break;

            case EventType.KeyUp:
                if (Event.current.keyCode == (KeyCode.LeftControl))
                {
                    controlDown = false;
                }
                break;

            case EventType.Layout:
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
                break;

            case EventType.MouseEnterWindow:
                if (SceneView.sceneViews.Count > 0)
                {
                    SceneView sceneView = (SceneView)SceneView.sceneViews[0];
                    sceneView.Focus();
                }
                break;
            }
        }