Files
JJBB/Assets/Editor/Scripts/AnimatorCullMode.cs
2024-08-23 15:49:34 +08:00

43 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.IO;
public class AnimatorCullMode : ResourceScanBase<GameObject>
{
[MenuItem("ResourceTool/Animator Cull Mode to Completely")]
public static void StartSetCullMode()
{
var instance = new AnimatorCullMode();
instance.Start();
}
private AnimatorCullMode() : base(".prefab")
{
}
protected override void FixOneAsset(GameObject asset, string assetPath)
{
var animator = asset.GetComponentInChildren<Animator>();
if (animator != null)
{
var instance = Object.Instantiate(asset);
try
{
var anims = instance.GetComponentsInChildren<Animator>();
for (var i = 0; i < anims.Length; i++)
anims[i].cullingMode = AnimatorCullingMode.CullCompletely;
PrefabUtility.CreatePrefab(AssetDatabase.GetAssetPath(asset), instance,
ReplacePrefabOptions.ReplaceNameBased);
}
catch (System.Exception e)
{
Debug.LogError(e.ToString());
}
Object.DestroyImmediate(instance);
}
}
}