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)
|
|
|
|
{
|
2023-07-03 23:35:29 +02:00
|
|
|
string dataPath = Path.Combine(Application.dataPath, GetRelativeFilePath(scenePartitionSO));
|
2023-06-24 14:27:50 +02:00
|
|
|
|
|
|
|
if (!Directory.Exists(dataPath))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(dataPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataPath;
|
|
|
|
}
|
|
|
|
|
2023-07-03 23:35:29 +02:00
|
|
|
public static string GetRelativeFilePath(ScenePartitionSO scenePartitionSO)
|
|
|
|
{
|
|
|
|
return $"../Data/ScenePartition/{scenePartitionSO.name}";
|
|
|
|
}
|
|
|
|
|
2023-06-24 14:27:50 +02:00
|
|
|
public static string GetScenePath(ScenePartitionSO scenePartitionSO)
|
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
string scenePath = AssetDatabase.GetAssetOrScenePath(scenePartitionSO.SceneAsset);
|
2023-06-24 14:27:50 +02:00
|
|
|
|
|
|
|
return scenePath;
|
|
|
|
}
|
2023-06-25 04:39:12 +02:00
|
|
|
|
2023-07-03 23:35:29 +02:00
|
|
|
public static SortedSet<ulong> FindDeeplyLinkedObjects(SortedList<ulong, ScenePartition> scenePartitions, ulong partitionId)
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
2023-07-03 23:35:29 +02:00
|
|
|
SortedSet<ulong> linkedObjects = new SortedSet<ulong>();
|
2023-06-25 04:39:12 +02:00
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, partitionId, linkedObjects);
|
|
|
|
return linkedObjects;
|
|
|
|
}
|
|
|
|
|
2023-07-03 23:35:29 +02:00
|
|
|
private static void FindDeeplyLinkedObjectsRecursive(SortedList<ulong, ScenePartition> scenePartitions, ulong partitionId, SortedSet<ulong> linkedObjects)
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
|
|
|
if (linkedObjects.Contains(partitionId)) return;
|
|
|
|
if (!scenePartitions.TryGetValue(partitionId, out ScenePartition partition)) return;
|
|
|
|
|
|
|
|
linkedObjects.Add(partitionId);
|
|
|
|
|
2023-07-03 23:35:29 +02:00
|
|
|
foreach (ulong reference in partition.references)
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, reference, linkedObjects);
|
|
|
|
if (scenePartitions.TryGetValue(reference, out ScenePartition referencedPartition))
|
|
|
|
{
|
2023-07-03 23:35:29 +02:00
|
|
|
foreach (ulong subReference in referencedPartition.references)
|
2023-06-25 04:39:12 +02:00
|
|
|
{
|
|
|
|
FindDeeplyLinkedObjectsRecursive(scenePartitions, subReference, linkedObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-24 14:27:50 +02:00
|
|
|
}
|
|
|
|
}
|