Beispiel #1
0
    /// <summary>
    /// Unregisters the specified animation instance.
    /// </summary>
    /// <param name="animationInstance">The animation instance.</param>
    /// <remarks>
    /// <para>
    /// This method removes the specified animation tree from the animation system. If 
    /// <see cref="AnimationInstance.AutoRecycleEnabled"/> is set on the root node of the animation 
    /// tree, then all instances will be recycled.
    /// </para>
    /// <para>
    /// Adding and removing animation instances is usually controlled by 
    /// <see cref="AnimationTransition"/> instances.
    /// </para>
    /// </remarks>
    /// <exception cref="ArgumentException">
    /// Cannot remove <paramref name="animationInstance"/> from the animation system. The animation 
    /// instance is not a root instance.
    /// </exception>
    internal void Remove(AnimationInstance animationInstance)
    {
      if (!animationInstance.IsRoot)
        throw new ArgumentException("Cannot remove animation instance from animation system because it is not the root instance.");

      // Remove animation instance.
      bool removed = _rootInstances.Remove(animationInstance);
      if (removed)
      {
        // Remove animation transitions, if any.
        StopTransitions(animationInstance);

        // Stop all secondary animations.
        animationInstance.StopSecondaryAnimations(this);

        // Remove animations from composition chains.
        animationInstance.RemoveFromCompositionChains(this);

        // Note: The instances are not unassigned from the properties.
        // Animations can be restart when using an animation controller.
        //animationInstance.Unassign();

        // Reset animation time (State = Stopped).
        animationInstance.Time = null;

        // Recycle instance, if no longer needed.
        if (animationInstance.AutoRecycleEnabled)
        {
          // If the instance is in the completedInstances list, we need to wait 
          // until the Completed events were fired in ApplyAnimations().
          if (!_completedInstances.Contains(animationInstance))
            animationInstance.Recycle();
        }
      }
    }
Beispiel #2
0
        /// <summary>
        /// Recycles the animation instances associated with this controller.
        /// </summary>
        /// <inheritdoc cref="AutoRecycleEnabled"/>
        public void Recycle()
        {
            if (IsValid)
            {
                Stop();
            }

            // Check IsValid again - animation instance might have been recycled automatically.
            if (IsValid)
            {
                _animationInstance.Recycle();
            }
        }