ScenePartition/Editor/ScenePartitionSS.cs

43 lines
1.4 KiB
C#
Raw Permalink Normal View History

2023-06-27 00:24:46 +02:00
using UnityEditor;
using UnityEngine;
namespace VertexColor.ScenePartition.Editor
{
/// <summary>
/// Local cache/data container.
/// Hold loaded data, calculated data, cache data, state data.
/// This data is persistent though editor sessions and recompiles, is stored in the project folder.
/// </summary>
[FilePath("Library/ScenePartition/SceneDataCache.asset", FilePathAttribute.Location.ProjectFolder)]
2023-06-27 00:24:46 +02:00
public class ScenePartitionSS : ScriptableSingleton<ScenePartitionSS>
{
public SceneDataCache SceneDataCache => sceneDataCache;
[SerializeField]
private SceneDataCache sceneDataCache = new SceneDataCache();
public ScenePartitionData GetScenePartitionData(ScenePartitionSO scenePartitionSO)
{
if (!sceneDataCache.TryGetValue(scenePartitionSO, out ScenePartitionData scenePartitionData))
{
scenePartitionData = new ScenePartitionData();
sceneDataCache.Add(scenePartitionSO, scenePartitionData);
}
return scenePartitionData;
}
private void OnDisable()
{
Save();
}
public static void Save()
{
instance.Save(true);
}
2023-06-27 00:24:46 +02:00
}
[System.Serializable]
public class SceneDataCache : SerializableDictionary<ScenePartitionSO, ScenePartitionData> { }
}