57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
public static class EnableGPUInstancing
|
|
{
|
|
private const string MaterialPrefix = "M_";
|
|
|
|
[MenuItem("Tools/Optimization/Enable GPU Instancing On M_ Materials")]
|
|
public static void EnableOnMPrefixMaterials()
|
|
{
|
|
string[] materialGuids = AssetDatabase.FindAssets("t:Material");
|
|
|
|
int changed = 0;
|
|
int alreadyEnabled = 0;
|
|
int skippedWrongPrefix = 0;
|
|
int skippedInvalid = 0;
|
|
|
|
foreach (string guid in materialGuids)
|
|
{
|
|
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
Material mat = AssetDatabase.LoadAssetAtPath<Material>(path);
|
|
|
|
if (mat == null || mat.shader == null || !mat.shader.isSupported)
|
|
{
|
|
skippedInvalid++;
|
|
continue;
|
|
}
|
|
|
|
if (!mat.name.StartsWith(MaterialPrefix))
|
|
{
|
|
skippedWrongPrefix++;
|
|
continue;
|
|
}
|
|
|
|
if (mat.enableInstancing)
|
|
{
|
|
alreadyEnabled++;
|
|
continue;
|
|
}
|
|
|
|
mat.enableInstancing = true;
|
|
EditorUtility.SetDirty(mat);
|
|
changed++;
|
|
}
|
|
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log(
|
|
$"GPU Instancing terminé sur les matériaux commençant par '{MaterialPrefix}'. " +
|
|
$"Activés : {changed}, " +
|
|
$"déjà actifs : {alreadyEnabled}, " +
|
|
$"ignorés mauvais préfixe : {skippedWrongPrefix}, " +
|
|
$"ignorés invalides : {skippedInvalid}."
|
|
);
|
|
}
|
|
} |