Exemple #1
0
                public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
                {
                    ScriptPlayable <SpineAnimatorChannelTrackMixer> playable = TimelineUtils.CreateTrackMixer <SpineAnimatorChannelTrackMixer>(this, graph, go, inputCount);
                    SpineAnimatorTrack parentTrack = this.parent as SpineAnimatorTrack;

                    if (parentTrack != null)
                    {
                        SpineAnimatorTrackMixer parentMixer = TimelineUtils.GetTrackMixer <SpineAnimatorTrackMixer>(graph, parentTrack);

                        if (parentMixer != null)
                        {
                            SpineAnimatorChannelTrackMixer mixer = playable.GetBehaviour();
                            mixer.Init(parentMixer);

                            IEnumerable <TimelineClip> clips = GetClips();

                            foreach (TimelineClip clip in clips)
                            {
                                SpineAnimationClipAsset animationClip = clip.asset as SpineAnimationClipAsset;

                                if (animationClip != null)
                                {
                                    clip.displayName = animationClip._animationId;
                                    animationClip.SetParentTrack(parentTrack);
                                }
                            }
                        }
                    }

                    return(playable);
                }
Exemple #2
0
                public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
                {
                    ScriptPlayable <SpineAnimatorPlayableBehaviour> playable = ScriptPlayable <SpineAnimatorPlayableBehaviour> .Create(graph, new SpineAnimatorPlayableBehaviour());

                    SpineAnimatorPlayableBehaviour clone = playable.GetBehaviour();

                    SpineAnimatorTrackMixer trackMixer = TimelineUtils.GetTrackMixer <SpineAnimatorTrackMixer>(graph, _parentAnimatorTrack);

                    clone._clipAsset = this;

                    if (trackMixer != null && trackMixer.GetTrackBinding() != null && !string.IsNullOrEmpty(_animationId))
                    {
                        SkeletonAnimation skeletonAnimation = trackMixer.GetTrackBinding();
                        clone._animation      = skeletonAnimation.skeletonDataAsset.GetAnimationStateData().SkeletonData.FindAnimation(_animationId);
                        clone._animationSpeed = _animationSpeed;
                    }

                    return(playable);
                }
                protected virtual void PrepareChannelFrame(Playable playable)
                {
                    int numInputs = playable.GetInputCount();

                    SpineAnimatorTrackMixer.ChannelAnimationData        primaryAnimation     = new SpineAnimatorTrackMixer.ChannelAnimationData();
                    List <SpineAnimatorTrackMixer.ChannelAnimationData> backgroundAnimations = new List <SpineAnimatorTrackMixer.ChannelAnimationData>();

                    for (int i = 0; i < numInputs; i++)
                    {
                        ScriptPlayable <SpineAnimatorPlayableBehaviour> scriptPlayable = (ScriptPlayable <SpineAnimatorPlayableBehaviour>)playable.GetInput(i);
                        SpineAnimatorPlayableBehaviour inputBehaviour = scriptPlayable.GetBehaviour();

                        if (inputBehaviour != null && inputBehaviour._animation != null)
                        {
                            float inputWeight = playable.GetInputWeight(i);

                            if (inputWeight > 0.0f)
                            {
                                TimelineClip clip = TimelineUtils.GetClip(_trackAsset, inputBehaviour._clipAsset);

                                if (clip != null)
                                {
                                    double clipStart    = clip.hasPreExtrapolation ? clip.extrapolatedStart : clip.start;
                                    double clipDuration = clip.hasPreExtrapolation || clip.hasPostExtrapolation ? clip.extrapolatedDuration : clip.duration;

                                    if (_director.time >= clipStart && _director.time <= clipStart + clipDuration)
                                    {
                                        bool isPrimaryClip = IsPrimaryClip(clip);

                                        //Work out track time
                                        float animationDuration = inputBehaviour._animation.Duration;
                                        float trackTime         = GetExtrapolatedTrackTime(clip, _director.time, animationDuration);

                                        if (isPrimaryClip)
                                        {
                                            primaryAnimation._animation       = inputBehaviour._animation;
                                            primaryAnimation._animationTime   = trackTime;
                                            primaryAnimation._animationWeight = inputWeight;
                                            primaryAnimation._animationSpeed  = inputBehaviour._animationSpeed;
                                        }
                                        else
                                        {
                                            SpineAnimatorTrackMixer.ChannelAnimationData backroundAnimation = new SpineAnimatorTrackMixer.ChannelAnimationData
                                            {
                                                _animation       = inputBehaviour._animation,
                                                _animationTime   = trackTime,
                                                _animationWeight = 1.0f,
                                                _animationSpeed  = inputBehaviour._animationSpeed,
                                            };
                                            backgroundAnimations.Add(backroundAnimation);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    SpineAnimatorTrackMixer   parentMixer = (SpineAnimatorTrackMixer)_parentMixer;
                    SpineAnimatorChannelTrack track       = (SpineAnimatorChannelTrack)_trackAsset;

                    parentMixer.SetChannelData(track._animationChannel, primaryAnimation, backgroundAnimations.ToArray());
                }