public void DeserializeAnimation(AtomAnimation animation, JSONClass animationJSON)
        {
            if (animation == null)
            {
                throw new ArgumentNullException(nameof(animation));
            }

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

            animation.index.StartBulkUpdates();
            try
            {
                var 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 clip = DeserializeClip(clipJSON);
                    animation.AddClip(clip);
                }
            }
            finally
            {
                animation.index.EndBulkUpdates();
            }
        }
Example #2
0
        public void Bind(AtomAnimation animation, IList <IAnimationTargetWithCurves> targets)
        {
            Unbind();

            _animation = animation;
            if ((targets?.Count ?? 0) > 0)
            {
                _targets = targets;
                _lines.ClearCurves();
                foreach (var target in targets)
                {
                    target.onAnimationKeyframesModified.AddListener(OnAnimationCurveModified);
                    BindCurves(target);
                }
                _lines.SetVerticesDirty();
                _noCurves.SetActive(false);
                _scrubberRect.gameObject.SetActive(true);
                _time = -1f;
            }
            else
            {
                _targets         = null;
                _animationLength = 0f;
                _noCurves.SetActive(true);
                _scrubberRect.gameObject.SetActive(false);
            }
        }
Example #3
0
        public void Bind(AtomAnimation animation)
        {
            this.animation = animation;

            _controlPanel.Bind(animation);
            _curveType.Bind(animation);
            _curves.Bind(animation);
        }
Example #4
0
 public void Bind(AtomAnimation animation)
 {
     if (_animation != null)
     {
         throw new InvalidOperationException("Cannot bind to animation twice");
     }
     _animation = animation;
     _animation.onTargetsSelectionChanged.AddListener(OnTargetsSelectionChanged);
     OnTargetsSelectionChanged();
 }
        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();
        }
Example #6
0
        public void Bind(AtomAnimation animation)
        {
            UnbindAnimation();

            _animation = animation;
            _animation.TimeChanged.AddListener(OnTimeChanged);
            _animation.CurrentAnimationChanged.AddListener(OnCurrentAnimationChanged);
            _animation.AnimationSettingsChanged.AddListener(OnAnimationSettingsChanged);
            BindClip(_animation.Current);
            SetScrubberPosition(_animation.Time, true);
        }
Example #7
0
        private void UnbindAnimation()
        {
            if (_animation == null)
            {
                return;
            }

            _animation.TimeChanged.RemoveListener(OnTimeChanged);
            _animation.CurrentAnimationChanged.RemoveListener(OnCurrentAnimationChanged);
            _animation = null;

            UnbindClip();
        }
Example #8
0
 public OperationsFactory(AtomAnimation animation, AtomAnimationClip clip)
 {
     if (animation == null)
     {
         throw new ArgumentNullException(nameof(animation));
     }
     _animation = animation;
     if (clip == null)
     {
         throw new ArgumentNullException(nameof(clip));
     }
     _clip = clip;
 }
        private static string GenerateUniqueAnimationName(AtomAnimation animation, string animationName)
        {
            var i = 1;

            while (true)
            {
                var newAnimationName = $"{animationName} ({i})";
                if (!animation.clips.Any(c => c.animationName == newAnimationName))
                {
                    return(newAnimationName);
                }
                i++;
            }
        }
Example #10
0
 private void Unbind()
 {
     if (_targets != null)
     {
         _lines.ClearCurves();
         foreach (var target in _targets)
         {
             target.onAnimationKeyframesModified.RemoveListener(OnAnimationCurveModified);
         }
         _animation = null;
         _targets   = null;
         _lines.SetVerticesDirty();
     }
 }
 public void Bind(AtomAnimation animation)
 {
     _animation = animation;
     if (_scrubber != null)
     {
         _scrubber.animation = animation;
     }
     if (_dopeSheet != null)
     {
         _dopeSheet.Bind(animation);
     }
     _animation.onClipsListChanged.AddListener(OnClipsListChanged);
     _animation.onCurrentAnimationChanged.AddListener(OnCurrentAnimationChanged);
     SyncAnimationsListNow();
 }
        public JSONClass SerializeAnimation(AtomAnimation animation, string animationNameFilter = null)
        {
            var animationJSON = new JSONClass
            {
                { "Speed", animation.speed.ToString(CultureInfo.InvariantCulture) },
                { "Master", animation.master ? "1" : "0" }
            };
            var clipsJSON = new JSONArray();

            foreach (var clip in animation.clips.Where(c => animationNameFilter == null || c.animationName == animationNameFilter))
            {
                clipsJSON.Add(SerializeClip(clip));
            }
            animationJSON.Add("Clips", clipsJSON);
            return(animationJSON);
        }
Example #13
0
        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();
        }
Example #14
0
        private bool NextExists(AtomAnimationClip clip, string nextName)
        {
            if (nextName == AtomAnimation.RandomizeAnimationName)
            {
                return(true);
            }

            string group;

            if (AtomAnimation.TryGetRandomizedGroup(nextName, out group))
            {
                return(true);
            }

            var next = animation.index.ByLayer(clip.animationLayer).FirstOrDefault(c => c.animationName == nextName);

            return(next != null);
        }
        public JSONClass SerializeAnimation(AtomAnimation animation, string animationNameFilter = null)
        {
            var animationJSON = new JSONClass
            {
                { "Speed", animation.speed.ToString(CultureInfo.InvariantCulture) }
            };
            var clipsJSON = new JSONArray();

            animationJSON.Add("Clips", clipsJSON);
            foreach (var clip in animation.clips.Where(c => animationNameFilter == null || c.animationName == animationNameFilter))
            {
                var clipJSON = new JSONClass
                {
                    { "AnimationName", clip.animationName },
                    { "AnimationLength", clip.animationLength.ToString(CultureInfo.InvariantCulture) },
                    { "BlendDuration", clip.blendDuration.ToString(CultureInfo.InvariantCulture) },
                    { "Loop", clip.loop ? "1" : "0" },
                    { "Transition", clip.transition ? "1" : "0" },
                    { "EnsureQuaternionContinuity", clip.ensureQuaternionContinuity ? "1" : "0" },
                    { "AnimationLayer", clip.animationLayer },
                    { "Speed", clip.speed.ToString(CultureInfo.InvariantCulture) },
                    { "Weight", clip.weight.ToString(CultureInfo.InvariantCulture) },
                };
                if (clip.nextAnimationName != null)
                {
                    clipJSON["NextAnimationName"] = clip.nextAnimationName;
                }
                if (clip.nextAnimationTime != 0)
                {
                    clipJSON["NextAnimationTime"] = clip.nextAnimationTime.ToString(CultureInfo.InvariantCulture);
                }
                if (clip.autoPlay)
                {
                    clipJSON["AutoPlay"] = "1";
                }

                SerializeClip(clip, clipJSON);
                clipsJSON.Add(clipJSON);
            }
            return(animationJSON);
        }
Example #16
0
 public void Bind(AtomAnimation animation)
 {
     _controlPanel.Bind(animation);
     ChangeScreen(GetDefaultScreen());
 }
        public AtomAnimation DeserializeAnimation(AtomAnimation animation, JSONClass animationJSON, bool overwriteClips = true)
        {
            if (animation == null)
            {
                animation = new AtomAnimation(_atom)
                {
                    Speed = DeserializeFloat(animationJSON["Speed"], 1f),
                    InterpolationTimeout = DeserializeFloat(animationJSON["InterpolationTimeout"], 0.25f),
                    InterpolationSpeed   = DeserializeFloat(animationJSON["InterpolationSpeed"], 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)
            {
                string animationName = clipJSON["AnimationName"].Value;
                if (animation.Clips.Any(c => c.AnimationName == animationName))
                {
                    if (overwriteClips)
                    {
                        SuperController.LogError($"VamTimeline: Imported clip '{animationName}' already exists and will be overwritten");
                        var clipToRemove = animation.Clips.First(c => c.AnimationName == animationName);
                        animation.Clips.Remove(clipToRemove);
                        clipToRemove.Dispose();
                    }
                    else
                    {
                        // generate a new name since we don't want to overwrite in this case
                        var i = 1;
                        while (true)
                        {
                            var newAnimationName = $"{animationName} ({i})";
                            if (!animation.Clips.Any(c => c.AnimationName == newAnimationName))
                            {
                                SuperController.LogError($"VamTimeline: Imported clip '{animationName}' already exists and will be imported with the name {newAnimationName}");
                                animationName = newAnimationName;
                                break;
                            }
                            i++;
                        }
                    }
                }
                var clip = new AtomAnimationClip(animationName)
                {
                    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)
                };
                clip.animationLength = DeserializeFloat(clipJSON["AnimationLength"]).Snap();
                DeserializeClip(clip, clipJSON);
                animation.AddClip(clip);
            }
            animation.Initialize();
            animation.RebuildAnimation();
            return(animation);
        }
Example #18
0
 public TestContext(GameObject gameObject, StringBuilder output, AtomAnimation animation)
 {
     this.gameObject = gameObject;
     this.output     = output;
     this.animation  = animation;
 }
Example #19
0
 public void Bind(AtomAnimation animation)
 {
     _animation = animation;
     curveTypeJSON.setCallbackFunction = ChangeCurve;
     OnEnable();
 }
 public void Bind(AtomAnimation animation)
 {
     _animation          = animation;
     _scrubber.animation = animation;
     _dopeSheet.Bind(animation);
 }
 public AddAnimationOperations(AtomAnimation animation, AtomAnimationClip clip)
 {
     _animation = animation;
     _clip      = clip;
 }
Example #22
0
 public TargetsOperations(Atom containingAtom, AtomAnimation animation, AtomAnimationClip clip)
 {
     _containingAtom = containingAtom;
     _animation      = animation;
     _clip           = clip;
 }
Example #23
0
 public TargetsOperation(AtomAnimation animation, AtomAnimationClip clip)
 {
     _animation = animation;
     _clip      = clip;
 }
Example #24
0
 public ImportOperations(AtomAnimation animation, bool silent = false)
 {
     _animation = animation;
     _silent    = silent;
 }
Example #25
0
 public LayersOperations(AtomAnimation animation, AtomAnimationClip clip)
 {
     _animation = animation;
     _clip      = clip;
 }
 public MocapImportOperations(Atom containingAtom, AtomAnimation animation, AtomAnimationClip clip)
 {
     _containingAtom = containingAtom;
     _animation      = animation;
     this.clip       = clip;
 }
Example #27
0
 public RecordOperations(AtomAnimation animation, AtomAnimationClip clip)
 {
     _animation = animation;
     _clip      = clip;
 }