4 Commits

Author SHA1 Message Date
max
28e30a30a4 ClearRootOrderProperty 2023-08-13 04:24:01 +02:00
max
8453143918 Comment 2023-08-10 22:27:10 +02:00
max
1b9c367221 Prevent 'scene changed on disk' popup
Prevent 'scene changed on disk' popup when loading/additive loading.
2023-08-10 22:24:10 +02:00
max
4fe602e932 Save scene on save
- Check if the user wants to save the dirty scene on save
2023-08-10 21:41:57 +02:00

View File

@ -92,7 +92,7 @@ namespace VertexColor.ScenePartition.Editor
// Add always load ids.
SortedSet<ulong> baseIds = GetAlwaysLoadIds();
foreach (var id in baseIds)
foreach (ulong id in baseIds)
{
partitionIds.Add(id);
}
@ -129,6 +129,8 @@ namespace VertexColor.ScenePartition.Editor
}
AssetDatabase.Refresh();
// 'Reload' the scene to prevent the user getting the popup 'Scene has been changed on disk'.
EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
}
}
@ -139,6 +141,9 @@ namespace VertexColor.ScenePartition.Editor
{
using (new ProfilerUtility.ProfilerScope($"{nameof(Save)}"))
{
// Check if the user wants to save the scene if dirty.
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) return;
DeleteLoadedPartitions(); // Delete the loaded partitions from disk so we can write the new ones.
string pattern = @"&(\d+)";
@ -158,7 +163,11 @@ namespace VertexColor.ScenePartition.Editor
if (match.Success)
{
// Extract the file number
// Modify scene data.
// Optional: ClearRootOrderProperty.
ClearRootOrderProperty(ref sceneData, i, lastIndex);
// Extract the file number.
string id = match.Groups[1].Value;
// Write data to disk.
@ -377,5 +386,47 @@ namespace VertexColor.ScenePartition.Editor
{
data = null;
}
/// <summary>
/// Sets the m_RootOrder property to '0' on all transforms and prefab transform modifications.
/// The property changes every time you add/remove something in the scene for each object underneat it in the hierarchy.
/// This results in a lot of changes in source control that might cause conficts, and we don't want that.
/// This does however change the scene hierarchy order, so if things are order dependent this will break it.
/// </summary>
private void ClearRootOrderProperty(ref string[] data, int i, int lastIndex)
{
using (new ProfilerUtility.ProfilerScope($"{nameof(ClearRootOrderProperty)}"))
{
const string prefabHeaderPattern = "--- !u!1001 &";
const string transformHeaderPattern = "--- !u!4 &";
const string prefabRootOrderPropertyPattern = " propertyPath: m_RootOrder";
const string transformRootOrderPropertyPattern = " m_RootOrder:";
const string numberPattern = @"[\d-]";
// If object is a Prefab.
if (data[i].StartsWith(prefabHeaderPattern))
{
for (int j = i; j < lastIndex; j++)
{
if (!data[j].StartsWith(prefabRootOrderPropertyPattern)) continue;
data[j + 1] = Regex.Replace(data[j + 1], numberPattern, "0");
return;
}
}
// If object is a Transform.
else if (data[i].StartsWith(transformHeaderPattern))
{
// Reverse loop since property is usually at the bottom of the transform component.
for (int j = lastIndex - 1; j >= 0; j--)
{
if (!data[j].StartsWith(transformRootOrderPropertyPattern)) continue;
data[j] = Regex.Replace(data[j], numberPattern, "0");
return;
}
}
}
}
}
}