mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
87 lines
3.2 KiB
C#
87 lines
3.2 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class AutoSetTextureUISprite : AssetPostprocessor
|
|
{
|
|
void OnPreprocessTexture()
|
|
{
|
|
//自动设置类型
|
|
if (assetPath.Contains("FGui"))
|
|
{
|
|
//fgui的图片资源需要设置为Sprite和不生成Mip Maps
|
|
TextureImporter textureImporter = (TextureImporter)assetImporter;
|
|
textureImporter.textureType = TextureImporterType.Default;
|
|
textureImporter.textureShape = TextureImporterShape.Texture2D;
|
|
textureImporter.mipmapEnabled = false;
|
|
textureImporter.filterMode = FilterMode.Bilinear;
|
|
}
|
|
}
|
|
|
|
// private void OnPostprocessMaterial(Material material)
|
|
// {
|
|
// if (assetPath.Contains("FairyRes"))
|
|
// {
|
|
// material.SetInt("_StraightAlphaInput", 1);
|
|
// AssetDatabase.SaveAssets();
|
|
// }
|
|
// }
|
|
|
|
// [MenuItem("Tools/ConvertGammaToLinearTex")]
|
|
public static void ConvertGammaToLinearTex()
|
|
{
|
|
var assetGUIDs = Selection.assetGUIDs;
|
|
foreach (var assetGUID in assetGUIDs)
|
|
{
|
|
var assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);
|
|
Debug.Log(assetPath);
|
|
if (!assetPath.Contains(".png")) continue;
|
|
|
|
Texture2D srcTex = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
if (srcTex != null)
|
|
{
|
|
Texture2D temp = new Texture2D(srcTex.width, srcTex.height, TextureFormat.RGBA32, true);
|
|
Color[] pixels = srcTex.GetPixels();
|
|
for (int j = 0; j < pixels.Length; j++)
|
|
{
|
|
Color pixel = pixels[j];
|
|
pixel.r = Mathf.Pow(pixel.r, 2.2f);
|
|
pixel.g = Mathf.Pow(pixel.g, 2.2f);
|
|
pixel.b = Mathf.Pow(pixel.b, 2.2f);
|
|
pixels[j] = pixel;
|
|
}
|
|
|
|
temp.SetPixels(pixels);
|
|
temp.Apply();
|
|
var bytes = temp.EncodeToPNG();
|
|
File.WriteAllBytes(assetPath, bytes);
|
|
}
|
|
}
|
|
|
|
return;
|
|
// List<string> selectedAsset = FindSelectionObject("*. png");
|
|
// int count = selectedAsset.Count;
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// Texture2D srcTex = AssetDatabase.LoadAssetAtPath<Texture2D>(selectedAsset[i]);
|
|
// if (srcTex != null)
|
|
// {
|
|
// Texture2D temp = new Texture2D(srcTex.width, srcTex.height, TextureFormat.RGBA32, true);
|
|
// Color[] pixels = srcTex.GetPixels();
|
|
// for (int j = 0; j < pixels.Length; j++)
|
|
// {
|
|
// Color pixel = pixels[i];
|
|
// pixel.r = Mathf.Pow(pixel.r, 2.2f);
|
|
// pixel.g = Mathf.Pow(pixel.g, 2.2f);
|
|
// pixel.b = Mathf.Pow(pixel.b, 2.2f);
|
|
// pixels[i] = pixel;
|
|
// }
|
|
//
|
|
// temp.SetPixels(pixels);
|
|
// temp.Apply();
|
|
// var bytes = temp.EncodeToPNG();
|
|
// File.WriteAllBytes(selectedAsset[i], bytes);
|
|
// }
|
|
// }
|
|
}
|
|
} |