由于Unity的一个问题,导致Material中替换过的贴图,使用GetDepenecicies方法时会把替换掉的就资源也引用到。
替换方法:
public static void CleanMaterialSerializedProperty(List<Material> mats, ref string content)
{
for (int j = 0; j < mats.Count; j++)
{
if (mats[j])
{
bool flag = false;
SerializedObject psSource = new SerializedObject(mats[j]);
SerializedProperty propArr = psSource.FindProperty("m_SavedProperties");
SerializedProperty prop = null;
propArr.Next(true);
do
{
if (!propArr.isArray) continue;
for (int i = propArr.arraySize - 1; i >= 0; --i)
{
prop = propArr.GetArrayElementAtIndex(i);
if (!mats[j].HasProperty(prop.displayName))
{
propArr.DeleteArrayElementAtIndex(i);
flag = true;
}
}
} while (propArr.Next(false));
psSource.ApplyModifiedProperties();
if(flag)
content += AssetDatabase.GetAssetPath(mats[j]) + "\n";
}
}
AssetDatabase.SaveAssets();
}
????????
|