< 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:62
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;
 7using UnityEngine.Video;
 8
 9namespace ECSSystems.MaterialSystem
 10{
 11    public static class ECSMaterialSystem
 12    {
 13        private class State
 14        {
 15            public IECSReadOnlyComponentsGroup<InternalMaterial, InternalTexturizable> componentsGroup;
 16            public IInternalECSComponent<InternalTexturizable> texturizableComponent;
 17            public IInternalECSComponent<InternalMaterial> materialComponent;
 18        }
 19
 20        public static Action CreateSystem(IECSReadOnlyComponentsGroup<InternalMaterial, InternalTexturizable> components
 21            IInternalECSComponent<InternalTexturizable> texturizableComponent,
 22            IInternalECSComponent<InternalMaterial> materialComponent)
 23        {
 524            var state = new State()
 25            {
 26                componentsGroup = componentsGroup,
 27                texturizableComponent = texturizableComponent,
 28                materialComponent = materialComponent
 29            };
 2730            return () => Update(state);
 31        }
 32
 33        private static void Update(State state)
 34        {
 2235            var componentGroup = state.componentsGroup.group;
 36
 7437            for (int i = 0; i < componentGroup.Count; i++)
 38            {
 1539                var entityData = componentGroup[i];
 1540                InternalMaterial materialModel = entityData.componentData1.model;
 1541                InternalTexturizable texturizableModel = entityData.componentData2.model;
 42
 43                // if neither component has changed then we skip this entity
 1544                if (!materialModel.dirty && !texturizableModel.dirty)
 45                    continue;
 46
 947                IList<Renderer> renderers = texturizableModel.renderers;
 948                Material material = materialModel.material;
 49
 3650                for (int j = 0; j < renderers.Count; j++)
 51                {
 952                    Renderer renderer = renderers[j];
 953                    if (renderer.sharedMaterial != material)
 54                    {
 955                        renderer.sharedMaterial = material;
 56                    }
 957                    renderer.shadowCastingMode = materialModel.castShadows ? ShadowCastingMode.On : ShadowCastingMode.Of
 58                }
 59            }
 2260        }
 61    }
 62}