获取场景中所有的特效,然后检查所有的ParticleSystem中的Prewarm是否打开,如果打开的话关闭,最后保存Prefab。就是这样的一个简单功能。代码如下:
public static void ModifyParticle()
{
ParticleSystem[] ps = FindObjectsOfType<ParticleSystem>();
Debug.Log(SceneManager.GetActiveScene().name + ":" + ps.Length);
for (int i = 0; i < ps.Length; i++)
{
ParticleSystem p = ps[i];
if (null != p && p.main.prewarm)
{
Debug.Log("Prewarm is true:" + p.name);
ParticleSystem.MainModule module = p.main;
module.prewarm = false;
var status = PrefabUtility.GetPrefabInstanceStatus(p);
if (status == PrefabInstanceStatus.Connected)
{
PrefabUtility.ApplyPrefabInstance(p.gameObject, InteractionMode.AutomatedAction);
}
else if (status == PrefabInstanceStatus.NotAPrefab)
{
var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
if (null != prefabStage)
{
PrefabUtility.SaveAsPrefabAsset(p.gameObject, prefabStage.prefabAssetPath);
}
else
{
PrefabUtility.SavePrefabAsset(p.gameObject);
}
}
else
{
Debug.LogError("prefab save failed : " + p.name);
}
}
else
{
Debug.Log("Prewarm is false:" + p.name);
}
}
}