2023-06-25 04:39:12 +02:00
|
|
|
using System.Collections.Generic;
|
2023-06-24 14:27:50 +02:00
|
|
|
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, $"../Data/Scenes/{scenePartitionSO.name}");
|
|
|
|
|
|
|
|
if (!Directory.Exists(dataPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(dataPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string GetScenePath(ScenePartitionSO scenePartitionSO)
|
|
|
|
{
|
|
|
|
string scenePath = AssetDatabase.GetAssetOrScenePath(scenePartitionSO.sceneAsset);
|
|
|
|
|
|
|
|
return scenePath;
|
|
|
|
}
|
2023-06-25 04:39:12 +02:00
|
|
|
|
|
|
|
public static SortedSet<uint> FindDeeplyLinkedObjects(SortedList<uint, ScenePartition> scenePartitions, uint partitionId)
|
|
|
|
{
|
|
|
|
SortedSet<uint> linkedObjects = new SortedSet<uint>();
|
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, partitionId, linkedObjects);
|
|
|
|
return linkedObjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void FindDeeplyLinkedObjectsRecursive(SortedList<uint, ScenePartition> scenePartitions, uint partitionId, SortedSet<uint> linkedObjects)
|
|
|
|
{
|
|
|
|
if (linkedObjects.Contains(partitionId)) return;
|
|
|
|
if (!scenePartitions.TryGetValue(partitionId, out ScenePartition partition)) return;
|
|
|
|
|
|
|
|
linkedObjects.Add(partitionId);
|
|
|
|
|
|
|
|
foreach (uint reference in partition.references)
|
|
|
|
{
|
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, reference, linkedObjects);
|
|
|
|
if (scenePartitions.TryGetValue(reference, out ScenePartition referencedPartition))
|
|
|
|
{
|
|
|
|
foreach (uint subReference in referencedPartition.references)
|
|
|
|
{
|
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, subReference, linkedObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-24 14:27:50 +02:00
|
|
|
}
|
|
|
|
}
|