public void Export() { var paths = StandaloneFileBrowser.SaveFilePanel("Export types", DefaultPath, "types", extensions); if (paths == null || string.IsNullOrEmpty(paths)) { return; } Texture2D exportTexture = new Texture2D(TerrainTypeData2D.GetLength(0), TerrainTypeData2D.GetLength(1), TextureFormat.RGB24, false); Color32[] pixels = new Color32[exportTexture.width * exportTexture.height]; for (int x = 0; x < exportTexture.width; x++) { for (int y = 0; y < exportTexture.width; y++) { int PixelId = x + y * exportTexture.width; pixels[PixelId] = new Color32(TerrainTypeData2D[x, y], 0, 0, 255); } } exportTexture.SetPixels32(pixels); exportTexture.Apply(); byte[] data = exportTexture.EncodeToPNG(); File.WriteAllBytes(paths, data); EnvPaths.SetLastPath(ExportPathKey, Path.GetDirectoryName(paths)); GenericInfoPopup.ShowInfo("Types export success!\n" + Path.GetFileName(paths)); }
public void Import() { var paths = StandaloneFileBrowser.OpenFilePanel("Import types", DefaultPath, extensions, false); if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0])) { return; } byte[] data = File.ReadAllBytes(paths[0]); Texture2D importTexture = new Texture2D(2, 2); importTexture.LoadImage(data, false); if (importTexture.width != TerrainTypeData2D.GetLength(0) || importTexture.height != TerrainTypeData2D.GetLength(1)) { Debug.LogError("Incorrect dimensions! " + importTexture.width + "x" + importTexture.height + " / " + TerrainTypeData2D.GetLength(0) + "x" + TerrainTypeData2D.GetLength(1)); } Undo.RegisterUndo(new UndoHistory.HistoryTerrainType()); Color32[] pixels = importTexture.GetPixels32(); for (int x = 0; x < importTexture.width; x++) { for (int y = 0; y < importTexture.width; y++) { int PixelId = x + y * importTexture.width; TerrainTypeData2D[x, y] = pixels[PixelId].r; //pixels[PixelId] = new Color32(TerrainTypeData2D[x, y], 0, 0, 255); } } TerrainTypeTexture = null; ApplyTerrainTypeChanges(); ScmapEditor.Current.TerrainMaterial.SetTexture("_TerrainTypeAlbedo", TerrainTypeTexture); }