Last active
January 23, 2018 03:11
-
-
Save nir1082/b6ef65899105823ff72e68c2882711e0 to your computer and use it in GitHub Desktop.
[Unity] Terrainのアルファマップをpngファイルに出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using UnityEngine; | |
using UnityEditor; | |
public class TerrainAlphamapToPNG : Editor | |
{ | |
[MenuItem("Assets/Create/TerrainPNG")] | |
static void Create() | |
{ | |
TerrainData terrainData = (TerrainData)Selection.activeObject; | |
Texture2D[] textures = terrainData.alphamapTextures; | |
string directory = "TerrainAlphaMaps/" + terrainData.name; | |
if (!Directory.Exists(directory)) { | |
Directory.CreateDirectory(directory); | |
} | |
for (int i = 0; i < textures.Length; i++) { | |
Texture2D texture = textures[i]; | |
byte[] texData = texture.EncodeToPNG(); | |
string filePath = directory + "/" + texture.name + ".png"; | |
File.WriteAllBytes(filePath, texData); | |
} | |
EditorUtility.OpenWithDefaultApp(directory); | |
} | |
[MenuItem("Assets/Create/TerrainPNG", true)] | |
static bool IsTerrainData() | |
{ | |
return Selection.activeObject != null && Selection.activeObject is TerrainData; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment