Exemple #1
0
        public void SelectAndDragOutsideAndBackInsideOfPalette_DoesSelectAction()
        {
            var w = CreatePaletteWindow();

            w.palette = AssetDatabase.LoadAssetAtPath <GameObject>(defaultTemporaryPalettePath);
            Selection.activeObject = null;
            TilemapEditorTool.SetActiveEditorTool(typeof(SelectTool));

            Event ev = new Event();

            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(2.5f, -2.5f)) +
                               new Vector2(0, paletteHeaderHeight);
            ev.type = EventType.MouseDown;
            w.SendEvent(ev);
            ev.type          = EventType.MouseDrag;
            ev.mousePosition =
                new Vector2(-10, -10); // MousePosition is relative to window, negative values are outside of window
            w.SendEvent(ev);
            ev.type          = EventType.MouseDrag;
            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(2.5f, -2.5f)) +
                               new Vector2(0, paletteHeaderHeight); // Drag back inside Palette
            w.SendEvent(ev);
            ev.type = EventType.MouseUp;
            w.SendEvent(ev);

            Assert.NotNull(Selection.activeObject);
            Assert.AreEqual(typeof(GridSelection), Selection.activeObject.GetType());
        }
Exemple #2
0
        public void EraseOnUneditablePalette_SwitchesToPaint()
        {
            var w = CreatePaletteWindow();

            Assert.True(AssetDatabase.CopyAsset(defaultTemporaryPalettePath, temporaryPalettePath),
                        "Unable to create temporary palette");
            w.palette = AssetDatabase.LoadAssetAtPath <GameObject>(temporaryPalettePath);
            var tile = AssetDatabase.LoadAssetAtPath <Tile>(tilePath);

            Assert.GreaterOrEqual(GridPaletteBrushes.brushes.Count, 1);
            GridPaintingState.defaultBrush.Init(new Vector3Int(1, 1, 1));
            GridPaintingState.defaultBrush.SetTile(Vector3Int.zero, tile);
            TilemapEditorTool.SetActiveEditorTool(typeof(EraseTool));
            w.clipboardView.unlocked = false;

            Event ev = new Event();

            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(2.5f, -2.5f)) +
                               new Vector2(0, paletteHeaderHeight);
            ev.type = EventType.MouseMove;
            w.SendEvent(ev);
            ev.type = EventType.MouseDown;
            w.SendEvent(ev);
            ev.type = EventType.MouseUp;
            w.SendEvent(ev);

            Assert.AreEqual(typeof(PaintTool), EditorTools.EditorTools.activeToolType);
        }
Exemple #3
0
 public void TilemapEditorTool_IsSet_IsActive(Type editorToolType, Type otherEditorToolType)
 {
     TilemapEditorTool.SetActiveEditorTool(editorToolType);
     Assert.IsTrue(TilemapEditorTool.IsActive(editorToolType));
     Assert.IsFalse(TilemapEditorTool.IsActive(otherEditorToolType));
     Assert.IsFalse(TilemapEditorTool.IsActive(typeof(ViewModeTool)));
 }
Exemple #4
0
 public void TilemapEditorTool_ToggleEditorTool_SwitchesToRightTool(Type initialToolType, Type startToolType, Type editorToolType, Type resultToolType)
 {
     EditorTools.EditorTools.SetActiveTool(initialToolType);
     EditorTools.EditorTools.SetActiveTool(startToolType);
     TilemapEditorTool.ToggleActiveEditorTool(editorToolType);
     TilemapEditorTool.ToggleActiveEditorTool(editorToolType);
     Assert.AreEqual(resultToolType, EditorTools.EditorTools.activeToolType);
 }
Exemple #5
0
        public void PaintOnPalette_EraseAndCreateNewTileAsset_RemovesTileFromPalette()
        {
            var w = CreatePaletteWindow();

            Assert.True(AssetDatabase.CopyAsset(defaultTemporaryPalettePath, temporaryPalettePath),
                        "Unable to create temporary palette");
            w.palette = AssetDatabase.LoadAssetAtPath <GameObject>(temporaryPalettePath);
            var tile = AssetDatabase.LoadAssetAtPath <Tile>(tilePath);

            Assert.GreaterOrEqual(GridPaletteBrushes.brushes.Count, 1);
            GridPaintingState.defaultBrush.Init(new Vector3Int(1, 1, 1));
            GridPaintingState.defaultBrush.SetTile(Vector3Int.zero, tile);
            w.clipboardView.unlocked = true;
            TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));

            Event ev = new Event();

            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(2.5f, -2.5f)) +
                               new Vector2(0, paletteHeaderHeight);
            ev.type = EventType.MouseMove;
            w.SendEvent(ev);
            ev.type = EventType.MouseDown;
            w.SendEvent(ev);
            ev.type = EventType.MouseUp;
            w.SendEvent(ev);
            w.clipboardView.unlocked = false;

            Grid       grid    = w.clipboardView.paletteInstance.GetComponent <Grid>();
            Vector3    local   = w.clipboardView.ScreenToLocal(ev.mousePosition - new Vector2(0, paletteHeaderHeight));
            Vector3Int pos3    = grid.LocalToCell(local);
            Vector2Int pos     = new Vector2Int(pos3.x, pos3.y);
            Tilemap    tilemap = AssetDatabase.LoadAssetAtPath <GameObject>(temporaryPalettePath)
                                 .GetComponentInChildren <Tilemap>();

            Assert.AreEqual(tile, tilemap.GetTile(new Vector3Int(pos.x, pos.y, 0)));

            w.clipboardView.unlocked = true;
            ev.shift         = true;
            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(2.5f, -2.5f)) +
                               new Vector2(0, paletteHeaderHeight);
            ev.type = EventType.MouseMove;
            w.SendEvent(ev);
            ev.type = EventType.MouseDown;
            w.SendEvent(ev);
            ev.type = EventType.MouseUp;
            w.SendEvent(ev);

            var temporaryTile = ScriptableObject.CreateInstance <Tile>();

            AssetDatabase.CreateAsset(temporaryTile, temporaryTilePath);

            tilemap = AssetDatabase.LoadAssetAtPath <GameObject>(temporaryPalettePath).GetComponentInChildren <Tilemap>();
            Assert.AreEqual(null, tilemap.GetTile(new Vector3Int(pos.x, pos.y, 0)));
        }
Exemple #6
0
        public void PaintDifferentSizedTilesOnAutomaticCellSizePalette_UpdatesPaletteCellSize(Grid.CellLayout layout,
                                                                                              GridLayout.CellSwizzle swizzle, int tileX, int tileY, float expectedCellXSize, float expectedCellYSize)
        {
            var smallTile = AssetDatabase.LoadAssetAtPath <Tile>(tilePath);
            var bigTile   = AssetDatabase.LoadAssetAtPath <Tile>(bigTilePath);

            var newPalette = GridPaletteUtility.CreateNewPalette(path, name, layout, GridPalette.CellSizing.Automatic,
                                                                 Vector3.one, swizzle);
            var tilemap = newPalette.GetComponentInChildren <Tilemap>();

            tilemap.SetTile(new Vector3Int(tileX, tileY, 0), bigTile);

            var w = CreatePaletteWindow();

            w.palette = newPalette;
            w.clipboardView.previewUtility.camera.orthographicSize = 1000;
            w.clipboardView.ClampZoomAndPan();
            Assert.GreaterOrEqual(GridPaletteBrushes.brushes.Count, 1);
            GridPaintingState.defaultBrush.Init(new Vector3Int(1, 1, 1));
            GridPaintingState.defaultBrush.SetTile(Vector3Int.zero, smallTile);
            w.clipboardView.unlocked = true;
            TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));

            Event ev = new Event();

            ev.mousePosition = w.clipboardView.GridToScreen(new Vector2(tileX + 1.5f, tileY + 1.5f)) +
                               new Vector2(0, paletteHeaderHeight);
            ev.type = EventType.MouseMove;
            w.SendEvent(ev);
            ev.type = EventType.MouseDown;
            w.SendEvent(ev);
            ev.type = EventType.MouseUp;
            w.SendEvent(ev);
            w.clipboardView.unlocked = false;

            var grid = w.palette.GetComponent <Grid>();

            Assert.AreEqual(expectedCellXSize, grid.cellSize.x);
            Assert.AreEqual(expectedCellYSize, grid.cellSize.y);
        }
Exemple #7
0
 public void TilemapEditorTool_CanNotSetUnityGlobalEditorTool(Type editorToolType)
 {
     TilemapEditorTool.SetActiveEditorTool(typeof(PaintTool));
     Assert.Throws(typeof(ArgumentException), () => { TilemapEditorTool.SetActiveEditorTool(editorToolType); },
                   "The tool to set must be valid and derive from TilemapEditorTool");
 }
Exemple #8
0
 public void TilemapEditorTool_CanSetEditorTool(Type editorToolType)
 {
     TilemapEditorTool.SetActiveEditorTool(editorToolType);
     Assert.AreEqual(editorToolType, EditorTools.EditorTools.activeToolType);
 }