Skip to content

Commit

Permalink
Merge pull request #176 from anatawa12/errors-in-object-mapping
Browse files Browse the repository at this point in the history
Errors in object mapping
  • Loading branch information
anatawa12 authored May 22, 2023
2 parents 16594d9 + d192bb3 commit 16c5798
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Errors in Animation Mapping System `#176`
- Error with removed property
- Error with Property moved twice

### Security

Expand Down
3 changes: 3 additions & 0 deletions Editor/ObjectMapping/AnimationObjectMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ public EditorCurveBinding MapBinding(EditorCurveBinding binding)
binding.path = newPath;

if (componentInfo.PropertyMapping.TryGetValue(binding.propertyName, out var newProp))
{
if (newProp == null) return default;
binding.propertyName = newProp;
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Editor/ObjectMapping/ObjectMappingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void MoveProperty(string oldProp, string newProp)
_afterPropertyIds.Remove(oldProp);
_afterPropertyIds[newProp] = propId;
if (!_beforePropertyIds.ContainsKey(oldProp))
_beforePropertyIds.Add(newProp, propId);
_beforePropertyIds.Add(oldProp, propId);
}
else
{
Expand Down
24 changes: 23 additions & 1 deletion Test~/ObjectMappingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ public void RecordMovePropertyTest()
Is.EqualTo(B("child1", typeof(SkinnedMeshRenderer), "blendShapes.changed")));
}

[Test]
public void RecordMovePropertyTwiceTest()
{
var root = new GameObject();
var child1 = Utils.NewGameObject("child1", root.transform);
var child1Component = child1.AddComponent<SkinnedMeshRenderer>();

var builder = new ObjectMappingBuilder(root);
builder.RecordMoveProperty(child1Component, "blendShapes.test", "blendShapes.changed0");
builder.RecordMoveProperty(child1Component, "blendShapes.changed0", "blendShapes.changed");

var built = builder.BuildObjectMapping();

var rootMapper = built.CreateAnimationMapper(root);

Assert.That(
rootMapper.MapBinding(B("child1", typeof(SkinnedMeshRenderer), "blendShapes.test")),
Is.EqualTo(B("child1", typeof(SkinnedMeshRenderer), "blendShapes.changed")));
Assert.That(
rootMapper.MapBinding(B("child1", typeof(SkinnedMeshRenderer), "blendShapes.changed0")),
Is.EqualTo(B("child1", typeof(SkinnedMeshRenderer), "blendShapes.changed")));
}

[Test]
public void RecordRemovePropertyTest()
{
Expand All @@ -165,7 +188,6 @@ public void RecordRemovePropertyTest()

var builder = new ObjectMappingBuilder(root);
builder.RecordRemoveProperty(child1Component, "blendShapes.test");
Object.DestroyImmediate(child1Component);

var built = builder.BuildObjectMapping();

Expand Down

0 comments on commit 16c5798

Please sign in to comment.