// Animancer // https://kybernetik.com.au/animancer // Copyright 2022 Kybernetik // using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; using Object = UnityEngine.Object; namespace Animancer { /// [Pro-Only] /// An which blends multiple child states. Unlike other mixers, this class does not /// perform any automatic weight calculations, it simple allows you to control the weight of all states manually. /// /// /// This mixer type is similar to the Direct Blend Type in Mecanim Blend Trees. /// The official Direct Blend Trees /// tutorial explains their general concepts and purpose which apply to s as well. /// /// Documentation: Mixers /// /// https://kybernetik.com.au/animancer/api/Animancer/ManualMixerState /// public partial class ManualMixerState : MixerState { /************************************************************************************************************************/ /// An that creates a . public interface ITransition : ITransition { } /************************************************************************************************************************/ #region Properties /************************************************************************************************************************/ /// The states managed by this mixer. private AnimancerState[] _Children = Array.Empty(); /// Returns the array of . public override IList ChildStates => _Children; /************************************************************************************************************************/ /// public override int ChildCount => _Children.Length; /// public override AnimancerState GetChild(int index) => _Children[index]; /// public override FastEnumerator GetEnumerator() => new FastEnumerator(_Children, _Children.Length); /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Initialisation /************************************************************************************************************************/ /// /// Initializes this mixer with the specified number of children which can be set individually by /// and . /// /// will be called on any existing children. public virtual void Initialize(int childCount) { #if UNITY_ASSERTIONS if (childCount <= 1 && OptionalWarning.MixerMinChildren.IsEnabled()) OptionalWarning.MixerMinChildren.Log( $"{this} is being initialized with {nameof(childCount)} <= 1." + $" The purpose of a mixer is to mix multiple child states.", Root?.Component); #endif for (int i = _Children.Length - 1; i >= 0; i--) { var state = _Children[i]; if (state == null) continue; state.Destroy(); } _Children = new AnimancerState[childCount]; if (_Playable.IsValid()) { _Playable.SetInputCount(childCount); } else if (Root != null) { CreatePlayable(); } } /************************************************************************************************************************/ /// Initializes this mixer with one state per clip. public void Initialize(params AnimationClip[] clips) { #if UNITY_ASSERTIONS if (clips == null) throw new ArgumentNullException(nameof(clips)); #endif var count = clips.Length; Initialize(count); for (int i = 0; i < count; i++) { var clip = clips[i]; if (clip != null) CreateChild(i, clip); } } /************************************************************************************************************************/ /// /// Initializes this mixer by calling for each of the /// `states`. /// public void Initialize(params Object[] animations) { #if UNITY_ASSERTIONS if (animations == null) throw new ArgumentNullException(nameof(animations)); #endif var count = animations.Length; Initialize(count); for (int i = 0; i < count; i++) { var state = animations[i]; if (state != null) CreateChild(i, state); } } /************************************************************************************************************************/ #endregion /************************************************************************************************************************/ } }