仮画像を作成したいときなど、仮画像と分かるようになにかしら対応をしたい
そんなときに利用できるツールを作成しました
使い方
変換したいテクスチャを Project Window で右クリックして
Texture/Nage
を選択すると変換できます
変更例
コード
using UnityEditor;using UnityEngine;public class TextureNegaConvertTool{[MenuItem("Assets/Texture/Nega")]private static void TextureConvertNega(){var guids = Selection.assetGUIDs;if (guids.Length <= 0)return;foreach (var guid in guids){var path = AssetDatabase.GUIDToAssetPath(guid);var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path);if (texture != null)ToNega(texture);}}private static void ToNega(Texture2D src){var texture = new Texture2D(src.width, src.height, src.format, src.mipmapCount == -1);var path = AssetDatabase.GetAssetPath(src);var importer = AssetImporter.GetAtPath(path) as TextureImporter;var isChange = !importer.isReadable;if (isChange){importer.isReadable = true;importer.SaveAndReimport();AssetDatabase.Refresh();}for (var x = 0; x < src.width; x++){for (var y = 0; y < src.height; y++){var color = src.GetPixel(x, y);for (var i = 0; i < 3; i++)color[i] = 1 - color[i];texture.SetPixel(x, y, color);}}texture.Apply();System.IO.File.WriteAllBytes(path.Replace('/', System.IO.Path.DirectorySeparatorChar), texture.EncodeToPNG());AssetDatabase.Refresh();if (isChange){var importer2 = AssetImporter.GetAtPath(path) as TextureImporter;importer2.isReadable = false;importer2.SaveAndReimport();}}}