Files
Zombie/Assets/Editor/BatchSetStatic.cs

48 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEditor;
public class BatchSetStatic : EditorWindow
{
[MenuItem("Tools/Static Batching/批量设置 Static")]
public static void ShowWindow()
{
GetWindow<BatchSetStatic>("批量设置 Static");
}
private void OnGUI()
{
GUILayout.Label("批量设置 Static 标志", EditorStyles.boldLabel);
if (GUILayout.Button("设置选中物体及子物体为 Static"))
{
SetStaticBatching();
}
}
private void SetStaticBatching()
{
GameObject[] selectedObjects = Selection.gameObjects;
if (selectedObjects.Length == 0)
{
Debug.LogWarning("请先选中一个或多个物体!");
return;
}
foreach (GameObject go in selectedObjects)
{
SetStaticRecursively(go);
}
Debug.Log("✅ 已将选中物体及其子物体设置为 StaticBatching Static。");
}
private void SetStaticRecursively(GameObject go)
{
go.isStatic = true; // 设置为静态
foreach (Transform child in go.transform)
{
SetStaticRecursively(child.gameObject);
}
}
}