/// <summary> /// Gathers the current details of the <see cref="AnimancerNode.Root"/> and register this /// <see cref="CustomFade"/> to be updated by it so that it can replace the regular fade behaviour. /// </summary> protected void Apply(AnimancerNode node) { #if UNITY_ASSERTIONS AnimancerUtilities.Assert(node != null, "Node is null."); AnimancerUtilities.Assert(node.IsValid, "Node is not valid."); AnimancerUtilities.Assert(node.FadeSpeed != 0, $"Node is not fading ({nameof(node.FadeSpeed)} is 0)."); var animancer = node.Root; AnimancerUtilities.Assert(animancer != null, $"{nameof(node)}.{nameof(node.Root)} is null."); if (OptionalWarning.CustomFadeBounds.IsEnabled()) { if (CalculateWeight(0) != 0) { OptionalWarning.CustomFadeBounds.Log("CalculateWeight(0) != 0.", animancer.Component); } if (CalculateWeight(1) != 1) { OptionalWarning.CustomFadeBounds.Log("CalculateWeight(1) != 1.", animancer.Component); } } #endif _Time = 0; _Target = new NodeWeight(node); _FadeSpeed = node.FadeSpeed; _Layer = node.Layer; _CommandCount = _Layer.CommandCount; node.FadeSpeed = 0; FadeOutNodes.Clear(); node.Root.RequirePreUpdate(this); }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="CartesianMixerState"/> or <see cref="DirectionalMixerState"/> /// depending on the <see cref="Type"/> connected to the 'layer'. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Serializable{TState}.State"/>. /// </summary> public override MixerState <Vector2> CreateState(AnimancerLayer layer) { switch (_Type) { case MixerType.Cartesian: State = new CartesianMixerState(layer); break; case MixerType.Directional: State = new DirectionalMixerState(layer); break; default: throw new ArgumentOutOfRangeException("_Type"); } InitialiseState(); return(State); }
/// <summary> /// Gather the current details of the <see cref="AnimancerNode.Root"/> and register this /// <see cref="CustomFade"/> to be updated by it so that it can replace the regular fade behaviour. /// </summary> protected void Apply(AnimancerState state) { #if UNITY_ASSERTIONS Debug.Assert(state != null, "State is null."); Debug.Assert(state.IsValid, "State is not valid."); Debug.Assert(state.IsPlaying, "State is not playing."); Debug.Assert(state.LayerIndex >= 0, "State is not connected to a layer."); Debug.Assert(state.TargetWeight > 0, "State is not fading in."); var animancer = state.Root; Debug.Assert(animancer != null, $"{nameof(state)}.{nameof(state.Root)} is null."); #if UNITY_EDITOR if (WarningType.CustomFadeBounds.IsEnabled()) { if (CalculateWeight(0) != 0) { WarningType.CustomFadeBounds.Log("CalculateWeight(0) != 0.", animancer.Component); } if (CalculateWeight(1) != 1) { WarningType.CustomFadeBounds.Log("CalculateWeight(1) != 1.", animancer.Component); } } #endif #endif _FadeSpeed = state.FadeSpeed; if (_FadeSpeed == 0) { return; } _Time = 0; _TargetState = new StateWeight(state); _TargetLayer = state.Layer; _CommandCount = _TargetLayer.CommandCount; OtherStates.Clear(); for (int i = _TargetLayer.ChildCount - 1; i >= 0; i--) { var other = _TargetLayer.GetChild(i); other.FadeSpeed = 0; if (other != state && other.Weight != 0) { OtherStates.Add(new StateWeight(other)); } } state.Root.RequireUpdate(this); }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="LinearMixerState"/> connected to the 'layer'. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Serializable{TState}.State"/>. /// </summary> public override LinearMixerState CreateState(AnimancerLayer layer) { State = new LinearMixerState(layer); InitialiseState(); return(State); }
/// <summary> /// Constructs a new <see cref="MixerState"/> and connects it to the 'layer's /// <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from previously destroyed /// states, or by adding a new port. /// </summary> public MixerState(AnimancerLayer layer) : this(layer.Root) { layer.AddChild(this); }
/// <summary> /// Creates and returns a new <typeparamref name="TState"/> connected to the 'layer'. /// <para></para> /// This method also assigns it as the <see cref="State"/> (which must be done manually when overriding /// this method). /// </summary> public abstract TState CreateState(AnimancerLayer layer);
/// <summary> /// Constructs a new <see cref="DirectionalMixerState"/> and connects it to the 'layer's /// <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from previously destroyed /// states, or by adding a new port. /// </summary> public DirectionalMixerState(AnimancerLayer layer) : base(layer) { }
/// <summary> /// Constructs a new <see cref="Float3ControllerState"/> to play the `controller` and connects it to the /// the `layer`. /// </summary> public Float3ControllerState(AnimancerLayer layer, RuntimeAnimatorController controller, Parameter parameterX, Parameter parameterY, Parameter parameterZ, bool resetStatesOnStop = true) : this(layer.Root, controller, parameterX, parameterY, parameterZ, resetStatesOnStop) { layer.AddChild(this); }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="Vector3ControllerState"/> connected to the 'layer'. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Serializable{TState}.State"/>. /// </summary> public override Vector3ControllerState CreateState(AnimancerLayer layer) { return(State = new Vector3ControllerState(layer, Controller, _ParameterNameX, _ParameterNameY, _ParameterNameZ)); }
/// <summary> /// Constructs a new <see cref="Vector3ControllerState"/> to play the 'controller' and /// connects it to the 'layer's <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from /// previously destroyed states, or by adding a new port. /// </summary> public Vector3ControllerState(AnimancerLayer layer, RuntimeAnimatorController controller, Parameter parameterX, Parameter parameterY, Parameter parameterZ) : this(layer.Root, controller, parameterX, parameterY, parameterZ) { layer.AddChild(this); }
/// <summary> /// Constructs a new <see cref="PlayableAssetState"/> to play the `asset` and connects it to a new port on the /// `layer`s <see cref="Playable"/>. /// </summary> public PlayableAssetState(AnimancerLayer layer, PlayableAsset asset) : this(layer.Root, asset) { layer.AddChild(this); }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="PlayableAssetState"/> connected to the `layer`. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Transition{TState}.State"/>. /// </summary> public override PlayableAssetState CreateState(AnimancerLayer layer) { return(State = new PlayableAssetState(layer, _Asset)); }
/// <summary> /// Constructs a new <see cref="ControllerState"/> to play the 'animatorController' and connects it to /// the 'layer's <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from previously /// destroyed states, or by adding a new port. /// </summary> public ControllerState(AnimancerLayer layer, RuntimeAnimatorController animatorController) : this(layer.Root, animatorController) { layer.AddChild(this); }
/// <summary>Wraps <see cref="ITransition.CreateState"/>.</summary> public AnimancerState CreateState(AnimancerLayer layer) { return(GetTransition().CreateState(layer)); }
/// <summary> /// Constructs a new <see cref="LinearMixerState"/> and connects it to the 'layer's /// <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from previously destroyed /// states, or by adding a new port. /// </summary> public LinearMixerState(AnimancerLayer layer) : base(layer) { }
/// <summary> /// Constructs a new <see cref="LinearMixerState"/> and connects it to the `layer`. /// </summary> public ManualMixerState(AnimancerLayer layer) : base(layer) { }
/// <summary> /// Constructs a new <see cref="CartesianMixerState"/> and connects it to the 'layer's /// <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from previously destroyed /// states, or by adding a new port. /// </summary> public CartesianMixerState(AnimancerLayer layer) : base(layer) { }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="Float3ControllerState"/> connected to the `layer`. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Transition{TState}.State"/>. /// </summary> public override Float3ControllerState CreateState(AnimancerLayer layer) { return(new Float3ControllerState(layer, Controller, _ParameterNameX, _ParameterNameY, _ParameterNameZ, KeepStateOnStop)); }
/// <summary> /// Constructs a new <see cref="ControllerState"/> to play the `animatorController` and connects it to /// the `layer`. /// </summary> public ControllerState(AnimancerLayer layer, RuntimeAnimatorController animatorController, bool keepStateOnStop = false) : this(layer.Root, animatorController, keepStateOnStop) { layer.AddChild(this); }
/// <summary> /// Creates and returns a new <typeparamref name="TState"/> connected to the 'layer'. /// </summary> public AnimancerState CreateState(AnimancerLayer layer) { return(_Animation.CreateState(layer)); }
/************************************************************************************************************************/ /// <summary> /// Creates and returns a new <see cref="FloatControllerState"/> connected to the 'layer'. /// <para></para> /// This method also assigns it as the <see cref="AnimancerState.Serializable{TState}.State"/>. /// </summary> public override FloatControllerState CreateState(AnimancerLayer layer) { return(State = new FloatControllerState(layer, Controller, _ParameterName)); }
/// <summary>Creates and returns a new <typeparamref name="TState"/> connected to the 'layer'.</summary> AnimancerState IAnimancerTransition.CreateState(AnimancerLayer layer) { return(CreateState(layer)); }
/// <summary> /// Constructs a new <see cref="FloatControllerState"/> to play the 'controller' and connects /// it to the 'layer's <see cref="IAnimationMixer.Playable"/> using a spare port if there are any from /// previously destroyed states, or by adding a new port. /// </summary> public FloatControllerState(AnimancerLayer layer, RuntimeAnimatorController controller, Parameter parameter) : this(layer.Root, controller, parameter) { layer.AddChild(this); }