コード例 #1
0
        public void DeserializeAnimation(AtomAnimation animation, JSONClass animationJSON)
        {
            if (animation == null)
            {
                throw new ArgumentNullException(nameof(animation));
            }

            animation.speed = DeserializeFloat(animationJSON["Speed"], 1f);

            JSONArray clipsJSON = animationJSON["Clips"].AsArray;

            if (clipsJSON == null || clipsJSON.Count == 0)
            {
                throw new NullReferenceException("Saved state does not have clips");
            }
            foreach (JSONClass clipJSON in clipsJSON)
            {
                var animationName  = clipJSON["AnimationName"].Value;
                var animationLayer = DeserializeString(clipJSON["AnimationLayer"], AtomAnimationClip.DefaultAnimationLayer);
                var existingClip   = animation.GetClip(animationName);
                if (existingClip != null)
                {
                    if (existingClip.IsEmpty())
                    {
                        var clipToRemove = animation.GetClip(animationName);
                        animation.clips.Remove(clipToRemove);
                        clipToRemove.Dispose();
                    }
                    else
                    {
                        var newAnimationName = GenerateUniqueAnimationName(animation, animationName);
                        SuperController.LogError($"VamTimeline: Imported clip '{animationName}' already exists and will be imported with the name {newAnimationName}");
                        animationName = newAnimationName;
                    }
                }
                var clip = new AtomAnimationClip(animationName, animationLayer)
                {
                    blendDuration = DeserializeFloat(clipJSON["BlendDuration"], AtomAnimationClip.DefaultBlendDuration),
                    loop          = DeserializeBool(clipJSON["Loop"], true),
                    transition    = DeserializeBool(clipJSON["Transition"], false),
                    ensureQuaternionContinuity = DeserializeBool(clipJSON["EnsureQuaternionContinuity"], true),
                    nextAnimationName          = clipJSON["NextAnimationName"]?.Value,
                    nextAnimationTime          = DeserializeFloat(clipJSON["NextAnimationTime"], 0),
                    autoPlay = DeserializeBool(clipJSON["AutoPlay"], false),
                    speed    = DeserializeFloat(clipJSON["Speed"], 1),
                    weight   = DeserializeFloat(clipJSON["Weight"], 1),
                };
                clip.animationLength = DeserializeFloat(clipJSON["AnimationLength"]).Snap();
                DeserializeClip(clip, clipJSON);
                animation.AddClip(clip);
            }
            animation.Initialize();
            animation.RebuildAnimationNow();
        }
コード例 #2
0
ファイル: AtomPlugin.cs プロジェクト: lfe999/vam-timeline
        private IEnumerator DeferredInit()
        {
            yield return(new WaitForEndOfFrame());

            if (animation != null)
            {
                StartAutoPlay();
                yield break;
            }
            base.containingAtom.RestoreFromLast(this);
            if (animation != null)
            {
                yield break;
            }
            animation = new AtomAnimation(base.containingAtom);
            animation.Initialize();
            BindAnimation();
        }