71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
public class SpriteProcessor : EditorWindow
|
|||
|
{
|
|||
|
[MenuItem("Tools/<2F><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>")]
|
|||
|
public static void FixMultipleMaterialSprites()
|
|||
|
{
|
|||
|
string[] guids = AssetDatabase.FindAssets("t:sprite");
|
|||
|
List<Sprite> spritesToFix = new List<Sprite>();
|
|||
|
|
|||
|
foreach (string guid in guids)
|
|||
|
{
|
|||
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|||
|
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (IsUsingMultipleMaterials(sprite))
|
|||
|
{
|
|||
|
spritesToFix.Add(sprite);
|
|||
|
Debug.Log("Found sprite with multiple materials: " + path);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// <20><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Sprite
|
|||
|
foreach (var sprite in spritesToFix)
|
|||
|
{
|
|||
|
FixSprite(sprite);
|
|||
|
}
|
|||
|
|
|||
|
AssetDatabase.SaveAssets();
|
|||
|
AssetDatabase.Refresh();
|
|||
|
EditorUtility.DisplayDialog("<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>顣", "OK");
|
|||
|
}
|
|||
|
|
|||
|
private static bool IsUsingMultipleMaterials(Sprite sprite)
|
|||
|
{
|
|||
|
if (sprite == null) return false;
|
|||
|
|
|||
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|||
|
var textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(sprite)) as TextureImporter;
|
|||
|
|
|||
|
return textureImporter != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple;
|
|||
|
}
|
|||
|
|
|||
|
private static void FixSprite(Sprite sprite)
|
|||
|
{
|
|||
|
// <20><>ȡSprite<74><65>·<EFBFBD><C2B7>
|
|||
|
string path = AssetDatabase.GetAssetPath(sprite);
|
|||
|
var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
|
|||
|
|
|||
|
if (textureImporter != null)
|
|||
|
{
|
|||
|
// <20><><EFBFBD>浱ǰ<E6B5B1>и<EFBFBD><D0B8><EFBFBD>Ϣ
|
|||
|
SpriteMetaData[] originalMetaData = textureImporter.spritesheet;
|
|||
|
|
|||
|
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Sprite<74><65><EFBFBD><EFBFBD>
|
|||
|
textureImporter.spriteImportMode = SpriteImportMode.None;
|
|||
|
textureImporter.SaveAndReimport();
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Sprite<74><65><EFBFBD>벢<EFBFBD><EBB2A2><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
textureImporter.spriteImportMode = SpriteImportMode.Multiple;
|
|||
|
textureImporter.spritesheet = originalMetaData; // <20>ָ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD>Ϣ
|
|||
|
|
|||
|
// <20><><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ø<EFBFBD><C3B8><EFBFBD>
|
|||
|
textureImporter.SaveAndReimport();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|