private bool ValidateOutputState(StateNode outState)
        {
            if (subStates.IsNullOrEmpty())
            {
                return(false);
            }

            //Only allow animStateNodes as output
            AnimationStateNode outputAsAnimState = outState as AnimationStateNode;

            if (outputAsAnimState == null)
            {
                return(false);
            }

            //Makes sure output state is present in list
            foreach (var state in subStates)
            {
                if (state == outState)
                {
                    return(true);
                }
            }

            return(false);
        }
 public override void Enter()
 {
     //Check if its anim state node, if so, set is output state
     foreach (var subState in subStates)
     {
         AnimationStateNode subStateAsAnimState = subState as AnimationStateNode;
         if (subStateAsAnimState != null)
         {
             subStateAsAnimState.SetIsStateOutput(subStateAsAnimState == outputState);
             // Debug.Log($"State: {subStateAsAnimState.name} | IsOutput: {subStateAsAnimState == outputState}");
         }
     }
     base.Enter();
 }
예제 #3
0
        public void TransitionToState(AnimationStateNode newState, float transitionTime, AnimationCurve transitionCurve)
        {
            lock (transitioningLock)
            {
                if (transitioning)
                {
                    transitionTween.callOnCompletes();
                    // transitionTween.setOnUpdate((float value) => { }).setOnComplete(() => { });
                    LeanTween.cancel(transitionTween.id);
                }
            }

            mixerRunner.Output.DisconnectInput(0);
            mixerRunner.Output.DisconnectInput(1);
            // if (!mixerPlayable.GetInput(0).IsNull()) mixerPlayable.DisconnectInput(0);
            // if (!mixerPlayable.GetInput(1).IsNull()) mixerPlayable.DisconnectInput(1);

            activeState     = nextActiveState;
            nextActiveState = newState;

            // Debug.Log($"Transition from {activeState?.name} to {nextActiveState?.name}, {newState.Output.IsValid()}, {newState.Output.GetInputCount()}");

            if (nextActiveState)
            {
                mixerRunner.Output.ConnectInput(0, nextActiveState.Output, 0);
            }
            else
            {
                mixerRunner.Output.ConnectInput(0, defaultPlayable, 0);
            }

            if (activeState)
            {
                mixerRunner.Output.ConnectInput(1, activeState.Output, 0);
            }

            mixerRunner.Output.SetInputWeight(0, 1f);
            mixerRunner.Output.SetInputWeight(1, 1f);

            if (nextActiveState != null)
            {
                transitioning = true;
                mixerRunner.SetBlendFromLastPosition(true);

                transitionTween =
                    LeanTween
                    .value(sharedData.Animatable.RootTransform.gameObject, 0f, 1f, transitionTime)
                    .setEase(transitionCurve)
                    .setOnStart(() =>
                {
                    // transitioning = true;
                    // mixerRunner.SetBlendFromLastPosition(true);
                    //Debug.Log($"Start tween from {activeState?.name} to {nextActiveState?.name}");
                })
                    .setOnUpdate((float value) =>
                {
                    mixerRunner.Factor = value;
                    //Debug.Log($"Update tween value {mixerRunner.Factor}");
                })
                    .setOnComplete(() =>
                {
                    lock (transitioningLock)
                    {
                        transitioning = false;
                    }
                    mixerRunner.SetBlendFromLastPosition(false);
                    //Debug.Log($"Complete tween from {activeState?.name} to {nextActiveState?.name}");
                });
            }

            // sharedData.Animatable.playableOutput.SetSourcePlayable(newState.Output);

            // mixerRunner.Factor = 0.0f;
        }