using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; namespace VertexColor.ScenePartition.Editor { public static class ScenePartitionUtils { public static string GetDataPath(ScenePartitionSO scenePartitionSO) { string dataPath = Path.Combine(Application.dataPath, GetRelativeFilePath(scenePartitionSO)); if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } return dataPath; } public static string GetRelativeFilePath(ScenePartitionSO scenePartitionSO) { return $"../Data/ScenePartition/{scenePartitionSO.name}"; } public static string GetScenePath(ScenePartitionSO scenePartitionSO) { string scenePath = AssetDatabase.GetAssetOrScenePath(scenePartitionSO.SceneAsset); return scenePath; } public static SortedSet FindDeeplyLinkedObjects(SortedList scenePartitions, ulong partitionId) { SortedSet linkedObjects = new SortedSet(); FindDeeplyLinkedObjectsRecursive(scenePartitions, partitionId, linkedObjects); return linkedObjects; } private static void FindDeeplyLinkedObjectsRecursive(SortedList scenePartitions, ulong partitionId, SortedSet linkedObjects) { if (linkedObjects.Contains(partitionId)) return; if (!scenePartitions.TryGetValue(partitionId, out ScenePartition partition)) return; linkedObjects.Add(partitionId); foreach (ulong reference in partition.references) { FindDeeplyLinkedObjectsRecursive(scenePartitions, reference, linkedObjects); if (scenePartitions.TryGetValue(reference, out ScenePartition referencedPartition)) { foreach (ulong subReference in referencedPartition.references) { FindDeeplyLinkedObjectsRecursive(scenePartitions, subReference, linkedObjects); } } } } } }