public static void ChangeInstanceType() { var start = new HostObject { nested = new DerivedObject { c = 5 } }; var end = new HostObject { nested = new SimpleObject { a = 1, b = 2 } }; var startModel = new SavedObject(start); var endModel = new SavedObject(end); var delta = new SavedObjectDelta(startModel, endModel); delta.ApplyChanges(ref end); Assert.AreEqual(start.nested.GetType(), end.nested.GetType()); Assert.AreEqual(start.nested.a, end.nested.a); Assert.AreEqual(start.nested.b, end.nested.b); Assert.AreEqual(((DerivedObject)start.nested).c, ((DerivedObject)end.nested).c); }
public static void RunSimpleApplyTest() { var start = new SimpleObject { a = 1, b = 2, nested = new SimpleObject { a = 3, b = 4 } }; var end = new SimpleObject { a = 2, b = 2 }; var startModel = new SavedObject(start); var endModel = new SavedObject(end); var delta = new SavedObjectDelta(startModel, endModel); delta.ApplyChanges(ref end); Assert.AreEqual(end.a, start.a); Assert.AreEqual(end.b, start.b); Assert.AreEqual(end.nested.a, start.nested.a); Assert.AreEqual(end.nested.b, start.nested.b); Assert.AreEqual(end.nested.nested, start.nested.nested); }
public static void RunCollectionApplyTest() { var start = new CollectionHolder(); start.dict["foo1"] = "bar1"; start.dict["foo2"] = "bar2"; start.list = new List <int> { 1, 2 }; start.arr = new[] { true, false }; var end = new CollectionHolder(); end.dict["foo1"] = "baz"; end.list = new List <int> { 1, 3, 4 }; end.arr = new bool[] { }; // Compute in-memory representation. var startModel = new SavedObject(start); var endModel = new SavedObject(end); // Compute differental. var delta = new SavedObjectDelta(startModel, endModel); // Apply differental. delta.ApplyChanges(ref end); // Compare. CollectionAssert.AreEqual(start.dict, end.dict); CollectionAssert.AreEqual(start.list, end.list); CollectionAssert.AreEqual(start.arr, end.arr); }
public static void ApplyEnum() { var before = new EnumHolder { enumValue = EnumHolder.EnumValue.A }; var after = new EnumHolder { enumValue = EnumHolder.EnumValue.B }; var delta = new SavedObjectDelta(new SavedObject(after), new SavedObject(before)); delta.ApplyChanges(ref before); Assert.AreEqual(after.enumValue, before.enumValue); }
public static void ShowInspectorForSerializedObject(UnityObject[] targets) { CheckForNewBaseBehaviorType(targets[0].GetType()); DrawOpenScriptButton(targets[0]); // TODO: How do we show a mixed value? // TODO: We could have a global call of some sort? // TODO: We have the edit path w.r.t. metadata, so we can compute the // deltas at the start and then export it as a list which // property editors can check against. // Capture object state if we are doing multi-object editing. var preeditState = new SavedObject(); if (fiSettings.EnableMultiEdit && targets.Length > 1) { preeditState = new SavedObject(targets[0]); } // Run the editor BehaviorEditor.Get(targets[0].GetType()).EditWithGUILayout(targets[0]); // Inspector for the serialized state var inspectedObject = targets[0] as ISerializedObject; if (inspectedObject != null) { EditorGUI.BeginChangeCheck(); DrawSerializedState(inspectedObject); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(targets[0]); inspectedObject.RestoreState(); } } // Apply changes to other objects that are being edited. if (fiSettings.EnableMultiEdit && targets.Length > 1) { var posteditState = new SavedObject(targets[0]); var delta = new SavedObjectDelta(posteditState, preeditState); for (int i = 1; i < targets.Length; ++i) { UnityObject obj = targets[i]; delta.ApplyChanges(ref obj); } } }
public static void ShowInspectorForSerializedObject(UnityObject[] targets) { CheckForNewBaseBehaviorType(targets[0].GetType()); DrawOpenScriptButton(targets[0]); // TODO: How do we show a mixed value? // TODO: We could have a global call of some sort? // TODO: We have the edit path w.r.t. metadata, so we can compute the // deltas at the start and then export it as a list which // property editors can check against. // Capture object state if we are doing multi-object editing. var preeditState = new SavedObject(); if (fiSettings.EnableMultiEdit && targets.Length > 1) preeditState = new SavedObject(targets[0]); // Run the editor BehaviorEditor.Get(targets[0].GetType()).EditWithGUILayout(targets[0]); // Inspector for the serialized state var inspectedObject = targets[0] as ISerializedObject; if (inspectedObject != null) { EditorGUI.BeginChangeCheck(); DrawSerializedState(inspectedObject); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(targets[0]); inspectedObject.RestoreState(); } } // Apply changes to other objects that are being edited. if (fiSettings.EnableMultiEdit && targets.Length > 1) { var posteditState = new SavedObject(targets[0]); var delta = new SavedObjectDelta(posteditState, preeditState); for (int i = 1; i < targets.Length; ++i) { UnityObject obj = targets[i]; delta.ApplyChanges(ref obj); } } }
public static void SimpleIntegrationExample() { var inspected = new SimpleObject() { a = 1, b = 2 }; var previousState = new SavedObject(inspected); inspected.a = 5; var currentState = new SavedObject(inspected); var delta = new SavedObjectDelta(currentState, previousState); var hello = new SimpleObject(); delta.ApplyChanges(ref hello); Assert.AreEqual(5, hello.a); Assert.AreEqual(0, hello.b); }
public static void TestApplyMissingProperty() { var start = new DerivedObject { a = 1, b = 2, c = 3 }; var end = new DerivedObject { a = 2, b = 2, c = 5 }; var delta = new SavedObjectDelta(new SavedObject(start), new SavedObject(end)); var simpleObj = new SimpleObject() { b = 20 }; delta.ApplyChanges(ref simpleObj); Assert.AreEqual(start.a, simpleObj.a); Assert.AreEqual(20, simpleObj.b); }
public static void RunCollectionApplyTest() { var start = new CollectionHolder(); start.dict["foo1"] = "bar1"; start.dict["foo2"] = "bar2"; start.list = new List<int> { 1, 2 }; start.arr = new[] { true, false }; var end = new CollectionHolder(); end.dict["foo1"] = "baz"; end.list = new List<int> { 1, 3, 4 }; end.arr = new bool[] { }; // Compute in-memory representation. var startModel = new SavedObject(start); var endModel = new SavedObject(end); // Compute differental. var delta = new SavedObjectDelta(startModel, endModel); // Apply differental. delta.ApplyChanges(ref end); // Compare. CollectionAssert.AreEqual(start.dict, end.dict); CollectionAssert.AreEqual(start.list, end.list); CollectionAssert.AreEqual(start.arr, end.arr); }