Last active
September 4, 2018 07:03
-
-
Save GeorgiyRyaposov/00659d4ae53e73540da7d5daa5c85449 to your computer and use it in GitHub Desktop.
Reimport png with settings
This file contains hidden or 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
[MenuItem("Custom tools/import icons")] | |
public static void ImportIcons() | |
{ | |
var rootPath = Path.Combine(Application.dataPath, "Resources/text_icons/"); | |
var icons = Directory.GetFiles(rootPath, "*.png", SearchOption.AllDirectories); | |
if (icons.Length == 0) | |
{ | |
UnityEngine.Debug.Log("Failed to find icons"); | |
return; | |
} | |
var assets = icons[0].IndexOf("Assets"); | |
for (int i = 0; i < icons.Length; i++) | |
{ | |
var path = icons[i].Substring(assets); | |
var icon = AssetDatabase.LoadAssetAtPath<Texture2D>(path); | |
if (icon == null) | |
{ | |
continue; | |
} | |
var importer = TextureImporter.GetAtPath(AssetDatabase.GetAssetPath(icon)) as TextureImporter; | |
var ppu = 100; | |
var tag = "HD"; | |
if (icon.name.EndsWith("-md", System.StringComparison.OrdinalIgnoreCase)) | |
{ | |
ppu = 75; | |
tag = "MD"; | |
} | |
else if (icon.name.EndsWith("-sd", System.StringComparison.OrdinalIgnoreCase)) | |
{ | |
ppu = 50; | |
tag = "SD"; | |
} | |
importer.spritePixelsPerUnit = ppu; | |
importer.spritePackingTag = tag; | |
importer.mipmapEnabled = false; | |
importer.alphaIsTransparency = true; | |
importer.wrapMode = TextureWrapMode.Clamp; | |
importer.SaveAndReimport(); | |
} | |
AssetDatabase.Refresh(); | |
UnityEngine.Debug.Log("Done"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment