48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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("✅ 已将选中物体及其子物体设置为 Static(Batching Static)。");
|
||
}
|
||
|
||
private void SetStaticRecursively(GameObject go)
|
||
{
|
||
go.isStatic = true; // 设置为静态
|
||
foreach (Transform child in go.transform)
|
||
{
|
||
SetStaticRecursively(child.gameObject);
|
||
}
|
||
}
|
||
} |