// Called when the "Animate" button was clicked. private void OnButtonClicked(object sender, EventArgs eventArgs) { // Get the selected easing function from the DropDownButton. EasingFunction easingFunction = (EasingFunction)_functionDropDown.Items[_functionDropDown.SelectedIndex]; // Set the selected easing mode. easingFunction.Mode = (EasingMode)_modeDropDown.Items[_modeDropDown.SelectedIndex]; // The current slider value: float startValue = _slider.Value; // Set the slider to the target value. _slider.Value = (startValue > 0.5f) ? 0 : 1; // Create a from-animation that uses the easing function. It animates the slider // value from startValue to the new value. SingleFromToByAnimation animation = new SingleFromToByAnimation { TargetProperty = "Value", From = startValue, Duration = TimeSpan.FromSeconds(1), EasingFunction = easingFunction, FillBehavior = FillBehavior.Stop, // Stop the animation when it is finished. }; // Start the animation. // (Use the Replace transition to replace any currently running animations. // This is necessary because the user could press the Animate button while // an animation is running.) _animationService.StartAnimation(animation, _slider, AnimationTransitions.Replace()) .UpdateAndApply(); // Apply new animation value immediately. }
public override void Update(GameTime gameTime) { base.Update(gameTime); // <Space> --> Cross-fade to next animation. if (InputService.IsPressed(Keys.Space, true)) { _currentAnimationIndex++; if (_currentAnimationIndex >= _animations.Length) { _currentAnimationIndex = 0; } for (int i = 0; i < NumberOfModels; i++) { // Start a next animation using a Replace transition with a fade-in time. AnimationService.StartAnimation( _animations[_currentAnimationIndex], (IAnimatableProperty <SkeletonPose>)_meshNodes[i].SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.2))) .AutoRecycle(); } } // Sidenote: // SkeletonPose.Update() is a method that can be called to update all internal skeleton pose // data immediately. If SkeletonPose.Update() is not called, the internal data will // be updated when needed - for example, when SkeletonPose.SkinningMatricesXna are accessed. //for (int i = 0; i < NumberOfModels; i++) // _meshNodes[i].SkeletonPose.Update(); }
public override void Update(GameTime gameTime) { if (_avatarPose == null) { if (_avatarRenderer.State == AvatarRendererState.Ready) { _avatarPose = new AvatarPose(_avatarRenderer); // Start the first animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } } else { if (InputService.IsPressed(Buttons.A, false, LogicalPlayerIndex.One)) { // Switch to next preset. _currentAvatarAnimationPreset++; if (!Enum.IsDefined(typeof(AvatarAnimationPreset), _currentAvatarAnimationPreset)) { _currentAvatarAnimationPreset = 0; } // Cross-fade to new animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5)) ).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } if (InputService.IsPressed(Buttons.B, false, LogicalPlayerIndex.One)) { // Switch to previous preset. _currentAvatarAnimationPreset--; if (!Enum.IsDefined(typeof(AvatarAnimationPreset), _currentAvatarAnimationPreset)) { _currentAvatarAnimationPreset = (AvatarAnimationPreset)EnumHelper.GetValues(typeof(AvatarAnimationPreset)).Length - 1; } // Cross-fade to new animation. var wrappedAnimation = WrapAnimation(_currentAvatarAnimationPreset); AnimationService.StartAnimation(wrappedAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5)) ).AutoRecycle(); _debugRenderer.Clear(); _debugRenderer.DrawText("\n\nCurrent Animation: " + _currentAvatarAnimationPreset); } } }
public MixingSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); var animations = _meshNode.Mesh.Animations; _runAnimation = new AnimationClip <SkeletonPose>(animations["Run"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _idleAnimation = new AnimationClip <SkeletonPose>(animations["Idle"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Create a 'Shoot' animation that only affects the upper body. var shootAnimation = animations["Shoot"]; // The SkeletonKeyFrameAnimations allows to set a weight for each bone channel. // For the 'Shoot' animation, we set the weight to 0 for all bones that are // not descendants of the second spine bone (bone index 2). That means, the // animation affects only the upper body bones and is disabled on the lower // body bones. for (int i = 0; i < _meshNode.Mesh.Skeleton.NumberOfBones; i++) { if (!SkeletonHelper.IsAncestorOrSelf(_meshNode.SkeletonPose, 2, i)) { shootAnimation.SetWeight(i, 0); } } var loopedShootingAnimation = new AnimationClip <SkeletonPose>(shootAnimation) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Start 'Idle' animation. _idleAnimationController = AnimationService.StartAnimation(_idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose); _idleAnimationController.AutoRecycle(); // Start looping the 'Shoot' animation. We use a Compose transition. This will add the // 'Shoot' animation to the animation composition chain and keeping all other playing // animations. // The 'Idle' animation animates the whole skeleton. The 'Shoot' animation replaces // the 'Idle' animation on the bones of the upper body. AnimationService.StartAnimation(loopedShootingAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Compose() ).AutoRecycle(); }
public void ComposeAfterWithFadeIn() { var property = new AnimatableProperty <float> { Value = 100.0f }; var animationA = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animationA, property); Assert.AreEqual(100.0f, property.Value); controllerA.Start(AnimationTransitions.Compose(TimeSpan.FromSeconds(1.0))); Assert.AreEqual(100.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(150.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(200.0f, property.Value); var animationB = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 10.0f, }; var controllerB = manager.CreateController(animationB, property); Assert.AreEqual(200.0f, property.Value); controllerB.Start(AnimationTransitions.Compose(controllerA.AnimationInstance, TimeSpan.FromSeconds(1.0))); Assert.AreEqual(200.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(205.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(210.0f, property.Value); controllerA.Stop(); controllerA.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); controllerB.Stop(); controllerB.UpdateAndApply(); Assert.AreEqual(100.0f, property.Value); }
public override void Update(GameTime gameTime) { if (InputService.IsPressed(Keys.Space, false)) { if (_state == 1) { // Fade-in the vertical animation, replacing the previous animations. _state = 2; _currentAnimationController = AnimationService.StartAnimation( _verticalAnimation, _animatedPosition, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5))); // Replace all previous animations using a fade-in of 0.5 seconds. _currentAnimationController.AutoRecycle(); } else { // Fade-in the horizontal animation, replacing the previous animations. _state = 1; _currentAnimationController = AnimationService.StartAnimation( _horizontalAnimation, _animatedPosition, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5))); _currentAnimationController.AutoRecycle(); } } if (InputService.IsPressed(Keys.Enter, false)) { if (_state == 0) { // Fade-in the horizontal animation. _state = 1; _currentAnimationController = AnimationService.StartAnimation( _horizontalAnimation, _animatedPosition, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5))); _currentAnimationController.AutoRecycle(); } else { // Fade-out the current animation. _state = 0; _currentAnimationController.Stop(TimeSpan.FromSeconds(0.5)); // Fade-out over 0.5 seconds. } } base.Update(gameTime); }
public void FindUIElements() { // Only find if none of the critical UI elements are assigned: var elements = UnityUISelectorElements.instance; if (elements == null) { elements = SearchForElements(DialogueManager.instance.transform); } if (elements != null) { UnityUISelectorElements.instance = elements; } if (mainGraphic == null && nameText == null && reticleInRange == null) { if (elements == null) { if (DialogueDebug.logWarnings) { Debug.LogWarning("Dialogue System: UnityUISelectorDisplay can't find UI elements", this); } } else { if (mainGraphic == null) { mainGraphic = elements.mainGraphic; } if (nameText == null) { nameText = elements.nameText; } if (useMessageText == null) { useMessageText = elements.useMessageText; } inRangeColor = elements.inRangeColor; outOfRangeColor = elements.outOfRangeColor; if (reticleInRange == null) { reticleInRange = elements.reticleInRange; } if (reticleOutOfRange == null) { reticleOutOfRange = elements.reticleOutOfRange; } animationTransitions = elements.animationTransitions; } } if (mainGraphic != null) { animator = mainGraphic.GetComponentInChildren <Animator>(); } }
public AdditiveAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { Rectangle bounds = GraphicsService.GraphicsDevice.Viewport.TitleSafeArea; // ----- Create and start the base animation. Vector2FromToByAnimation leftRightAnimation = new Vector2FromToByAnimation { TargetProperty = "Position", From = new Vector2(bounds.Left + 100, bounds.Center.Y), To = new Vector2(bounds.Right - 100, bounds.Center.Y), Duration = TimeSpan.FromSeconds(2), EasingFunction = new HermiteEase { Mode = EasingMode.EaseInOut }, }; AnimationClip <Vector2> baseAnimation = new AnimationClip <Vector2>(leftRightAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; _baseAnimationController = AnimationService.StartAnimation(baseAnimation, _animatablePosition); _baseAnimationController.UpdateAndApply(); // ----- Create and start the additive animation. Vector2FromToByAnimation upDownAnimation = new Vector2FromToByAnimation { TargetProperty = "Position", From = new Vector2(0, 50), To = new Vector2(0, -50), Duration = TimeSpan.FromSeconds(0.5), EasingFunction = new SineEase { Mode = EasingMode.EaseInOut }, // Set IsAdditive flag. IsAdditive = true, }; AnimationClip <Vector2> additiveAnimation = new AnimationClip <Vector2>(upDownAnimation) { LoopBehavior = LoopBehavior.Oscillate, Duration = TimeSpan.MaxValue, }; // Start animation using "Compose". _additiveAnimationController = AnimationService.StartAnimation( additiveAnimation, _animatablePosition, AnimationTransitions.Compose()); _additiveAnimationController.UpdateAndApply(); }
public void FadeOut() { var property = new AnimatableProperty <float> { Value = 10.0f }; var animation = new SingleFromToByAnimation { From = 100.0f, To = 200.0f, IsAdditive = true, }; var manager = new AnimationManager(); var controller = manager.CreateController(animation, property); Assert.AreEqual(10.0f, property.Value); controller.Start(AnimationTransitions.Compose()); controller.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); // Changing the base value has no effect. manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(110.0f, property.Value); manager.Update(TimeSpan.FromSeconds(1.0)); manager.ApplyAnimations(); Assert.AreEqual(210.0f, property.Value); controller.Stop(TimeSpan.FromSeconds(1.0)); Assert.AreEqual(210.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(110.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(10.0f, property.Value); Assert.AreEqual(AnimationState.Filling, controller.State); manager.Update(TimeSpan.FromSeconds(0.1)); manager.ApplyAnimations(); Assert.AreEqual(10.0f, property.Value); Assert.AreEqual(AnimationState.Stopped, controller.State); }
public void AdditiveAnimation() { var property = new AnimatableProperty <float> { Value = 123.4f }; var manager = new AnimationManager(); // Start base animation. var animation0 = new SingleFromToByAnimation { Duration = TimeSpan.FromSeconds(1.0), To = 234.5f, FillBehavior = FillBehavior.Stop, }; var controller0 = manager.StartAnimation(animation0, property); Assert.AreEqual(123.4f, property.Value); // Start additive animation. var animation1 = new SingleFromToByAnimation { Duration = TimeSpan.FromSeconds(1.0), From = 0.0f, To = 10.0f, IsAdditive = true, FillBehavior = FillBehavior.Hold, }; var controller1 = manager.StartAnimation(animation1, property, AnimationTransitions.Compose()); Assert.AreEqual(123.4f, property.Value); manager.Update(TimeSpan.FromSeconds(1.0)); Assert.AreEqual(123.4f, property.Value); manager.ApplyAnimations(); Assert.AreEqual(234.5f + 10.0f, property.Value); manager.Update(new TimeSpan(166666)); Assert.AreEqual(234.5f + 10.0f, property.Value); manager.ApplyAnimations(); Assert.AreEqual(123.4f + 10.0f, property.Value); // Stop additive animation. controller1.Stop(); controller1.UpdateAndApply(); Assert.AreEqual(123.4f, property.Value); }
public CharacterCrossFadeSample(Microsoft.Xna.Framework.Game game) : base(game) { var modelNode = ContentManager.Load <ModelNode>("Marine/PlayerMarine"); _meshNode = modelNode.GetSubtree().OfType <MeshNode>().First().Clone(); SampleHelper.EnablePerPixelLighting(_meshNode); GraphicsScreen.Scene.Children.Add(_meshNode); Dictionary <string, SkeletonKeyFrameAnimation> animations = _meshNode.Mesh.Animations; // Create a looping 'Idle' animation. _idleAnimation = new AnimationClip <SkeletonPose>(animations["Idle"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Create a looping 'Run' animation. _runAnimation = new AnimationClip <SkeletonPose>(animations["Run"]) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Combine the 'Aim' and 'Shoot' animation. The 'Aim' animation should start immediately. // The 'Shoot' animation should start after 0.3 seconds. // (Animations can be combined by creating timeline groups. All timelines/animations // in a timeline group are played simultaneously. AnimationClips can be used to // arrange animations on a timeline. The property Delay, for example, can be used to // set the begin time.) _aimAndShootAnimation = new TimelineGroup(); _aimAndShootAnimation.Add(animations["Aim"]); _aimAndShootAnimation.Add(new AnimationClip <SkeletonPose>(animations["Shoot"]) { Delay = TimeSpan.FromSeconds(0.3) }); // Start 'Idle' animation. We use a Replace transition with a fade-in. _idleAnimationController = AnimationService.StartAnimation( _idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5))); _idleAnimationController.AutoRecycle(); }
public override void Update(GameTime gameTime) { base.Update(gameTime); // <Space> --> Cross-fade to 'Aim-and-Shoot' animation. if (InputService.IsPressed(Keys.Space, false)) { // Start the new animation using a Replace transition with a fade-in time. _aimAndShootAnimationController = AnimationService.StartAnimation( _aimAndShootAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.1))); _aimAndShootAnimationController.AutoRecycle(); } // <Up> --> Cross-fade to 'Run' animation - unless the 'Aim-and-Shoot' animation is playing // or the 'Run' animation is already playing. if (_aimAndShootAnimationController.State != AnimationState.Playing && _runAnimationController.State != AnimationState.Playing && InputService.IsDown(Keys.Up)) { _runAnimationController = AnimationService.StartAnimation( _runAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.2))); _runAnimationController.AutoRecycle(); } if (_aimAndShootAnimationController.State != AnimationState.Playing) { // If none of the animations are playing, or if the user releases the <Up> key, // then restart the 'Idle' animation. if (_runAnimationController.State != AnimationState.Playing && _idleAnimationController.State != AnimationState.Playing || _runAnimationController.State == AnimationState.Playing && InputService.IsUp(Keys.Up)) { _idleAnimationController = AnimationService.StartAnimation( _idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.2))); _idleAnimationController.AutoRecycle(); } } }
public void Compose() { var property = new AnimatableProperty <float> { Value = 100.0f }; var animationA = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animationA, property); Assert.AreEqual(100.0f, property.Value); controllerA.Start(AnimationTransitions.Compose()); controllerA.UpdateAndApply(); Assert.AreEqual(200.0f, property.Value); var animationB = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 10.0f, }; var controllerB = manager.CreateController(animationB, property); Assert.AreEqual(200.0f, property.Value); controllerB.Start(AnimationTransitions.Compose()); controllerB.UpdateAndApply(); Assert.AreEqual(210.0f, property.Value); controllerA.Stop(); controllerA.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); controllerB.Stop(); controllerB.UpdateAndApply(); Assert.AreEqual(100.0f, property.Value); }
public override void Update(GameTime gameTime) { if (_avatarPose == null) { if (_avatarRenderer.State == AvatarRendererState.Ready) { _avatarPose = new AvatarPose(_avatarRenderer); AnimationService.StartAnimation(_waveAnimation, _avatarPose).AutoRecycle(); } } else if (InputService.IsPressed(Buttons.A, false, LogicalPlayerIndex.One)) { // Restart animation using a cross-fade of 0.5 seconds. AnimationService.StartAnimation(_waveAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.5)) ).AutoRecycle(); } }
public void StartStopAnimationsWithinOneFrame1() { var property = new AnimatableProperty <float> { Value = 123.4f }; var manager = new AnimationManager(); // Start base animation. var animation0 = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 234.5f, FillBehavior = FillBehavior.Stop, }; var controller0 = manager.StartAnimation(animation0, property); controller0.UpdateAndApply(); Assert.AreEqual(234.5f, property.Value); // Start additive animation. var animation1 = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 10.0f, IsAdditive = true, FillBehavior = FillBehavior.Stop, }; var controller1 = manager.StartAnimation(animation1, property, AnimationTransitions.Compose()); controller1.UpdateAndApply(); Assert.AreEqual(234.5f + 10.0f, property.Value); // Stop base animation. controller0.Stop(); controller0.UpdateAndApply(); Assert.AreEqual(123.4f + 10.0f, property.Value); // Stop additive animation. controller1.Stop(); controller1.UpdateAndApply(); Assert.AreEqual(123.4f, property.Value); }
public void Replace() { var property = new AnimatableProperty <float> { Value = 10.0f }; var animation = new SingleFromToByAnimation { From = 100.0f, To = 200.0f, IsAdditive = true, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animation, property); Assert.AreEqual(10.0f, property.Value); controllerA.Start(AnimationTransitions.Replace()); controllerA.UpdateAndApply(); Assert.AreEqual(110.0f, property.Value); // Changing the base value has no effect. property.Value = 20.0f; manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(120.0f, property.Value); // Start second animation using Replace. var controllerB = manager.CreateController(animation, property); Assert.AreEqual(120.0f, property.Value); controllerB.Start(AnimationTransitions.Replace(controllerA.AnimationInstance)); controllerB.UpdateAndApply(); Assert.AreEqual(120.0f, property.Value); controllerB.Stop(); controllerB.UpdateAndApply(); Assert.AreEqual(20.0f, property.Value); }
public void SnapshotFromDelegateAnimatableProperty() { var testObject = new TestObject { Value = 123.4f }; Func <float> getter = () => testObject.Value; Action <float> setter = f => { testObject.Value = f; }; var property = new DelegateAnimatableProperty <float>(getter, setter); var manager = new AnimationManager(); var byAnimation = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 25.0f, }; var controller = manager.StartAnimation(byAnimation, property, AnimationTransitions.SnapshotAndReplace()); controller.UpdateAndApply(); // The DelegateAnimatableProperty<T> does not provide a base value. // --> No snapshot is created. Assert.AreEqual(25.0f, testObject.Value); // 0.0f (SingleTraits.Identity) + 25.0f (By Animation) }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (InputService.IsDown(Keys.Up)) { if (!_isRunning) { _isRunning = true; // Start 'Run' animation. We use a Replace transition and replace the 'Idle' // animation which is the first in the animation composition chain. Since we only // replace one specific animation, the 'Shoot' animation will stay in the composition // chain and keep playing. _runAnimationController = AnimationService.StartAnimation( _runAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(_idleAnimationController.AnimationInstance, TimeSpan.FromSeconds(0.3))); _runAnimationController.AutoRecycle(); } } else { if (_isRunning) { _isRunning = false; // Start 'Idle' animation and replace the 'Run' animation. _idleAnimationController = AnimationService.StartAnimation( _idleAnimation, (IAnimatableProperty)_meshNode.SkeletonPose, AnimationTransitions.Replace(_runAnimationController.AnimationInstance, TimeSpan.FromSeconds(0.3))); _idleAnimationController.AutoRecycle(); } } }
public override void Update(GameTime gameTime) { if (_avatarPose == null) { if (_avatarRenderer.State == AvatarRendererState.Ready) { _avatarPose = new AvatarPose(_avatarRenderer); // Start stand animation. _standAnimationController = AnimationService.StartAnimation(_standAnimation, _avatarPose); _standAnimationController.AutoRecycle(); } } else { // When the user presses buttons, we cross-fade to the custom animations. if (InputService.IsPressed(Buttons.A, false, LogicalPlayerIndex.One)) { _actionAnimationController = AnimationService.StartAnimation( _jumpAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _actionAnimationController.AutoRecycle(); } if (InputService.IsPressed(Buttons.B, false, LogicalPlayerIndex.One)) { _actionAnimationController = AnimationService.StartAnimation( _punchAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _actionAnimationController.AutoRecycle(); } if (InputService.IsPressed(Buttons.X, false, LogicalPlayerIndex.One)) { _actionAnimationController = AnimationService.StartAnimation( _kickAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _actionAnimationController.AutoRecycle(); } if (InputService.IsPressed(Buttons.Y, false, LogicalPlayerIndex.One)) { _actionAnimationController = AnimationService.StartAnimation( _faintAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _actionAnimationController.AutoRecycle(); } // The left trigger controls the speed of the walk cycle. float leftTrigger = Math.Abs(InputService.GetGamePadState(LogicalPlayerIndex.One).Triggers.Left); _walkAnimationController.Speed = leftTrigger * 2; if (_walkAnimationController.State != AnimationState.Playing) { // The walk cycle is not playing. // --> Start walk animation if left trigger is pressed. if (leftTrigger > 0) { _walkAnimationController = AnimationService.StartAnimation( _walkAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _walkAnimationController.AutoRecycle(); } } else { // The walk cycle is playing. // --> Cross-fade to stand animation if left trigger is not pressed. if (leftTrigger == 0) { _standAnimationController = AnimationService.StartAnimation( _standAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _standAnimationController.AutoRecycle(); } } // If none of the animations is playing, then restart the stand animation. if (_standAnimationController.State != AnimationState.Playing && _actionAnimationController.State != AnimationState.Playing && _walkAnimationController.State != AnimationState.Playing) { _standAnimationController = AnimationService.StartAnimation( _standAnimation, _avatarPose, AnimationTransitions.Replace(TimeSpan.FromSeconds(0.3))); _standAnimationController.AutoRecycle(); } } }
public void AnimationShapshots() { var property = new AnimatableProperty <float> { Value = 10.0f }; var manager = new AnimationManager(); var byAnimation = new SingleFromToByAnimation { Duration = TimeSpan.Zero, By = 25.0f, }; var byController = manager.CreateController(byAnimation, property); Assert.AreEqual(10.0f, property.Value); // Without snapshot. byController.Start(AnimationTransitions.Replace()); byController.UpdateAndApply(); Assert.AreEqual(35.0f, property.Value); property.Value = 100.0f; manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(125.0f, property.Value); byController.Stop(); byController.UpdateAndApply(); Assert.AreEqual(100.0f, property.Value); // With snapshot. property.Value = 10.0f; byController.Start(AnimationTransitions.SnapshotAndReplace()); byController.UpdateAndApply(); Assert.AreEqual(35.0f, property.Value); property.Value = 100.0f; manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(35.0f, property.Value); // Create another snapshot. var additiveAnimation = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, IsAdditive = true, }; var additiveController = manager.CreateController(additiveAnimation, property); additiveController.Start(AnimationTransitions.SnapshotAndReplace()); additiveController.UpdateAndApply(); Assert.AreEqual(235.0f, property.Value); byController.Stop(); Assert.AreEqual(235.0f, property.Value); byController.Start(AnimationTransitions.Replace()); byController.UpdateAndApply(); Assert.AreEqual(60.0f, property.Value); // 35.0f (Snapshot) + 25.0f (By Animation) }
public void ReplaceAllWithFadeIn() { var property = new AnimatableProperty <float> { Value = 100.0f }; var animationA = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 200.0f, }; var manager = new AnimationManager(); var controllerA = manager.CreateController(animationA, property); Assert.AreEqual(100.0f, property.Value); controllerA.Start(AnimationTransitions.Replace(TimeSpan.FromSeconds(1.0))); Assert.AreEqual(100.0f, property.Value); // Changing the base value has no effect. property.Value = 150.0f; manager.Update(TimeSpan.Zero); manager.ApplyAnimations(); Assert.AreEqual(150.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(175.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(200.0f, property.Value); // Start second animation using Replace. var animationB = new SingleFromToByAnimation { Duration = TimeSpan.Zero, To = 100.0f, }; var controllerB = manager.CreateController(animationB, property); Assert.AreEqual(200.0f, property.Value); controllerB.Start(AnimationTransitions.Replace(TimeSpan.FromSeconds(1.0))); Assert.AreEqual(200.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(150.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(100.0f, property.Value); manager.Update(TimeSpan.FromSeconds(0.5)); manager.ApplyAnimations(); Assert.AreEqual(100.0f, property.Value); Assert.AreEqual(AnimationState.Stopped, controllerA.State); }
public void FindUIElements() { // Only find if none of the critical UI elements are assigned: if (mainGraphic == null && nameText == null && reticleInRange == null) { var elements = FindObjectOfType<UnityUISelectorElements>(); if (elements == null) { if (DialogueDebug.LogWarnings) Debug.LogWarning("Dialogue System: UnityUISelectorDisplay can't find UI elements", this); } else { if (mainGraphic == null) mainGraphic = elements.mainGraphic; if (nameText == null) nameText = elements.nameText; if (useMessageText == null) useMessageText = elements.useMessageText; inRangeColor = elements.inRangeColor; outOfRangeColor = elements.outOfRangeColor; if (reticleInRange == null) reticleInRange = elements.reticleInRange; if (reticleOutOfRange == null) reticleOutOfRange = elements.reticleOutOfRange; animationTransitions = elements.animationTransitions; } } if (mainGraphic != null) animator = GetComponentInChildren<Animator>(); }