获取场景中所有的特效,然后检查所有的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);
}
}
}
本文介绍了一个Unity脚本功能,用于遍历场景中所有粒子系统(ParticleSystem),检查并关闭Prewarm属性,适用于游戏开发和Unity引擎使用者。代码实现了获取所有粒子系统实例,检查Prewarm状态,如开启则关闭,并根据不同情况保存Prefab。
2045

被折叠的 条评论
为什么被折叠?



