using System.Collections.Generic; using UnityEditor; using UnityEngine; public static class LightProbeGroupMerger { const string MergedLightProbeGroupName = "MergedLightProbeGroup"; [MenuItem("Tools/Lights/Merge Light Probe Groups")] static void MergeLightProbeGroups() { var lightProbeGroups = GameObject.FindObjectsOfType(); if (lightProbeGroups.Length > 1) { // Collect light probe positions from all light probe groups in the scene. var mergedLightProbePositions = new List(); foreach (var lightProbeGroup in lightProbeGroups) { foreach (var lightProbePosition in lightProbeGroup.probePositions) { mergedLightProbePositions.Add(lightProbeGroup.transform.TransformPoint(lightProbePosition)); } } // Create a new light probe group that merges all the light probe positions. var newGameObject = new GameObject(MergedLightProbeGroupName); Undo.RegisterCreatedObjectUndo(newGameObject, $"Created {MergedLightProbeGroupName}"); var mergedLightProbeGroup = newGameObject.AddComponent(); mergedLightProbeGroup.probePositions = mergedLightProbePositions.ToArray(); // Destroy the old individual light probe groups. foreach (var lightProbeGroup in lightProbeGroups) { if (lightProbeGroup != null && lightProbeGroup.gameObject != null) { Undo.DestroyObjectImmediate(lightProbeGroup.gameObject); } } Debug.Log($"Merged {mergedLightProbePositions.Count} light probes from {lightProbeGroups.Length} light probe groups into '{MergedLightProbeGroupName}'."); Selection.activeObject = newGameObject; } } }