2023-04-03 11:04:31 +08:00

71 lines
2.4 KiB
C#

using UnityEngine;
using UnityEditor;
namespace BFEditor.Resource
{
public class PrefabTools
{
public static void DeleteAllOverEffectMesh()
{
var paths = BFEditorUtils.GetAssetPathsWithSuffix(ResourceProcessConfig.EFFECT_PREFAB_FOLDER_PATH, ".prefab");
var i = 0;
foreach (var path in paths)
{
EditorUtility.DisplayProgressBar("正在处理", path, (float)(i + 1) / paths.Count);
var gameObject = AssetDatabase.LoadAssetAtPath<GameObject>(path);
var effectsRenderer = gameObject.GetComponentsInChildren<ParticleSystemRenderer>(true);
foreach (var renderer in effectsRenderer)
{
if (renderer.mesh != null && renderer.renderMode != ParticleSystemRenderMode.Mesh)
{
AssetDatabase.ImportAsset(path);
}
}
i++;
}
EditorUtility.ClearProgressBar();
AssetDatabase.Refresh();
}
public static void DeleteAllMissingPrefab()
{
var paths = BFEditorUtils.GetAssetPathsWithSuffix(ResourceProcessConfig.PREFAB_FOLDER_PATH, ".prefab");
for (int i = 0; i < paths.Count; i++)
{
EditorUtility.DisplayProgressBar("正在检查Prefab", paths[i], (float)(i + 1) / paths.Count);
TryDeleteMissingPrefab(paths[i]);
}
EditorUtility.ClearProgressBar();
AssetDatabase.Refresh();
}
static void TryDeleteMissingPrefab(string assetPath)
{
var fileObj = PrefabUtility.LoadPrefabContents(assetPath);
if (fileObj)
{
var components = fileObj.GetComponentsInChildren<Component>(true);
foreach (var component in components)
{
if (component)
{
var status = PrefabUtility.GetPrefabInstanceStatus(component.gameObject);
if (status == PrefabInstanceStatus.MissingAsset)
{
Debug.Log(assetPath + " delete missing prefab " + component.gameObject.name);
Object.DestroyImmediate(component.gameObject);
PrefabUtility.SaveAsPrefabAsset(fileObj, assetPath);
}
}
}
}
PrefabUtility.UnloadPrefabContents(fileObj);
}
}
}