81 lines
3.0 KiB
C#
81 lines
3.0 KiB
C#
using System.Linq;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
namespace AssetsImport
|
||
{
|
||
public class AssetPostProcess : AssetPostprocessor
|
||
{
|
||
private void OnPostprocessAudio(AudioClip clip)
|
||
{
|
||
if (!assetImporter.importSettingsMissing) return;
|
||
foreach (var item in ImporterAudio.AudioDetailMap.Where(item => assetPath.Contains(item.Key)))
|
||
{
|
||
Debug.Log("[AudioPostProcess]音频后处理!" + assetPath);
|
||
var importer = (AudioImporter)assetImporter;
|
||
var audioDetail = item.Value;
|
||
ImporterAudio.DealAudioImporter(assetPath, clip, importer, audioDetail.ForceMono, audioDetail.Sensitive,
|
||
audioDetail.CompressSampleRate);
|
||
Debug.Log("所有音频设置完成");
|
||
break;
|
||
}
|
||
}
|
||
|
||
private static void SetLayerToDefault(GameObject go, int layer)
|
||
{
|
||
if (go.layer == layer)
|
||
{
|
||
Debug.Log($"{go.name} 使用了未定义的Layer,设置默认Layer.");
|
||
go.layer = 0;
|
||
}
|
||
|
||
foreach (Transform child in go.transform)
|
||
{
|
||
SetLayerToDefault(child.gameObject, layer);
|
||
}
|
||
}
|
||
|
||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||
{
|
||
foreach (var assetPath in importedAssets)
|
||
{
|
||
// 检查导入的资源是否为Prefab
|
||
if (assetPath.EndsWith(".prefab"))
|
||
{
|
||
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
||
if (prefab == null) continue;
|
||
for (var i = 0; i < 32; i++)
|
||
{
|
||
var layer = LayerMask.LayerToName(i);
|
||
// 如果Layer被定义(非空字符串),继续下一个
|
||
if (!string.IsNullOrEmpty(layer))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
SetLayerToDefault(prefab, i);
|
||
}
|
||
}
|
||
|
||
if (assetPath.EndsWith(".max"))
|
||
{
|
||
EditorUtility.DisplayDialog("警告", assetPath + "为.max文件," + "请不要导入.max文件", "确定(删除)");
|
||
AssetDatabase.DeleteAsset(assetPath);
|
||
AssetDatabase.Refresh();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void OnPreprocessAsset()
|
||
{
|
||
if (!assetImporter.importSettingsMissing)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (!assetPath.EndsWith(".psd")) return;
|
||
EditorUtility.DisplayDialog("警告", assetPath + "为.psd文件," + "请不要使用.psd格式的图片", "确定");
|
||
Debug.LogWarning(assetPath + "为.psd文件," + "请不要使用.psd格式的图片");
|
||
}
|
||
}
|
||
} |