public void SetUp() { m_TilemapGO1 = CreateTilemapGameObjectWithName("1"); m_TilemapGO2 = CreateTilemapGameObjectWithName("2"); var paletteFullPath1 = GetPaletteFullPath(m_PaletteName1); if (!AssetDatabase.GetAllAssetPaths().Contains(paletteFullPath1)) { m_PaletteGO1 = GridPaletteUtility.CreateNewPalette(m_PaletteAssetPath, m_PaletteName1, GridLayout.CellLayout.Rectangle, GridPalette.CellSizing.Automatic, Vector3.one, GridLayout.CellSwizzle.XYZ); m_PaletteGO2 = GridPaletteUtility.CreateNewPalette(m_PaletteAssetPath, m_PaletteName2, GridLayout.CellLayout.Rectangle, GridPalette.CellSizing.Automatic, Vector3.one, GridLayout.CellSwizzle.XYZ); } }
public void CreatePalette_ReturnsValidPalettesWithGridAndChildTilemap(Grid.CellLayout layout, GridLayout.CellSwizzle swizzle) { int paletteCount = GridPalettes.palettes.Count; GameObject palette1 = GridPaletteUtility.CreateNewPalette(path, name, layout, GridPalette.CellSizing.Automatic, Vector3.one, swizzle); GameObject palette2 = GridPaletteUtility.CreateNewPalette(path2, name2, layout, GridPalette.CellSizing.Automatic, Vector3.one, swizzle); GridPalettes.CleanCache(); Assert.AreEqual(paletteCount + 2, GridPalettes.palettes.Count); Assert.NotNull(palette1.GetComponent <Grid>()); Assert.NotNull(palette1.GetComponentInChildren <Tilemap>()); Assert.NotNull(palette2.GetComponent <Grid>()); Assert.NotNull(palette2.GetComponentInChildren <Tilemap>()); }
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); }
public void PalettePrefabIsUpdated_DoesNotCreateAnInstanceInScene(Grid.CellLayout layout, GridLayout.CellSwizzle swizzle) { var palettePrefab = GridPaletteUtility.CreateNewPalette(path, name, layout, GridPalette.CellSizing.Automatic, Vector3.one, swizzle); var w = CreatePaletteWindow(); w.palette = palettePrefab; Object[] objs = GameObject.FindObjectsOfType <Grid>(); Assert.AreEqual(0, objs.Length, "There should be 0 Grids in this test as Palette instances have HideAndDontSave hide flags"); var sceneGameObject = (GameObject)PrefabUtility.InstantiatePrefab(palettePrefab); var grid = sceneGameObject.GetComponent <Grid>(); Object[] objsAfterInstantiatePrefab = GameObject.FindObjectsOfType <Grid>(); Assert.AreEqual(1, objsAfterInstantiatePrefab.Length, "There should be 1 Grid in this test which is the instantiated prefab."); Assert.AreEqual(objsAfterInstantiatePrefab[0], grid, "The Grid found should be the Grid instantiated from the prefab."); grid.cellGap = new Vector3(2.0f, 2.0f, 0.0f); PrefabUtility.SaveAsPrefabAssetAndConnect(sceneGameObject, AssetDatabase.GetAssetPath(palettePrefab), InteractionMode.AutomatedAction); Object[] objsAfterReplacePrefab = GameObject.FindObjectsOfType <Grid>(); Assert.AreEqual(1, objsAfterReplacePrefab.Length, "There should be 1 Grid in this test which is the instantiated prefab after replacing the prefab."); Assert.AreEqual(objsAfterReplacePrefab[0], grid, "The Grid found should be the Grid instantiated from the prefab after replacing the prefab."); // Clean up Object.DestroyImmediate(sceneGameObject); }