Example #1
0
        public SelectionWheelObjectAnimation(SelectionWheelGameObject SelectionWheelGameObject, AnimationClip enterTransitionAnimationClip, Action OnExitAnimationCompleted)
        {
            SelectionWheelObjectAnimationVariables = new Dictionary <SelectionWheelObjectAnimationVarableType, BoolVariable>()
            {
                { SelectionWheelObjectAnimationVarableType.OpenAnimation, new BoolVariable(false, OnOpenAnimationStarted) },
                {
                    SelectionWheelObjectAnimationVarableType.CloseAnimation, new BoolVariable(false, OnCloseAnimationStarted, () =>
                    {
                        OnCloseAnimationFinished();
                        OnExitAnimationCompleted.Invoke();
                    })
                }
            };

            AnimationGraph = PlayableGraph.Create(GetType().Name);
            AnimationGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

            EnterTransitionAnimationClipPlayable = AnimationClipPlayable.Create(AnimationGraph, enterTransitionAnimationClip);
            EnterTransitionAnimationClipPlayable.SetApplyFootIK(false);
            EnterTransitionAnimationClipPlayable.Pause();
            var animationGraphPlayableOutput = AnimationPlayableOutput.Create(AnimationGraph, "Animation", SelectionWheelGameObject.Animator);

            animationGraphPlayableOutput.SetSourcePlayable(EnterTransitionAnimationClipPlayable);

            AnimationGraph.Play();
        }
Example #2
0
 //次のアニメーションのプレイアブル作成
 private void SetNextAnimationPlayable()
 {
     if (setPlayAnimation != null && playableGraph.IsValid())
     {
         if (mixer.IsValid())
         {
             playableGraph.Disconnect(mixer, 0);
             playableGraph.Disconnect(mixer, 1);
         }
         else
         {
             mixer = AnimationMixerPlayable.Create(playableGraph, 2, true);
             var output = AnimationPlayableOutput.Create(playableGraph, "output", GetComponent <Animator>());
             output.SetSourcePlayable(mixer);
         }
         if (_beforePlayAnimation.IsValid())
         {
             _beforePlayAnimation.Destroy();
         }
         if (_nowPlayAnimation.IsValid())
         {
             _beforePlayAnimation = _nowPlayAnimation;
         }
         //今のアニメーションに設定
         nowPlayAnimation   = setPlayAnimation;
         _beforeNowPlayClip = nowPlayAnimation;
         setPlayAnimation   = null;
         //アニメーションプレイアブル作成
         _nowPlayAnimation = AnimationClipPlayable.Create(playableGraph, nowPlayAnimation);
         mixer.ConnectInput(0, _nowPlayAnimation, 0);
         mixer.ConnectInput(1, _beforePlayAnimation, 0);
     }
 }
Example #3
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Jump settings)
        {
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            m_additiveMixer = AnimationLayerMixerPlayable.Create(graph);

            m_animJump = AnimationClipPlayable.Create(graph, settings.animJump);
            m_animJump.SetApplyFootIK(true);
            m_animJump.SetDuration(settings.animJump.length);
            m_animJump.Pause();
            int port = m_additiveMixer.AddInput(m_animJump, 0);

            m_additiveMixer.SetLayerAdditive((uint)port, false);
            m_additiveMixer.SetInputWeight(port, 1);

            // Adjust play speed so vertical velocity in animation is matched with character velocity (so feet doesnt penetrate ground)
            var animJumpVel      = settings.jumpHeight / settings.animJump.length;
            var characterJumpVel = Game.config != null ? Game.config.jumpAscentHeight / Game.config.jumpAscentDuration : animJumpVel;

            playSpeed = characterJumpVel / animJumpVel;


            // Aim
            //m_aimHandler = new AimVerticalHandler(m_additiveMixer, settings.animAimDownToUp);
        }
Example #4
0
        /// <summary>
        /// Use animation Playables API to control keyed values, blended between the first frame of 2 animation clips.
        /// </summary>
        /// <param name="valueForAdaptationCurve">A value to evaluate into adaptation curve producing a real blend value for 2 clips.</param>
        /// <param name="animator">The control target for animation playables. The clips used must be able to control the keyed fields traveling down from this animator component.</param>
        public void Adapt(float valueForAdaptationCurve, Animator animator)
        {
            if (!Adaptable)
            {
                return;
            }

            float blend = adaptationCurve.Evaluate(valueForAdaptationCurve);

            //Connect up a playable graph, evaluate once, then we're done with them.
            PlayableGraph pg = PlayableGraph.Create("AdaptationGraph");

            pg.SetTimeUpdateMode(DirectorUpdateMode.Manual);

            var mixer = AnimationMixerPlayable.Create(pg, 2, normalizeWeights: true);

            //Not sure if the mixer should be "cross fade" like this, or should we do 0~1 weight over 1 weight?
            //But I think that's for AnimationLayerMixerPlayable ?
            mixer.SetInputWeight(inputIndex: 0, weight: 1 - blend);
            mixer.SetInputWeight(inputIndex: 1, weight: blend);


            var normalStateAcp       = AnimationClipPlayable.Create(pg, normalState);
            var fullyAdaptedStateAcp = AnimationClipPlayable.Create(pg, fullyAdaptedState);

            pg.Connect(normalStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 0);
            pg.Connect(fullyAdaptedStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 1);

            var output = AnimationPlayableOutput.Create(pg, "AdaptationGraphOutput", animator);

            output.SetSourcePlayable(mixer);

            pg.Evaluate();
            pg.Destroy();
        }
Example #5
0
    public void Configure(Animator animator, EnemyAnimationConfig config)
    {
        graph = PlayableGraph.Create();
        graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        mixer = AnimationMixerPlayable.Create(graph, 4);

        var clip = AnimationClipPlayable.Create(graph, config.Move);

        clip.Pause();
        mixer.ConnectInput((int)Clip.Move, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Intro);
        clip.SetDuration(config.Intro.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Intro, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Outro);
        clip.SetDuration(config.Outro.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Outro, clip, 0);

        clip = AnimationClipPlayable.Create(graph, config.Dying);
        clip.SetDuration(config.Dying.length);
        clip.Pause();
        mixer.ConnectInput((int)Clip.Dying, clip, 0);

        var output = AnimationPlayableOutput.Create(graph, "Enemy", animator);

        output.SetSourcePlayable(mixer);
    }
Example #6
0
 protected override void OnMixer(float time, MixClip mix)
 {
     if (mixPlayable.IsValid())
     {
         if (!mix.connect || !Application.isPlaying)
         {
             XAnimationClip clipA = (XAnimationClip)mix.blendA;
             XAnimationClip clipB = (XAnimationClip)mix.blendB;
             if (clipA && clipB)
             {
                 mixA = clipA.playable;
                 mixB = clipB.playable;
             }
         }
         mix.connect = true;
         float weight = (time - mix.start) / mix.duration;
         if (mixA.IsValid() && mixB.IsValid())
         {
             mixJob.weight = weight;
             mixPlayable.SetJobData(mixJob);
         }
         else
         {
             string tip = "playable invalid while animating mix ";
             Debug.LogError(tip + mixA.IsValid() + " " + mixB.IsValid());
         }
     }
 }
Example #7
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings)
            {
                m_Settings       = settings;
                m_AnimState      = controller.GetComponent <AnimStateData>();
                m_PredictedState = controller.GetComponent <LogicStateData>();

                m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform");

                m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

                m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
                graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle);
                m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

                m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL);
                m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR);

                var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

                m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports);

                if (settings.animTurnL.events.Length != 0)
                {
                    m_LeftTurnFootFalls  = ExtractFootFalls(settings.animTurnL);
                    m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR);
                }

                var animator  = controller.GetComponent <Animator>();
                var skeleton  = controller.GetComponent <Skeleton>();
                var leftToes  = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())];
                var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())];

                var ikJob = new FootIkJob
                {
                    settings = settings.footIK,
                    leftToe  = animator.BindStreamTransform(leftToes),
                    rightToe = animator.BindStreamTransform(rightToes)
                };

                m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
                graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0);
                m_FootIk.SetInputWeight(0, 1f);

                m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

                m_AnimAimLeft  = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft);
                m_AnimAimMid   = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid);
                m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight);

                m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph);

                var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0);

                m_AdditiveMixer.SetInputWeight(locoMixerPort, 1);

                var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0);

                m_AdditiveMixer.SetInputWeight(aimMixerPort, 1);
                m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true);
            }
    public void SetState(AnimationClip clip, AvatarMask mask, float weight, float time, float speed)
    {
        if (clip.GetHashCode() == this.currentStateHash)
        {
            this.targetWeight = 1.0f - weight;
            this.smoothTime   = time;

            Playable input = this.mixer.GetInput(0);
            if (input.IsValid())
            {
                input.SetSpeed(speed);
            }
        }
        else
        {
            this.currentStateHash = clip.GetHashCode();
            this.SetState(
                (clip == null ? Playable.Null : AnimationClipPlayable.Create(this.graph, clip)),
                mask,
                weight,
                time,
                speed
                );
        }
    }
    // PUBLIC METHODS: ----------------------------------------------------------------------------

    public virtual void PlayGesture(AnimationClip clip, AvatarMask avatarMask, float speed,
                                    float transitionIn = TRANSITION, float transitionOut = TRANSITION)
    {
        if (clip == null)
        {
            return;
        }

        this.gesturePlayable = AnimationClipPlayable.Create(this.graph, clip);
        this.gesturePlayable.SetTime(0f);
        this.gesturePlayable.SetSpeed(speed);
        this.gesturePlayable.SetDuration(clip.length);

        this.graph.Disconnect(this.mixer, 1);
        this.graph.Connect(this.gesturePlayable, 0, this.mixer, 1);

        this.mixer.SetInputWeight(0, 1.0f);
        this.mixer.SetInputWeight(1, 0.0f);
        this.mixer.SetLayerMaskFromAvatarMask(1, avatarMask);

        this.gesturePlaying       = true;
        this.gestureDuration      = clip.length;
        this.gestureTransitionIn  = transitionIn;
        this.gestureTransitionOut = transitionOut;
    }
        public void Init(PlayableGraph graph, bool enable, float weight)
        {
            if (clip == null)
            {
                return;
            }

            if (graph.IsValid())
            {
                clipPlayable = AnimationClipPlayable.Create(graph, clip);
                if (!clip.isLooping)
                {
                    clipPlayable.SetDuration(clip.length);
                }
                clipPlayable.SetApplyFootIK(applyFootIK);
                clipPlayable.SetApplyPlayableIK(applyPlayableIK);
            }
            duration = clip.length;

            this.enable      = enable;
            this.enableDirty = false;
            this.weight      = weight;
            this.weightDirty = false;
            this.fading      = false;
            this.fadeSpeed   = 0.0f;
            this.isLooping   = clip.isLooping;
        }
Example #11
0
    public void Initialize()
    {
        if (this.initialized)
        {
            return;
        }

        this.animator = this.GetComponent <Animator>();

        Debug.Assert(this.animationClip != null && this.animationClip[0] != null, "No Animation Clips !");
        Debug.Assert(this.animator.runtimeAnimatorController == null, "AnimationController is set......");

        this.graph = PlayableGraph.Create("Animation Player");
        this.graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

        this.output = AnimationPlayableOutput.Create(this.graph, this.name, this.animator);

        this.clips = new AnimationClipPlayable[this.animationClip.Length];
        for (int i = 0; i < this.animationClip.Length; ++i)
        {
            this.clips[i] = AnimationClipPlayable.Create(this.graph, this.animationClip[i]);
            this.clips[i].SetApplyFootIK(false);
            this.clips[i].SetApplyPlayableIK(false);
        }

        this.initialized = true;
    }
Example #12
0
    public BlendTree2dSimpleDirectional(PlayableGraph graph, List <BlendSpaceNode> nodes)
    {
        m_Nodes = nodes;
        var count = m_Nodes.Count;

        m_Positions = new Vector2[count];
        m_Clips     = new AnimationClipPlayable[count];
        m_Weights   = new float[count];

        m_Mixer = AnimationMixerPlayable.Create(graph, count);
        m_Mixer.SetPropagateSetTime(true);

        for (var i = 0; i < count; i++)
        {
            var node = m_Nodes[i];
            var clip = AnimationClipPlayable.Create(graph, node.clip);
            node.clipLength = node.clip.length;
            clip.Play();
            m_Mixer.ConnectInput(i, clip, 0);
            m_Clips[i] = clip;
            m_Nodes[i] = node;
        }

        masterSpeed = 1f;
        SetBlendPosition(new Vector2(0f, 0f));
    }
Example #13
0
 public void SetAnimation(AnimationClip clip)
 {
     _clip   = AnimationClipPlayable.Create(_graph, clip);
     _output = AnimationPlayableOutput.Create(_graph, "output", _animator);
     _output.SetSourcePlayable(_clip);
     _clipTotalTime = (int)clip.length;
 }
Example #14
0
        public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers,
                                                  Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers, Dictionary <string, float> blendVars)
        {
            var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true);

            if (blendTree.Count == 0)
            {
                return(treeMixer);
            }

            Action <float> setVar1    = val => blendVars[blendVariable] = val;
            Action <float> setVar2    = val => blendVars[blendVariable2] = val;
            var            controller = new BlendTreeController2D(blendVariable, blendVariable2, treeMixer, blendTree.Count, setVar1, setVar2);

            varTo2DBlendControllers.GetOrAdd(blendVariable).Add(controller);
            varTo2DBlendControllers.GetOrAdd(blendVariable2).Add(controller);
            blendVars[blendVariable]  = 0;
            blendVars[blendVariable2] = 0;

            for (int j = 0; j < blendTree.Count; j++)
            {
                var blendTreeEntry = blendTree[j];
                var clipPlayable   = AnimationClipPlayable.Create(graph, blendTreeEntry.clip);
                clipPlayable.SetSpeed(speed);
                graph.Connect(clipPlayable, 0, treeMixer, j);

                controller.Add(j, blendTreeEntry.threshold1, blendTreeEntry.threshold2);
            }

            treeMixer.SetInputWeight(0, 1f);
            return(treeMixer);
        }
Example #15
0
 public void Initial(ClipData data, int port)
 {
     this.port = port;
     anData    = data as AnimClipData;
     aclip     = XResources.LoadSharedAsset <AnimationClip>(anData.anim);
     playable  = AnimationClipPlayable.Create(XTimeline.graph, aclip);
 }
Example #16
0
        public TwoDBlendTree(int layerId, PlayableGraph PlayableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable,
                             TwoDAnimationInput TwoDAnimationInput) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            this.TwoDAnimationInput                   = TwoDAnimationInput;
            this.TwoDBlendTreeAnimationClips          = TwoDAnimationInput.TwoDBlendTreeAnimationClipInputs.ConvertAll(i => new TwoDBlendTreeAnimationClip(i.AnimationClip, i.TreePosition, i.Speed));
            this.TwoDBlendTreeAnimationClipsPositions = this.TwoDBlendTreeAnimationClips.ConvertAll(c => c.TreePosition).ToArray();
            this.Weights = new float[this.TwoDBlendTreeAnimationClipsPositions.Length];

            //create a playable mixer
            this.AnimationMixerPlayable = AnimationMixerPlayable.Create(PlayableGraph);

            foreach (var TwoDBlendTreeAnimationClip in TwoDBlendTreeAnimationClips)
            {
                var animationClipPlayable = AnimationClipPlayable.Create(PlayableGraph, TwoDBlendTreeAnimationClip.AnimationClip);
                animationClipPlayable.SetApplyFootIK(false);
                animationClipPlayable.SetApplyPlayableIK(false);
                animationClipPlayable.SetSpeed(TwoDBlendTreeAnimationClip.Speed);
                TwoDBlendTreeAnimationClip.InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, animationClipPlayable, 0);
                PlayableExtensions.Play(animationClipPlayable);
                TwoDBlendTreeAnimationClip.AnimationClipPlayable = animationClipPlayable;
            }

            this.Inputhandler = PlayableExtensions.AddInput(parentAnimationLayerMixerPlayable, this.AnimationMixerPlayable, 0);
            if (TwoDAnimationInput.AvatarMask != null)
            {
                parentAnimationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)this.Inputhandler, TwoDAnimationInput.AvatarMask);
            }
        }
Example #17
0
    AnimationStateInfo DoAddState(string name, AnimationClip clip, Dictionary <string, Action <object> > eventDic = null)
    {
        AnimationStateInfo newState = mStateInfoManager.InsertState();

        newState.Init(name, clip, clip.wrapMode, eventDic);

        int index = newState.Index;

        if (index == mMixerPlayable.GetInputCount())
        {
            mMixerPlayable.SetInputCount(index + 1);
        }

        var clipPlayable = AnimationClipPlayable.Create(mGraph, clip);

        clipPlayable.SetApplyFootIK(false);
        clipPlayable.SetApplyPlayableIK(false);
        if (!clip.isLooping || newState.WrapMode == WrapMode.Once)
        {
            clipPlayable.SetDuration(clip.length);
        }

        newState.SetPlayable(clipPlayable);
        newState.Pause();

        if (mIsKeepStoppedPlayablesConnected)
        {
            ConnectInput(newState.Index);
        }

        return(newState);
    }
Example #18
0
        public AnimationClipPlayable Play(AnimationClip clip, float transition = 0, int toLayer = 0)
        {
            var playable = AnimationClipPlayable.Create(_playableGraph, clip);

            int inputIndex;

            if (AnimationPlayLayers.Length > 1)
            {
                var animationMixerPlayable = (AnimationMixerPlayable)layerMixerPlayable.GetInput(toLayer);
                inputIndex = GetInputIndex(animationMixerPlayable);
                _playableGraph.Connect(playable, 0, animationMixerPlayable, inputIndex);
            }
            else
            {
                if (AnimationClipIsPlaying(mixerPlayable, clip, out var playingPlayable))
                {
                    return(playingPlayable);
                }
                inputIndex = GetInputIndex(mixerPlayable);
                var layer = AnimationPlayLayers[toLayer];
                layer.Add(inputIndex, transition);
                _playableGraph.Connect(playable, 0, mixerPlayable, inputIndex);
                if (layer.bInputIndex == -1)
                {
                    mixerPlayable.SetInputWeight(layer.aInputIndex, 1f);
                }
            }
            return(playable);
        }
Example #19
0
    private StateInfo DoAddClip(string name, AnimationClip clip)
    {
        //Start new State
        StateInfo newState = m_States.InsertState();

        newState.stateName = name;
        newState.clip      = clip;
        newState.wrapMode  = clip.wrapMode;
        //Find at which input the state will be connected
        int index = newState.index;

        //Increase input count if needed
        if (index == m_Mixer.GetInputCount())
        {
            m_Mixer.SetInputCount(index + 1);
        }

        newState.playable = AnimationClipPlayable.Create(graph, clip);
        if (!clip.isLooping || newState.wrapMode == WrapMode.Once)
        {
            newState.playable.SetDuration(clip.length);
            newState.playable.SetPlayState(PlayState.Paused);
        }

        if (keepStoppedPlayablesConnected)
        {
            ConnectInput(newState.index);
        }

        return(newState);
    }
    public ActionAnimationHandler(AnimationLayerMixerPlayable mixer, ActionAnimationDefinition[] actionAnimationDefs)
    {
        if (actionAnimationDefs == null)
        {
            return;
        }

        m_mixer = mixer;
        foreach (var def in actionAnimationDefs)
        {
            if (def.animation == null)
            {
                continue;
            }

            if (m_actionAnimations.ContainsKey(def.action))
            {
                continue;
            }

            ActionAnimation actionAnim = new ActionAnimation();
            actionAnim.animation = AnimationClipPlayable.Create(mixer.GetGraph(), def.animation);
            actionAnim.animation.SetApplyFootIK(false);
            actionAnim.animation.SetDuration(def.animation.length);
            actionAnim.port = mixer.AddInput(actionAnim.animation, 0);
            actionAnim.restartTimeOffset = def.restartTimeOffset;
            mixer.SetLayerAdditive((uint)actionAnim.port, true);
            m_actionAnimations.Add(def.action, actionAnim);
        }
    }
Example #21
0
    private StateInfo DoAddClip(string name, AnimationClip clip)
    {
        //Start new State
        StateInfo newState = m_States.InsertState();

        newState.Initialize(name, clip, clip.wrapMode);
        //Find at which input the state will be connected
        int index = newState.index;

        //Increase input count if needed
        if (index == m_Mixer.GetInputCount())
        {
            m_Mixer.SetInputCount(index + 1);
        }

        var clipPlayable = AnimationClipPlayable.Create(graph, clip);

        clipPlayable.SetApplyFootIK(false);
        clipPlayable.SetApplyPlayableIK(false);
        if (!clip.isLooping || newState.wrapMode == WrapMode.Once)
        {
            clipPlayable.SetDuration(clip.length);
        }
        newState.SetPlayable(clipPlayable);
        newState.Pause();

        if (keepStoppedPlayablesConnected)
        {
            ConnectInput(newState.index);
        }

        return(newState);
    }
Example #22
0
        internal static Playable CreatePlayable(PlayableGraph graph, AnimationClip clip, Vector3 positionOffset, Vector3 eulerOffset, bool removeStartOffset, AppliedOffsetMode mode, bool applyFootIK, LoopMode loop)
        {
            if (clip == null || clip.legacy)
            {
                return(Playable.Null);
            }


            var clipPlayable = AnimationClipPlayable.Create(graph, clip);

            clipPlayable.SetRemoveStartOffset(removeStartOffset);
            clipPlayable.SetApplyFootIK(applyFootIK);
            clipPlayable.SetOverrideLoopTime(loop != LoopMode.UseSourceAsset);
            clipPlayable.SetLoopTime(loop == LoopMode.On);

            Playable root = clipPlayable;

            if (ShouldApplyScaleRemove(mode))
            {
                var removeScale = AnimationRemoveScalePlayable.Create(graph, 1);
                graph.Connect(root, 0, removeScale, 0);
                removeScale.SetInputWeight(0, 1.0f);
                root = removeScale;
            }

            if (ShouldApplyOffset(mode, clip))
            {
                var offsetPlayable = AnimationOffsetPlayable.Create(graph, positionOffset, Quaternion.Euler(eulerOffset), 1);
                graph.Connect(root, 0, offsetPlayable, 0);
                offsetPlayable.SetInputWeight(0, 1.0F);
                root = offsetPlayable;
            }

            return(root);
        }
Example #23
0
    PlayableGraph CreatePlayableGraph()
    {
        // Create a Mixer.
        PlayableGraph g = animator.playableGraph;

        //var playableOutput = AnimationPlayableOutput.Create(g, "AnimationOutput", animator);

        mixerPlayable = AnimationMixerPlayable.Create(g, AnimationMapping.Length + 1);

        // Create a 'neutral' playable with low weight
        var neutral = AnimationClipPlayable.Create(g, NeutralAnimation);

        g.Connect(neutral, 0, mixerPlayable, 0);
        // Create a playable for every AffdexPlayable and connect inputs to the Mixer
        for (int i = 0; i < AnimationMapping.Length; i++)
        {
            var playable = AnimationClipPlayable.Create(g, AnimationMapping[i].CubismExpression);
            Debug.Log("Connection: " + i + 1);
            g.Connect(playable, 0, mixerPlayable, i + 1);
        }

        if (AttemptLayerMix)
        {
            AttachMixerToLayerMixer(mixerPlayable, g);
        }
        else
        {
            AttachMixerToAnimationPlayableOutput(mixerPlayable, g);
        }
        g.Play();
        GraphVisualizerClient.Show(g, "Affdex");
        rawWeights = new float[AnimationMapping.Length];
        return(g);
    }
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_DamageReaction settings)
        {
            m_settings      = settings;
            m_graph         = graph;
            m_EntityManager = entityManager;
            m_Owner         = owner;

            m_rootMixer = AnimationLayerMixerPlayable.Create(graph, 2);
            m_rootMixer.SetInputWeight(0, 1f);

            // Setup blend mixer
            m_blendMixer = AnimationMixerPlayable.Create(graph, 4);
            GameDebug.Assert(m_settings.clips != null && m_settings.clips.Length > 0, "No animation clips added to damagereaction settings:{0}", settings.name);
            for (var i = 0; i < m_settings.clips.Length; i++)
            {
                var clipPlayable = AnimationClipPlayable.Create(graph, m_settings.clips[i]);
                clipPlayable.SetApplyFootIK(false);
                clipPlayable.Pause();
                graph.Connect(clipPlayable, 0, m_blendMixer, i);

                if (m_settings.clips[i].length > m_reactionAnimDuration)
                {
                    m_reactionAnimDuration = m_settings.clips[i].length;
                }
            }
            m_reactionAnimAngleSpan = 360 / m_blendMixer.GetInputCount();
            graph.Connect(m_blendMixer, 0, m_rootMixer, m_blendMixerPort);
            m_rootMixer.SetLayerAdditive(m_blendMixerPort, true);
        }
Example #25
0
        /************************************************************************************************************************/
#endif
        /************************************************************************************************************************/

        /// <summary>
        /// Called by Unity when this component is first created.
        /// <para></para>
        /// Initialises everything needed to play the <see cref="Clip"/>.
        /// </summary>
        private void Awake()
        {
            if (_Clip == null || _Animator == null)
            {
                return;
            }

            if (_Graph.IsValid())
            {
                _Graph.Destroy();
            }

            _Playable = AnimationPlayableUtilities.PlayClip(_Animator, _Clip, out _Graph);

            _Playable.SetSpeed(_Speed);

            if (!_FootIK)
            {
                _Playable.SetApplyFootIK(false);
            }

            if (!_Clip.isLooping)
            {
                _Playable.SetDuration(_Clip.length);
            }
        }
Example #26
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_Simple settings)
        {
            m_EntityManager = entityManager;
            m_Owner         = owner;

            m_layerMixer = AnimationLayerMixerPlayable.Create(graph);
            int port;

            // Idle
            m_animIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
            m_animIdle.SetApplyFootIK(settings.idleFootIKActive);
            port = m_layerMixer.AddInput(m_animIdle, 0);
            m_layerMixer.SetInputWeight(port, 1.0f);

            // Aim
            if (settings.animAimDownToUp != null)
            {
                m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp);
            }

            // Actions
            m_actionMixer = AnimationLayerMixerPlayable.Create(graph);
            port          = m_actionMixer.AddInput(m_layerMixer, 0);
            m_actionMixer.SetInputWeight(port, 1);
            m_actionAnimationHandler = new ActionAnimationHandler(m_actionMixer, settings.actionAnimations);
        }
Example #27
0
        private void ProgressThroughSequenceFrom(int currentClipIndex, ref AnimationClipPlayable runtimePlayable, ref double timeLastFrame)
        {
            var currentClipTime     = runtimePlayable.GetTime();
            var currentClipDuration = ClipsToUse[currentClipIndex].length;

            if (currentClipTime < currentClipDuration)
            {
                return;
            }

            if (indexOfPlayedClip == ClipsToUse.Count - 1 && loopMode == SequenceLoopMode.DontLoop)
            {
                return;
            }

            indexOfPlayedClip = (currentClipIndex + 1) % ClipsToUse.Count;

            var timeToPlayNextClipAt = currentClipTime - currentClipDuration;

            timeLastFrame -= currentClipDuration;
            SwapPlayedClipTo(ref runtimePlayable, ClipsToUse[indexOfPlayedClip], timeToPlayNextClipAt);

            // recurse in case we've got a really long delta time or a really short clip, and have to jump past two clips.
            ProgressThroughSequenceFrom(indexOfPlayedClip, ref runtimePlayable, ref timeLastFrame);
        }
Example #28
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_InAir settings)
        {
            m_settings       = settings;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            GameDebug.Assert(entityManager.HasComponent <Character>(m_AnimStateOwner), "Owner has no Character component");
            m_character = entityManager.GetComponentObject <Character>(m_AnimStateOwner);

            m_mainMixer = AnimationMixerPlayable.Create(graph);

            m_animInAir = AnimationClipPlayable.Create(graph, settings.animInAir);
            m_animInAir.Play();
            m_animInAir.SetApplyFootIK(false);
            inAirPort = m_mainMixer.AddInput(m_animInAir, 0);

            m_animLandAntic = AnimationClipPlayable.Create(graph, settings.animLandAntic);
            m_animInAir.Play();
            m_animLandAntic.SetApplyFootIK(false);
            landAnticPort = m_mainMixer.AddInput(m_animLandAntic, 0);

            m_layerMixer = AnimationLayerMixerPlayable.Create(graph);
            var port = m_layerMixer.AddInput(m_mainMixer, 0);

            m_layerMixer.SetInputWeight(port, 1);

            // Aim
            //if (settings.animAimDownToUp != null)
            //    m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp);

            // Actions
            m_actionAnimationHandler = new ActionAnimationHandler(m_layerMixer, settings.actionAnimations);
        }
Example #29
0
    void Start()

    {
        // Creates the graph, the mixer and binds them to the Animator.

        playableGraph = PlayableGraph.Create();

        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

        mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);

        playableOutput.SetSourcePlayable(mixerPlayable);

        // Creates AnimationClipPlayable and connects them to the mixer.

        var clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0);

        var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);

        playableGraph.Connect(clipPlayable0, 0, mixerPlayable, 0);

        playableGraph.Connect(clipPlayable1, 0, mixerPlayable, 1);



        // Plays the Graph.

        playableGraph.Play();
    }
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        private void AddClipToPreview(AnimationClip a_clip)
        {
            if (m_previewActive && a_clip != null)
            {
                m_blendWeights.Add(0f);

                AnimationMixerPlayable mixer = MxMPreviewScene.Mixer;

                int inputId = mixer.GetInputCount();
                mixer.SetInputCount(inputId + 1);

                var clipPlayable = AnimationClipPlayable.Create(MxMPreviewScene.PlayableGraph, a_clip);

                mixer.ConnectInput(inputId, clipPlayable, 0);

                for (int i = 0; i < mixer.GetInputCount(); ++i)
                {
                    var playable = mixer.GetInput(i);

                    if (playable.IsValid())
                    {
                        playable.SetTime(0f);
                    }
                }

                CalculateBlendWeights();
                ApplyBlendWeights();
            }
        }