114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
|
using Thousandto.Core.Asset;
|
|||
|
using Thousandto.Core.Base;
|
|||
|
using Thousandto.Launcher.ExternalLibs;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.Package
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 测试bundle读取,方便确认打出来的bundle是否有效
|
|||
|
/// </summary>
|
|||
|
public class CheckSceneLightmap
|
|||
|
{
|
|||
|
private const string SCENE_ROOT = "Assets/GameAssets/RawResources/scene";
|
|||
|
|
|||
|
|
|||
|
public static void StartCheck()
|
|||
|
{
|
|||
|
EditorUtility.DisplayProgressBar("检查场景Lightingmap", "", 0);
|
|||
|
var sceneDirs = GetSceneDirs();
|
|||
|
for (int i = 0; i < sceneDirs.Length; ++i)
|
|||
|
{
|
|||
|
EditorUtility.DisplayProgressBar("检查场景Lightingmap", sceneDirs[i], i / (float)sceneDirs.Length);
|
|||
|
var lightingDataAssetArray = GetLighingDataAsset(sceneDirs[i]);
|
|||
|
for (int j = 0; j < lightingDataAssetArray.Length; ++j)
|
|||
|
{
|
|||
|
var lightingAssetLen = GetFileSize(lightingDataAssetArray[j]);
|
|||
|
UnityEngine.Debug.Log("LightingDataAsset size: " + SizeToKbOrMb(lightingAssetLen) + " ---> " +
|
|||
|
lightingDataAssetArray[j]);
|
|||
|
}
|
|||
|
|
|||
|
var lightingTexArra = GetLightingTexture(sceneDirs[i]);
|
|||
|
for (int j = 0; j < lightingTexArra.Length; ++j)
|
|||
|
{
|
|||
|
EditorUtility.DisplayProgressBar("检查场景Lightingmap", "优化lightingmap贴图" + sceneDirs[i],
|
|||
|
i / (float)sceneDirs.Length);
|
|||
|
CompressTexture(lightingTexArra[j]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
EditorUtility.ClearProgressBar();
|
|||
|
}
|
|||
|
|
|||
|
private static string[] GetSceneDirs()
|
|||
|
{
|
|||
|
var sceneDirs = Directory.GetDirectories(SCENE_ROOT);
|
|||
|
return sceneDirs;
|
|||
|
}
|
|||
|
|
|||
|
private static string[] GetLighingDataAsset(string sceneDir, string lightingDir = "lightmap")
|
|||
|
{
|
|||
|
string lightMapPath = sceneDir + "/" + lightingDir;
|
|||
|
if (!Directory.Exists(lightMapPath))
|
|||
|
return new string[0];
|
|||
|
|
|||
|
var assetArray = Directory.GetFiles(lightMapPath, "*.asset");
|
|||
|
return assetArray;
|
|||
|
}
|
|||
|
|
|||
|
private static string[] GetLightingTexture(string sceneDir, string lightingDir = "lightmap")
|
|||
|
{
|
|||
|
//string lightMapPath = sceneDir + "/" + lightingDir;
|
|||
|
//if (!Directory.Exists(lightMapPath))
|
|||
|
// return new string[0];
|
|||
|
|
|||
|
var texArray = Directory.GetFiles(sceneDir, "*.exr", SearchOption.AllDirectories);
|
|||
|
return texArray;
|
|||
|
}
|
|||
|
|
|||
|
private static long GetFileSize(string file)
|
|||
|
{
|
|||
|
long size = -1;
|
|||
|
if (File.Exists(file))
|
|||
|
{
|
|||
|
FileInfo info = new FileInfo(file);
|
|||
|
size = info.Length;
|
|||
|
}
|
|||
|
|
|||
|
return size;
|
|||
|
}
|
|||
|
|
|||
|
private static string SizeToKbOrMb(float size)
|
|||
|
{
|
|||
|
float kb = size / 1024;
|
|||
|
float mb = kb / 1024;
|
|||
|
if (mb > 0)
|
|||
|
return string.Format("{0:#0.00}mb ", mb);
|
|||
|
|
|||
|
return string.Format("{0:#0.00}kb}", kb);
|
|||
|
}
|
|||
|
|
|||
|
private static void CompressTexture(string file)
|
|||
|
{
|
|||
|
TextureImporter importer = TextureImporter.GetAtPath(file) as TextureImporter;
|
|||
|
importer.textureCompression = TextureImporterCompression.Compressed;
|
|||
|
TextureImporterSettings ts = new TextureImporterSettings();
|
|||
|
importer.ReadTextureSettings(ts);
|
|||
|
importer.SetTextureSettings(ts);
|
|||
|
|
|||
|
AssetDatabase.ImportAsset(file);
|
|||
|
AssetDatabase.SaveAssets();
|
|||
|
AssetDatabase.Refresh();
|
|||
|
}
|
|||
|
|
|||
|
[MenuItem("Test/CompressTexture")]
|
|||
|
private static void Test()
|
|||
|
{
|
|||
|
var path = AssetDatabase.GetAssetPath(Selection.objects[0]);
|
|||
|
CompressTexture(path);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|