Compare commits

...

1 Commits

Author SHA1 Message Date
max
28e30a30a4 ClearRootOrderProperty 2023-08-13 04:24:01 +02:00

View File

@ -163,7 +163,11 @@ public void Save()
if (match.Success) 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; string id = match.Groups[1].Value;
// Write data to disk. // Write data to disk.
@ -382,5 +386,47 @@ public void ClearCache()
{ {
data = null; 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;
}
}
}
}
} }
} }