Skip to content

Commit

Permalink
fix: fixing register button not setting holder as dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Apr 5, 2023
1 parent 0636a33 commit 762e295
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Assets/Mirage/Editor/ClientObjectManagerInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public void MovePrefabsToSO()
var com = (ClientObjectManager)target;

// add to new
Undo.RecordObject(com.NetworkPrefabs, "Adding prefabs from com.spawnPrefabs");
Undo.RecordObject(com.NetworkPrefabs, "Adding prefabs to SO {com.NetworkPrefabs.name}");
NetworkPrefabUtils.AddToPrefabList(com.NetworkPrefabs.Prefabs, com.spawnPrefabs);
EditorUtility.SetDirty(com.NetworkPrefabs);

// clear old
var listProp = serializedObject.FindProperty(nameof(ClientObjectManager.spawnPrefabs));
Expand All @@ -103,12 +104,13 @@ public void RegisterAllPrefabs()
// first use networkprefabs for list, if null then use the list field
if (com.NetworkPrefabs != null)
{
Undo.RecordObject(com.NetworkPrefabs, "Register prefabs for spawn");
Undo.RecordObject(com.NetworkPrefabs, $"Register All Prefabs to SO {com.NetworkPrefabs.name}");
NetworkPrefabUtils.AddToPrefabList(com.NetworkPrefabs.Prefabs, foundPrefabs);
EditorUtility.SetDirty(com.NetworkPrefabs);
}
else
{
Undo.RecordObject(target, "Register prefabs for spawn");
Undo.RecordObject(com.NetworkPrefabs, $"Register All Prefabs to COM {com.name}");

Check failure on line 113 in Assets/Mirage/Editor/ClientObjectManagerInspector.cs

View workflow job for this annotation

GitHub Actions / Tests Results

Failed test RegisterAllWithField in Mirage.Tests.CustomGUI.ClientObjectManagerInspectorTest

Unhandled log message: '[Error] Undo object may not be null.'. Use UnityEngine.TestTools.LogAssert.Expect
Raw output
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Mirage.ClientObjectManagerInspector:RegisterAllPrefabs () (at Assets/Mirage/Editor/ClientObjectManagerInspector.cs:113)
Mirage.Tests.CustomGUI.ClientObjectManagerInspectorTest:RegisterAllWithField () (at Assets/Tests/Editor/CustomGUI/ClientObjectManagerInspectorTest.cs:60)
System.Reflection.MethodBase:Invoke (object,object[])
NUnit.Framework.Internal.Reflect:InvokeMethod (System.Reflection.MethodInfo,object,object[])
NUnit.Framework.Internal.MethodWrapper:Invoke (object,object[])
NUnit.Framework.Internal.Commands.TestMethodCommand:RunNonAsyncTestMethod (NUnit.Framework.Internal.ITestExecutionContext)
NUnit.Framework.Internal.Commands.TestMethodCommand:RunTestMethod (NUnit.Framework.Internal.ITestExecutionContext)
NUnit.Framework.Internal.Commands.TestMethodCommand:Execute (NUnit.Framework.Internal.ITestExecutionContext)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
NetworkPrefabUtils.AddToPrefabList(com.spawnPrefabs, foundPrefabs);
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Mirage/Editor/NetworkPrefabsInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public void RegisterPrefabs()

var target = (NetworkPrefabs)this.target;

Undo.RecordObject(target, "Register prefabs for spawn");
Undo.RecordObject(target, $"Register All Prefabs to SO {target.name}");
NetworkPrefabUtils.AddToPrefabList(target.Prefabs, foundPrefabs);
EditorUtility.SetDirty(target);
}
}
}
3 changes: 3 additions & 0 deletions Assets/Mirage/Editor/NetworkedPrefabAttributeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ private static void Register(IEnumerable<NetworkPrefabs> allHolders, NetworkIden
{
Undo.RecordObject(holder, $"Adding {prefab.name} to {holder.name}");
holder.Prefabs.Add(prefab);

// seems like we need to also mark dirty for non-scene objects
EditorUtility.SetDirty(holder);
}
GUIUtility.ExitGUI();
}
Expand Down

0 comments on commit 762e295

Please sign in to comment.