- Home /
Question by
Le-Capitaine · Oct 12, 2014 at 01:37 PM ·
c#listforeachlegacyanimation
Iterating through nulls in legacy-style Animation component
[HideInInspector] public List<AnimationClip> clips;
public void GetClips () {
if (animation) {
clips = new List<AnimationClip>();
foreach (AnimationState clip in animation) clips.Add (clip.clip);
}
}
public void AnimateClip (int which) {
if (which < clips.Count && clips[which]) {
animation.Stop ();
animation.Rewind ();
animation.Play (clips[which].name);
}
}
I'm intentionally using the legacy animation system so as not to bloat my project with tons of redundant animation controllers; this quick thing allows me to play animations by index. I'm sometimes relying on there being no animation stored in some of clips
's indices, so that nothing is done when it's called.
What I've run into is that animation slots without an animation aren't iterated through at all, leaving incorrect indices.
I get the feeling this is an intended behaviour, but it stops my whole system dead in its tracks. Is foreach the only way to iterate through animation
's list of states, which uses strings instead of indexes? Is some obvious solution flying over my head again?
Comment