211 lines
7.3 KiB
C#
211 lines
7.3 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.IO;
|
|
|
|
public class SaturnTextureGenerator : EditorWindow
|
|
{
|
|
public Texture2D sourceTexture;
|
|
public Texture2D ringsTexture;
|
|
public string outputFolder = "Assets/Textures/Saturn";
|
|
|
|
[MenuItem("Tools/Saturn Texture Generator")]
|
|
public static void ShowWindow()
|
|
{
|
|
GetWindow<SaturnTextureGenerator>("Saturn Texture Generator");
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.Label("Ãåíåðàòîð òåêñòóð Ñàòóðíà", EditorStyles.boldLabel);
|
|
sourceTexture = (Texture2D)EditorGUILayout.ObjectField("Òåêñòóðà Ñàòóðíà", sourceTexture, typeof(Texture2D), false);
|
|
ringsTexture = (Texture2D)EditorGUILayout.ObjectField("Òåêñòóðà ê³ëåöü", ringsTexture, 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", sourceTexture, GenerateTropoTexture);
|
|
}
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
if (GUILayout.Button("Çãåíåðóâàòè -- ʳëüöÿ", GUILayout.Height(35)))
|
|
{
|
|
if (ringsTexture == null) { EditorUtility.DisplayDialog("Ïîìèëêà", "Ïåðåòÿãíè òåêñòóðó ê³ëåöü!", "OK"); return; }
|
|
GenerateAllTextures("Rings", ringsTexture, GenerateRingsTexture);
|
|
}
|
|
|
|
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 fadedBeige = new Color(0.85f, 0.78f, 0.6f);
|
|
Color paleYellow = new Color(0.9f, 0.85f, 0.7f);
|
|
Color grayDead = new Color(0.55f, 0.5f, 0.42f);
|
|
Color darkDead = new Color(0.3f, 0.27f, 0.22f);
|
|
|
|
for (int p = 0; p < pixels.Length; p++)
|
|
{
|
|
Color col = pixels[p];
|
|
Color result_col = col;
|
|
|
|
if (alive < 0.7f)
|
|
{
|
|
float t = Mathf.Clamp01((0.7f - alive) / 0.2f);
|
|
result_col = Color.Lerp(result_col, fadedBeige, 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;
|
|
}
|
|
|
|
Texture2D GenerateRingsTexture(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 fadedRing = new Color(0.7f, 0.65f, 0.5f);
|
|
Color paleRing = new Color(0.6f, 0.55f, 0.42f);
|
|
Color grayRing = new Color(0.4f, 0.37f, 0.3f);
|
|
Color darkRing = new Color(0.2f, 0.18f, 0.14f);
|
|
|
|
for (int p = 0; p < pixels.Length; p++)
|
|
{
|
|
Color col = pixels[p];
|
|
Color result_col = col;
|
|
|
|
if (alive < 0.7f)
|
|
{
|
|
float t = Mathf.Clamp01((0.7f - alive) / 0.2f);
|
|
result_col = Color.Lerp(result_col, fadedRing, t * 0.5f);
|
|
}
|
|
if (alive < 0.5f)
|
|
{
|
|
float t = Mathf.Clamp01((0.5f - alive) / 0.2f);
|
|
result_col = Color.Lerp(result_col, paleRing, t * 0.6f);
|
|
}
|
|
if (alive < 0.3f)
|
|
{
|
|
float t = Mathf.Clamp01((0.3f - alive) / 0.2f);
|
|
result_col = Color.Lerp(result_col, grayRing, t * 0.8f);
|
|
}
|
|
if (alive < 0.1f)
|
|
{
|
|
float t = Mathf.Clamp01((0.1f - alive) / 0.1f);
|
|
result_col = Color.Lerp(result_col, darkRing, 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 deadBeige = new Color(0.35f, 0.3f, 0.22f);
|
|
Color darkGray = new Color(0.2f, 0.18f, 0.14f);
|
|
|
|
for (int p = 0; p < pixels.Length; p++)
|
|
{
|
|
Color col = pixels[p];
|
|
float brightness = (col.r + col.g + col.b) / 3f;
|
|
output[p] = Color.Lerp(darkGray, deadBeige, brightness);
|
|
}
|
|
|
|
result.SetPixels(output);
|
|
result.Apply();
|
|
|
|
SaveTexture(result, outputFolder + "/Dead.png");
|
|
AssetDatabase.Refresh();
|
|
EditorUtility.DisplayDialog("Ãîòîâî!", "Òåêñòóðà ñìåðò³ çáåðåæåíà!", "OK");
|
|
}
|
|
|
|
void GenerateAllTextures(string prefix, Texture2D source, System.Func<Texture2D, float, Texture2D> generator)
|
|
{
|
|
if (!Directory.Exists(outputFolder))
|
|
Directory.CreateDirectory(outputFolder);
|
|
|
|
MakeTextureReadable(source);
|
|
|
|
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(source, 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();
|
|
}
|
|
}
|
|
} |