public void AnimateObjects() { var objectA = new AnimatableObject("ObjectA"); var propertyA1 = new AnimatableProperty <float> { Value = 10.0f }; objectA.Properties.Add("Value", propertyA1); var propertyA2 = new AnimatableProperty <float> { Value = 20.0f }; objectA.Properties.Add("Value2", propertyA2); var objectB = new AnimatableObject("ObjectB"); var propertyB = new AnimatableProperty <float> { Value = 30.0f }; objectB.Properties.Add("Value", propertyB); var objectC = new AnimatableObject("ObjectC"); var propertyC = new AnimatableProperty <float> { Value = 40.0f }; objectC.Properties.Add("Value", propertyC); var animationA1 = new SingleFromToByAnimation // Should be assigned to ObjectA { From = 100.0f, To = 200.0f, TargetObject = "ObjectXyz", // Ignored because ObjectA is selected by animationGroup1. TargetProperty = "Value", // Required. }; var animationA2 = new SingleFromToByAnimation // Should be assigned to ObjectA { From = 200.0f, To = 300.0f, TargetObject = "ObjectB", // Ignored because ObjectA is selected by animationGroup1. TargetProperty = "Value", // Required. }; var animationA3 = new Vector3FFromToByAnimation // Ignored because of incompatible type. { From = new Vector3F(300.0f), To = new Vector3F(400.0f), TargetObject = "ObjectA", TargetProperty = "Value", }; var animationA4 = new SingleFromToByAnimation // Ignored because TargetProperty is not set. { From = 400.0f, To = 500.0f, TargetObject = "", TargetProperty = "", }; var animationGroupA = new TimelineGroup { TargetObject = "ObjectA" }; animationGroupA.Add(animationA1); animationGroupA.Add(animationA2); animationGroupA.Add(animationA3); animationGroupA.Add(animationA4); var animationB1 = new SingleFromToByAnimation // Should be assigned to ObjectB { From = 100.0f, To = 200.0f, TargetObject = "ObjectB", TargetProperty = "Value", }; var animationA5 = new SingleFromToByAnimation { From = 600.0f, To = 700.0f, TargetObject = "", TargetProperty = "Value", }; var animationGroupRoot = new TimelineGroup(); animationGroupRoot.Add(animationGroupA); animationGroupRoot.Add(animationB1); animationGroupRoot.Add(animationA5); var manager = new AnimationManager(); // CreateController() var controller = manager.CreateController(animationGroupRoot, new[] { objectA, objectB, objectC }); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[0]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[1]).Property); Assert.AreEqual(null, ((AnimationInstance <Vector3F>)controller.AnimationInstance.Children[0].Children[2]).Property); Assert.AreEqual(null, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[3]).Property); Assert.AreEqual(propertyB, ((AnimationInstance <float>)controller.AnimationInstance.Children[1]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[2]).Property); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); controller.Start(); controller.UpdateAndApply(); Assert.AreEqual(600.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(100.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsTrue(manager.IsAnimated(objectA)); Assert.IsTrue(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsTrue(manager.IsAnimated(objectB)); Assert.IsTrue(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); controller.Stop(); controller.UpdateAndApply(); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); // StartAnimation() controller = manager.StartAnimation(animationGroupRoot, new[] { objectA, objectB, objectC }); controller.UpdateAndApply(); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[0]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[1]).Property); Assert.AreEqual(null, ((AnimationInstance <Vector3F>)controller.AnimationInstance.Children[0].Children[2]).Property); Assert.AreEqual(null, ((AnimationInstance <float>)controller.AnimationInstance.Children[0].Children[3]).Property); Assert.AreEqual(propertyB, ((AnimationInstance <float>)controller.AnimationInstance.Children[1]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance <float>)controller.AnimationInstance.Children[2]).Property); Assert.AreEqual(600.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(100.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsTrue(manager.IsAnimated(objectA)); Assert.IsTrue(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsTrue(manager.IsAnimated(objectB)); Assert.IsTrue(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); manager.StopAnimation(new[] { objectA, objectB, objectC }); manager.UpdateAndApplyAnimation(new[] { objectA, objectB, objectC }); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); }
public void AnimateObjects() { var objectA = new AnimatableObject("ObjectA"); var propertyA1 = new AnimatableProperty<float> { Value = 10.0f }; objectA.Properties.Add("Value", propertyA1); var propertyA2 = new AnimatableProperty<float> { Value = 20.0f }; objectA.Properties.Add("Value2", propertyA2); var objectB = new AnimatableObject("ObjectB"); var propertyB = new AnimatableProperty<float> { Value = 30.0f }; objectB.Properties.Add("Value", propertyB); var objectC = new AnimatableObject("ObjectC"); var propertyC = new AnimatableProperty<float> { Value = 40.0f }; objectC.Properties.Add("Value", propertyC); var animationA1 = new SingleFromToByAnimation // Should be assigned to ObjectA { From = 100.0f, To = 200.0f, TargetObject = "ObjectXyz", // Ignored because ObjectA is selected by animationGroup1. TargetProperty = "Value", // Required. }; var animationA2 = new SingleFromToByAnimation // Should be assigned to ObjectA { From = 200.0f, To = 300.0f, TargetObject = "ObjectB", // Ignored because ObjectA is selected by animationGroup1. TargetProperty = "Value", // Required. }; var animationA3 = new Vector3FFromToByAnimation // Ignored because of incompatible type. { From = new Vector3F(300.0f), To = new Vector3F(400.0f), TargetObject = "ObjectA", TargetProperty = "Value", }; var animationA4 = new SingleFromToByAnimation // Ignored because TargetProperty is not set. { From = 400.0f, To = 500.0f, TargetObject = "", TargetProperty = "", }; var animationGroupA = new TimelineGroup { TargetObject = "ObjectA" }; animationGroupA.Add(animationA1); animationGroupA.Add(animationA2); animationGroupA.Add(animationA3); animationGroupA.Add(animationA4); var animationB1 = new SingleFromToByAnimation // Should be assigned to ObjectB { From = 100.0f, To = 200.0f, TargetObject = "ObjectB", TargetProperty = "Value", }; var animationA5 = new SingleFromToByAnimation { From = 600.0f, To = 700.0f, TargetObject = "", TargetProperty = "Value", }; var animationGroupRoot = new TimelineGroup(); animationGroupRoot.Add(animationGroupA); animationGroupRoot.Add(animationB1); animationGroupRoot.Add(animationA5); var manager = new AnimationManager(); // CreateController() var controller = manager.CreateController(animationGroupRoot, new[] { objectA, objectB, objectC }); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[0]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[1]).Property); Assert.AreEqual(null, ((AnimationInstance<Vector3F>)controller.AnimationInstance.Children[0].Children[2]).Property); Assert.AreEqual(null, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[3]).Property); Assert.AreEqual(propertyB, ((AnimationInstance<float>)controller.AnimationInstance.Children[1]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[2]).Property); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); controller.Start(); controller.UpdateAndApply(); Assert.AreEqual(600.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(100.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsTrue(manager.IsAnimated(objectA)); Assert.IsTrue(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsTrue(manager.IsAnimated(objectB)); Assert.IsTrue(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); controller.Stop(); controller.UpdateAndApply(); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); // StartAnimation() controller = manager.StartAnimation(animationGroupRoot, new[] { objectA, objectB, objectC }); controller.UpdateAndApply(); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[0]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[1]).Property); Assert.AreEqual(null, ((AnimationInstance<Vector3F>)controller.AnimationInstance.Children[0].Children[2]).Property); Assert.AreEqual(null, ((AnimationInstance<float>)controller.AnimationInstance.Children[0].Children[3]).Property); Assert.AreEqual(propertyB, ((AnimationInstance<float>)controller.AnimationInstance.Children[1]).Property); Assert.AreEqual(propertyA1, ((AnimationInstance<float>)controller.AnimationInstance.Children[2]).Property); Assert.AreEqual(600.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(100.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsTrue(manager.IsAnimated(objectA)); Assert.IsTrue(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsTrue(manager.IsAnimated(objectB)); Assert.IsTrue(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); manager.StopAnimation(new[] { objectA, objectB, objectC }); manager.UpdateAndApplyAnimation(new[] { objectA, objectB, objectC }); Assert.AreEqual(10.0f, propertyA1.Value); Assert.AreEqual(20.0f, propertyA2.Value); Assert.AreEqual(30.0f, propertyB.Value); Assert.AreEqual(40.0f, propertyC.Value); Assert.IsFalse(manager.IsAnimated(objectA)); Assert.IsFalse(manager.IsAnimated(propertyA1)); Assert.IsFalse(manager.IsAnimated(propertyA2)); Assert.IsFalse(manager.IsAnimated(objectB)); Assert.IsFalse(manager.IsAnimated(propertyB)); Assert.IsFalse(manager.IsAnimated(objectC)); Assert.IsFalse(manager.IsAnimated(propertyC)); }