using UnityEngine; using UnityEditor; using System.IO; public class NeptuneTextureGenerator : EditorWindow { public Texture2D sourceTexture; public string outputFolder = "Assets/Textures/Neptune"; [MenuItem("Tools/Neptune Texture Generator")] public static void ShowWindow() { GetWindow("Neptune Texture Generator"); } void OnGUI() { GUILayout.Label("Генератор текстур Нептуна", EditorStyles.boldLabel); sourceTexture = (Texture2D)EditorGUILayout.ObjectField("Текстура Нептуна", sourceTexture, typeof(Texture2D), false); outputFolder = EditorGUILayout.TextField("Папка збереження", outputFolder); EditorGUILayout.Space(10); if (GUILayout.Button("Згенерувати -- Тропосфера", GUILayout.Height(35))) { if (sourceTexture == null) { EditorUtility.DisplayDialog("Помилка", "Перетягни текстуру Нептуна!", "OK"); return; } GenerateAllTextures(); } EditorGUILayout.Space(5); if (GUILayout.Button("Згенерувати -- Текстура смерті", GUILayout.Height(35))) { if (sourceTexture == null) { EditorUtility.DisplayDialog("Помилка", "Перетягни текстуру Нептуна!", "OK"); return; } GenerateDeadTexture(); } } Texture2D GenerateTropoTexture(Texture2D source, float alive) { int width = source.width; int height = source.height; Texture2D result = new Texture2D(width, height, TextureFormat.RGB24, false); Color[] pixels = source.GetPixels(); Color[] output = new Color[pixels.Length]; Color stage70 = new Color(0.35f, 0.45f, 0.75f); Color stage50 = new Color(0.45f, 0.42f, 0.65f); Color stage30 = new Color(0.4f, 0.38f, 0.5f); Color stage0 = new Color(0.22f, 0.2f, 0.28f); for (int p = 0; p < pixels.Length; p++) { Color col = pixels[p]; Color result_col = col; if (alive <= 1f && alive > 0.7f) { result_col = col; } else if (alive <= 0.7f && alive > 0.5f) { float t = Mathf.Clamp01((0.7f - alive) / 0.2f); result_col = Color.Lerp(col, stage70, t * 0.8f); } else if (alive <= 0.5f && alive > 0.3f) { float t = Mathf.Clamp01((0.5f - alive) / 0.2f); result_col = Color.Lerp(stage70, stage50, t); } else if (alive <= 0.3f && alive > 0f) { float t = Mathf.Clamp01((0.3f - alive) / 0.3f); result_col = Color.Lerp(stage50, stage30, t); } else if (alive <= 0f) { result_col = stage0; } output[p] = result_col; } result.SetPixels(output); result.Apply(); return result; } void GenerateDeadTexture() { if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder); MakeTextureReadable(sourceTexture); int width = sourceTexture.width; int height = sourceTexture.height; Texture2D result = new Texture2D(width, height, TextureFormat.RGB24, false); Color[] pixels = sourceTexture.GetPixels(); Color[] output = new Color[pixels.Length]; Color deadColor = new Color(0.22f, 0.2f, 0.28f); Color darkColor = new Color(0.1f, 0.09f, 0.14f); for (int p = 0; p < pixels.Length; p++) { float brightness = (pixels[p].r + pixels[p].g + pixels[p].b) / 3f; output[p] = Color.Lerp(darkColor, deadColor, brightness); } result.SetPixels(output); result.Apply(); SaveTexture(result, outputFolder + "/Dead.png"); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("Готово!", "Текстура смерті збережена!", "OK"); } void GenerateAllTextures() { if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder); MakeTextureReadable(sourceTexture); float[] levels = { 1.0f, 0.7f, 0.5f, 0.3f, 0.0f }; string[] names = { "100", "70", "50", "30", "0" }; for (int i = 0; i < levels.Length; i++) { EditorUtility.DisplayProgressBar("Генерація", "Tropo_" + names[i], (float)i / levels.Length); Texture2D result = GenerateTropoTexture(sourceTexture, levels[i]); SaveTexture(result, outputFolder + "/Tropo_" + names[i] + ".png"); } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("Готово!", "Текстури збережено в " + outputFolder, "OK"); } void SaveTexture(Texture2D tex, string path) { byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(path, bytes); } void MakeTextureReadable(Texture2D tex) { string path = AssetDatabase.GetAssetPath(tex); TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer != null && !importer.isReadable) { importer.isReadable = true; importer.SaveAndReimport(); } } }