public void SplatmapsAreCopiedOnImport() { var terrainData = new TerrainData(); terrainData.alphamapResolution = 16; terrainData.terrainLayers = new [] { new TerrainLayer(), new TerrainLayer() }; float[,,] map = new float[terrainData.alphamapWidth, terrainData.alphamapHeight, 2]; for (int y = 0; y < terrainData.alphamapHeight; y++) { for (int x = 0; x < terrainData.alphamapWidth; x++) { map[x, y, 0] = 1; } } map[0, 0, 0] = 0; map[0, 0, 1] = 1; terrainData.SetAlphamaps(0, 0, map); // create terrain var TerrainGO = Terrain.CreateTerrainGameObject(terrainData); // import splatmaps into terrain toolbox var terrainUtilities = new TerrainToolboxUtilities(); Selection.activeGameObject = TerrainGO; terrainUtilities.ImportSplatmapsFromTerrain(); // perform flip operation (should modify data in the utilities local texture copy) terrainUtilities.FlipSplatmap(); // confirm that the value in the terrain splatmap hasn't changed terrainData.SyncTexture(TerrainData.AlphamapTextureName); var newMap = terrainData.GetAlphamaps(0, 0, terrainData.alphamapResolution, terrainData.alphamapResolution); Assert.That(newMap[0, 0, 0], Is.EqualTo(0)); Assert.That(newMap[0, 0, 1], Is.EqualTo(1)); }
public void TerrainToolboxUtilities_WhenApplySplatmaps_DoesNotModifyColorData() { //Setup terrain layer data TerrainToolboxWindow toolboxWindow = EditorWindow.GetWindow <TerrainToolboxWindow>(); TerrainLayer layer = new TerrainLayer(); layer.diffuseTexture = CreateGradientTexture(); byte[] texData = layer.diffuseTexture.GetRawTextureData(); m_TerrainComponent.terrainData.terrainLayers = new TerrainLayer[] { layer }; //Reproduce steps Selection.activeObject = m_TerrainGO; TerrainToolboxUtilities utilities = toolboxWindow.m_TerrainUtilitiesMode; utilities.ImportSplatmapsFromTerrain(); //Manually set splatmap list since the window's OnGUI method isn't called which normally sets the splatmap list utilities.m_SplatmapList = new UnityEditorInternal.ReorderableList(utilities.m_Splatmaps, typeof(Texture2D), true, false, true, true); utilities.ExportSplatmapsToTerrain(true); Assert.AreEqual(texData, layer.diffuseTexture.GetRawTextureData()); }