using UnityEngine; using UnityEditor; using System.IO; public class JupiterTextureGenerator : EditorWindow { public Texture2D sourceTexture; public string outputFolder = "Assets/Textures/Jupiter"; [MenuItem("Tools/Jupiter Texture Generator")] public static void ShowWindow() { GetWindow("Jupiter 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("Tropo", GenerateTropoTexture); } 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 fadedOrange = new Color(0.85f, 0.65f, 0.35f); Color paleYellow = new Color(0.9f, 0.82f, 0.6f); Color grayDead = new Color(0.45f, 0.38f, 0.3f); Color darkDead = new Color(0.25f, 0.2f, 0.15f); for (int p = 0; p < pixels.Length; p++) { Color col = pixels[p]; Color result_col = col; float isBelt = Mathf.Clamp01((col.r - col.g * 0.5f - col.b * 0.3f) * 2f); float brightness = (col.r + col.g + col.b) / 3f; if (alive < 0.7f) { float t = Mathf.Clamp01((0.7f - alive) / 0.2f); result_col = Color.Lerp(result_col, fadedOrange, isBelt * t * 0.4f); } if (alive < 0.5f) { float t = Mathf.Clamp01((0.5f - alive) / 0.2f); result_col = Color.Lerp(result_col, paleYellow, t * 0.5f); } if (alive < 0.3f) { float t = Mathf.Clamp01((0.3f - alive) / 0.2f); result_col = Color.Lerp(result_col, grayDead, t * 0.7f); } if (alive < 0.1f) { float t = Mathf.Clamp01((0.1f - alive) / 0.1f); result_col = Color.Lerp(result_col, darkDead, t); } 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 deadBrown = new Color(0.3f, 0.22f, 0.15f); Color darkGray = new Color(0.18f, 0.15f, 0.12f); for (int p = 0; p < pixels.Length; p++) { Color col = pixels[p]; float brightness = (col.r + col.g + col.b) / 3f; Color result_col = Color.Lerp(darkGray, deadBrown, brightness); output[p] = result_col; } result.SetPixels(output); result.Apply(); SaveTexture(result, outputFolder + "/Dead.png"); AssetDatabase.Refresh(); EditorUtility.DisplayDialog("Готово!", "Текстура смерті збережена в " + outputFolder, "OK"); } void GenerateAllTextures(string prefix, System.Func generator) { 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("Генерація", prefix + "_" + names[i], (float)i / levels.Length); Texture2D result = generator(sourceTexture, levels[i]); SaveTexture(result, outputFolder + "/" + prefix + "_" + 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(); } } }