< Summary

Class:DCL.ECSComponents.AnimatorHandler
Assembly:DCL.ECSComponents.Animator
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Animator/AnimatorHandler.cs
Covered lines:20
Uncovered lines:0
Coverable lines:20
Total lines:60
Line coverage:100% (20 of 20)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:5
Method coverage:100% (5 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AnimatorHandler()0%110100%
AnimatorHandler(...)0%110100%
OnComponentCreated(...)0%110100%
OnComponentRemoved(...)0%220100%
OnComponentModelUpdated(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/Animator/AnimatorHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECS7.InternalComponents;
 3using DCL.ECSRuntime;
 4using DCL.Models;
 5using System.Collections.Generic;
 6using UnityEngine.Pool;
 7
 8namespace DCL.ECSComponents
 9{
 10    public class AnimatorHandler : IECSComponentHandler<PBAnimator>
 11    {
 112        private static readonly ObjectPool<List<InternalAnimationPlayer.State>> animationsStatePool =
 313            new ObjectPool<List<InternalAnimationPlayer.State>>(() => new List<InternalAnimationPlayer.State>());
 14
 15        private readonly IInternalECSComponent<InternalAnimationPlayer> internalAnimationPlayer;
 16
 617        public AnimatorHandler(IInternalECSComponent<InternalAnimationPlayer> internalAnimationPlayer)
 18        {
 619            this.internalAnimationPlayer = internalAnimationPlayer;
 620        }
 21
 122        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 23
 24        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 25        {
 226            var storedData = internalAnimationPlayer.GetFor(scene, entity);
 27
 228            if (storedData.HasValue)
 29            {
 130                animationsStatePool.Release(storedData.Value.model.States);
 131                internalAnimationPlayer.RemoveFor(scene, entity);
 32            }
 233        }
 34
 35        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBAnimator model)
 36        {
 437            var storedData = internalAnimationPlayer.GetFor(scene, entity);
 38
 439            InternalAnimationPlayer internalModel = storedData?.model ?? new InternalAnimationPlayer(animationsStatePool
 440            List<InternalAnimationPlayer.State> stateList = internalModel.States;
 441            stateList.Clear();
 42
 1643            for (int i = 0; i < model.States.Count; i++)
 44            {
 445                var stateData = model.States[i];
 46
 447                stateList.Add(new InternalAnimationPlayer.State(
 48                    stateData.Clip,
 49                    stateData.Playing,
 50                    stateData.GetWeight(),
 51                    stateData.GetSpeed(),
 52                    stateData.GetLoop(),
 53                    stateData.GetShouldReset()
 54                ));
 55            }
 56
 457            internalAnimationPlayer.PutFor(scene, entity, internalModel);
 458        }
 59    }
 60}