< Summary

Class:ECSSystems.MaterialSystem.ECSMaterialSystem
Assembly:ECS7Plugin.Systems.Material
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/Systems/MaterialSystem/ECSMaterialSystem.cs
Covered lines:16
Uncovered lines:0
Coverable lines:16
Total lines:61
Line coverage:100% (16 of 16)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreateSystem(...)0%110100%
Update(...)0%880100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.ECS7.InternalComponents;
 4using DCL.ECSRuntime;
 5using UnityEngine;
 6using UnityEngine.Rendering;
 7
 8namespace ECSSystems.MaterialSystem
 9{
 10    public static class ECSMaterialSystem
 11    {
 12        private class State
 13        {
 14            public IECSReadOnlyComponentsGroup<InternalMaterial, InternalTexturizable> componentsGroup;
 15            public IInternalECSComponent<InternalTexturizable> texturizableComponent;
 16            public IInternalECSComponent<InternalMaterial> materialComponent;
 17        }
 18
 19        public static Action CreateSystem(IECSReadOnlyComponentsGroup<InternalMaterial, InternalTexturizable> components
 20            IInternalECSComponent<InternalTexturizable> texturizableComponent,
 21            IInternalECSComponent<InternalMaterial> materialComponent)
 22        {
 323            var state = new State()
 24            {
 25                componentsGroup = componentsGroup,
 26                texturizableComponent = texturizableComponent,
 27                materialComponent = materialComponent
 28            };
 929            return () => Update(state);
 30        }
 31
 32        private static void Update(State state)
 33        {
 634            var componentGroup = state.componentsGroup.group;
 35
 3636            for (int i = 0; i < componentGroup.Count; i++)
 37            {
 1238                var entityData = componentGroup[i];
 1239                InternalMaterial materialModel = entityData.componentData1.model;
 1240                InternalTexturizable texturizableModel = entityData.componentData2.model;
 41
 42                // if neither component has changed then we skip this entity
 1243                if (!materialModel.dirty && !texturizableModel.dirty)
 44                    continue;
 45
 746                IList<Renderer> renderers = texturizableModel.renderers;
 747                Material material = materialModel.material;
 48
 2849                for (int j = 0; j < renderers.Count; j++)
 50                {
 751                    Renderer renderer = renderers[j];
 752                    if (renderer.sharedMaterial != material)
 53                    {
 754                        renderer.sharedMaterial = material;
 55                    }
 756                    renderer.shadowCastingMode = materialModel.castShadows ? ShadowCastingMode.On : ShadowCastingMode.Of
 57                }
 58            }
 659        }
 60    }
 61}