Esempio n. 1
0
        private void AssignNextAnimation(AtomAnimationClip clip)
        {
            if (clip.nextAnimationName == null)
            {
                return;
            }
            if (clips.Count == 1)
            {
                return;
            }

            if (clip.nextAnimationTime <= 0)
            {
                return;
            }

            var nextTime = (playTime + clip.nextAnimationTime).Snap();

            if (clip.nextAnimationName == RandomizeAnimationName)
            {
                var idx = Random.Range(0, clips.Count - 1);
                if (idx >= clips.IndexOf(clip))
                {
                    idx += 1;
                }
                clip.SetNext(clips[idx].animationName, nextTime);
            }
            else if (clip.nextAnimationName.EndsWith(RandomizeGroupSuffix))
            {
                var prefix = clip.nextAnimationName.Substring(0, clip.nextAnimationName.Length - RandomizeGroupSuffix.Length);
                var group  = clips
                             .Where(c => c.animationName != clip.animationName)
                             .Where(c => c.animationName.StartsWith(prefix))
                             .ToList();
                var idx = Random.Range(0, group.Count);
                clip.SetNext(group[idx].animationName, nextTime);
            }
            else
            {
                clip.SetNext(clip.nextAnimationName, nextTime);
            }
        }
        private void TransitionAnimation(AtomAnimationClip from, AtomAnimationClip to)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }

            from.SetNext(null, float.NaN);

            if (!to.playbackEnabled)
            {
                to.clipTime = to.loop && from.loop && to.preserveLoops ? from.clipTime : 0f;
            }

            // if(!from.loop && to.blendInDuration > from.animationLength - from.clipTime)
            //     SuperController.LogError($"Timeline: Transition from '{from.animationName}' to '{to.animationName}' will stop the former animation after it ends, because the blend-in time of the latter is too long for the sequenced time.");
            Blend(from, 0f, to.blendInDuration);
            from.playbackMainInLayer = false;
            Blend(to, 1f, to.blendInDuration);
            to.playbackMainInLayer = true;

            if (sequencing)
            {
                AssignNextAnimation(to);
            }

            if (from.animationPattern != null)
            {
                // Let the loop finish during the transition
                from.animationPattern.SetBoolParamValue("loopOnce", true);
            }

            if (to.animationPattern != null)
            {
                to.animationPattern.SetBoolParamValue("loopOnce", false);
                to.animationPattern.ResetAndPlay();
            }
        }
Esempio n. 3
0
        private void TransitionAnimation(AtomAnimationClip from, AtomAnimationClip to)
        {
            if (from == null)
            {
                throw new ArgumentNullException(nameof(from));
            }
            if (to == null)
            {
                throw new ArgumentNullException(nameof(to));
            }

            from.SetNext(null, 0);
            Blend(from, 0f, current.blendDuration);
            from.playbackMainInLayer = false;
            Blend(to, 1f, current.blendDuration);
            to.playbackMainInLayer = true;
            if (to.playbackWeight == 0)
            {
                to.clipTime = 0f;
            }

            if (sequencing)
            {
                AssignNextAnimation(to);
            }

            if (from.animationPattern != null)
            {
                // Let the loop finish during the transition
                from.animationPattern.SetBoolParamValue("loopOnce", true);
            }

            if (to.animationPattern != null)
            {
                to.animationPattern.SetBoolParamValue("loopOnce", false);
                to.animationPattern.ResetAndPlay();
            }
        }
        private void AssignNextAnimation(AtomAnimationClip source)
        {
            if (source.nextAnimationName == null)
            {
                return;
            }
            if (clips.Count == 1)
            {
                return;
            }

            if (source.nextAnimationTime <= 0)
            {
                return;
            }

            AtomAnimationClip next;

            string group;

            if (source.nextAnimationName == RandomizeAnimationName)
            {
                var candidates = index
                                 .ByLayer(source.animationLayer)
                                 .Where(c => c.animationName != source.animationName)
                                 .ToList();
                if (candidates.Count == 0)
                {
                    return;
                }
                var idx = Random.Range(0, candidates.Count);
                next = candidates[idx];
            }
            else if (TryGetRandomizedGroup(source.nextAnimationName, out group))
            {
                var candidates = index
                                 .ByLayer(source.animationLayer)
                                 .Where(c => c.animationName != source.animationName)
                                 .Where(c => c.animationNameGroup == group)
                                 .ToList();
                if (candidates.Count == 0)
                {
                    return;
                }
                var idx = Random.Range(0, candidates.Count);
                next = candidates[idx];
            }
            else
            {
                next = GetClip(source.animationLayer, source.nextAnimationName);
            }

            if (next == null)
            {
                return;
            }

            var nextTime = source.nextAnimationTime;

            if (source.preserveLoops && source.loop)
            {
                nextTime = nextTime.RoundToNearest(source.animationLength) - (next.blendInDuration / 2f) + source.clipTime;
            }
            if (source.nextAnimationTimeRandomize > 0f)
            {
                nextTime = Random.Range(nextTime, nextTime + (source.preserveLoops ? source.nextAnimationTimeRandomize.RoundToNearest(source.animationLength) : source.nextAnimationTimeRandomize));
            }
            source.SetNext(next.animationName, nextTime);
        }