< Summary

Class:ECSSystems.AnimationSystem.AnimationSystem
Assembly:ECS7Plugin.Systems.Animation
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/AnimationSystem/AnimationSystem.cs
Covered lines:41
Uncovered lines:4
Coverable lines:45
Total lines:99
Line coverage:91.1% (41 of 45)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:4
Method coverage:100% (4 of 4)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AnimationSystem(...)0%110100%
Update()0%550100%
SetupAnimation(...)0%440100%
SetAnimationState(...)0%10.9310078.95%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/AnimationSystem/AnimationSystem.cs

#LineLine coverage
 1using DCL.ECS7.InternalComponents;
 2using DCL.ECSRuntime;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6namespace ECSSystems.AnimationSystem
 7{
 8    public class AnimationSystem
 9    {
 10        private IECSReadOnlyComponentsGroup<InternalAnimationPlayer, InternalAnimation> animationGroup;
 11        private readonly IInternalECSComponent<InternalAnimation> animationComponent;
 12
 213        public AnimationSystem(IECSReadOnlyComponentsGroup<InternalAnimationPlayer, InternalAnimation> animationGroup,
 14            IInternalECSComponent<InternalAnimation> animationComponent)
 15        {
 216            this.animationGroup = animationGroup;
 217            this.animationComponent = animationComponent;
 218        }
 19
 20        public void Update()
 21        {
 122            var group = animationGroup.group;
 23
 424            for (int i = 0; i < group.Count; i++)
 25            {
 126                var elementData = group[i];
 127                var animationPlayerModel = elementData.componentData1.model;
 128                var animationModel = elementData.componentData2.model;
 29
 130                if (!animationPlayerModel.dirty && !animationModel.dirty)
 31                    continue;
 32
 133                if (!animationModel.IsInitialized)
 34                {
 135                    SetupAnimation(animationModel.Animation);
 136                    animationModel.IsInitialized = true;
 137                    animationComponent.PutFor(elementData.scene, elementData.entity, animationModel);
 38                }
 39
 140                SetAnimationState(animationPlayerModel.States, animationModel.Animation);
 41            }
 142        }
 43
 44        private static void SetupAnimation(Animation animation)
 45        {
 146            int layerIndex = 0;
 47
 148            animation.playAutomatically = true;
 149            animation.enabled = true;
 150            animation.Stop();
 51
 52            //putting the component in play state if playAutomatically was true at that point.
 153            if (animation.clip)
 154                animation.clip.SampleAnimation(animation.gameObject, 0);
 55
 656            foreach (AnimationState unityState in animation)
 57            {
 258                unityState.clip.wrapMode = WrapMode.Loop;
 259                unityState.layer = layerIndex;
 260                unityState.blendMode = AnimationBlendMode.Blend;
 261                layerIndex++;
 62            }
 163        }
 64
 65        private static void SetAnimationState(IList<InternalAnimationPlayer.State> animationState, Animation animation)
 66        {
 167            if (animationState.Count == 0)
 068                return;
 69
 470            for (int i = 0; i < animationState.Count; i++)
 71            {
 172                var state = animationState[i];
 173                AnimationState unityState = animation[state.Clip];
 74
 175                if (!unityState)
 76                    continue;
 77
 178                unityState.weight = state.Weight;
 79
 180                unityState.wrapMode = state.Loop ? WrapMode.Loop : WrapMode.Default;
 81
 182                unityState.clip.wrapMode = unityState.wrapMode;
 183                unityState.speed = state.Speed;
 184                unityState.enabled = state.Playing;
 85
 186                if (state.ShouldReset && animation.IsPlaying(state.Clip))
 87                {
 088                    animation.Stop(state.Clip);
 89
 90                    //Manually sample the animation. If the reset is not played again the frame 0 wont be applied
 091                    unityState.clip.SampleAnimation(animation.gameObject, 0);
 92                }
 93
 194                if (state.Playing && !animation.IsPlaying(state.Clip))
 095                    animation.Play(state.Clip);
 96            }
 197        }
 98    }
 99}