< Summary

Class:DCL.Skybox.ReflectionProbeRuntime
Assembly:ProceduralSkybox
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/ReflectionProbeRuntime.cs
Covered lines:3
Uncovered lines:43
Coverable lines:46
Total lines:119
Line coverage:6.5% (3 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ReflectionProbeRuntime()0%110100%
Start()0%2100%
Update()0%6200%
UpdateFixedSkybox()0%12300%
UpdateDynamicSkybox()0%6200%
LateUpdate()0%6200%
BakeNewReflection()0%2100%
UpdateResolution(...)0%6200%
SkyboxModeChanged(...)0%6200%
FixedSkyboxTimeChanged()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/ProceduralSkybox/ToolProceduralSkybox/Scripts/ReflectionProbeRuntime.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5namespace DCL.Skybox
 6{
 7    public class ReflectionProbeRuntime : MonoBehaviour
 8    {
 9        public ReflectionProbe realtimeProbe;
 110        public float updateAfter = 60;
 11        float timer;
 12        public Transform followTransform;
 113        public int resolution = 256;
 14        [SerializeField] bool fixedSkybox = false;
 15        [SerializeField] bool fixedSkyboxBaked = false;
 116        [SerializeField] float fixedSkyboxUpdateTime = 3;
 17        [SerializeField] float fixedSkyboxTimer = 0;
 18
 19        private void Start()
 20        {
 021            timer = 0;
 022            realtimeProbe.resolution = resolution;
 023            BakeNewReflection();
 024        }
 25
 26        private void Update()
 27        {
 028            if (fixedSkybox)
 29            {
 030                UpdateFixedSkybox();
 31            }
 32            else
 33            {
 034                UpdateDynamicSkybox();
 35            }
 36
 37
 038        }
 39
 40        void UpdateFixedSkybox()
 41        {
 042            if (fixedSkyboxBaked)
 43            {
 044                return;
 45            }
 46
 047            fixedSkyboxTimer += Time.deltaTime;
 48
 049            if (fixedSkyboxTimer >= fixedSkyboxUpdateTime)
 50            {
 051                BakeNewReflection();
 052                fixedSkyboxBaked = true;
 53            }
 054        }
 55
 56        void UpdateDynamicSkybox()
 57        {
 058            timer += Time.deltaTime / updateAfter;
 59
 060            if (timer >= 1)
 61            {
 062                timer = 0;
 063                BakeNewReflection();
 64            }
 065        }
 66
 67        private void LateUpdate()
 68        {
 069            if (followTransform != null)
 70            {
 071                transform.position = followTransform.position;
 72            }
 073        }
 74
 75        void BakeNewReflection()
 76        {
 077            realtimeProbe.resolution = resolution;
 078            realtimeProbe.RenderProbe();
 079        }
 80
 81        public void UpdateResolution(int resolution)
 82        {
 083            this.resolution = resolution;
 084            realtimeProbe.resolution = resolution;
 85
 086            if (fixedSkybox)
 87            {
 088                FixedSkyboxTimeChanged();
 89            }
 90            else
 91            {
 092                timer = 0;
 093                BakeNewReflection();
 94            }
 095        }
 96
 97        public void SkyboxModeChanged(bool dynamicSkybox)
 98        {
 099            fixedSkybox = !dynamicSkybox;
 100
 0101            if (fixedSkybox)
 102            {
 0103                fixedSkyboxTimer = 0;
 0104                fixedSkyboxBaked = false;
 105            }
 106            else
 107            {
 0108                timer = 0;
 0109                BakeNewReflection();
 110            }
 0111        }
 112
 113        public void FixedSkyboxTimeChanged()
 114        {
 0115            fixedSkyboxTimer = 0;
 0116            fixedSkyboxBaked = false;
 0117        }
 118    }
 119}