< Summary

Information
Class: Hertzole.ScriptableValues.ScriptableValuesInitialization
Assembly: Hertzole.ScriptableValues
File(s): ./Packages/se.hertzole.scriptable-values/Runtime/Core/ScriptableValuesInitialization.cs
Tag: 52_28197466029
Line coverage
81%
Covered lines: 39
Uncovered lines: 9
Coverable lines: 48
Total lines: 84
Line coverage: 81.2%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScriptableValuesInitialization()0%2100%
InitInEditor()0%2100%
OnPlayModeStateChanged(...)0%440100%
Init()0%330100%
RegisterForEnable(...)0%3.13077.78%
RegisterForDisable(...)0%3.13077.78%

File(s)

./Packages/se.hertzole.scriptable-values/Runtime/Core/ScriptableValuesInitialization.cs

#LineLine coverage
 1#if UNITY_EDITOR
 2using System;
 3using System.Collections.Generic;
 4using UnityEditor;
 5using UnityEngine;
 6
 7namespace Hertzole.ScriptableValues
 8{
 9    internal static class ScriptableValuesInitialization
 10    {
 011        private static readonly List<IScriptableValueCallbacks> objectsToEnable = new List<IScriptableValueCallbacks>();
 012        private static readonly List<IScriptableValueCallbacks> objectsToDisable = new List<IScriptableValueCallbacks>()
 13
 14        [InitializeOnLoadMethod]
 15        private static void InitInEditor()
 016        {
 017            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
 018        }
 19
 20        private static void OnPlayModeStateChanged(PlayModeStateChange state)
 14421        {
 22            // When exiting play mode, we want to call OnScriptableObjectPreDisable and OnScriptableObjectDisable on all
 14423            if (state == PlayModeStateChange.EnteredEditMode)
 3624            {
 24025                for (int i = 0; i < objectsToDisable.Count; i++)
 8426                {
 8427                    objectsToDisable[i].OnScriptableObjectPreDisable();
 8428                }
 29
 24030                for (int i = 0; i < objectsToDisable.Count; i++)
 8431                {
 8432                    objectsToDisable[i].OnScriptableObjectDisable();
 8433                }
 34
 3635                objectsToDisable.Clear();
 3636            }
 14437        }
 38
 39        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
 40        private static void Init()
 3641        {
 42            // When the game starts, call OnScriptableObjectPreEnable and OnScriptableObjectEnable on all registered obj
 25243            for (int i = 0; i < objectsToEnable.Count; i++)
 9044            {
 9045                objectsToEnable[i].OnScriptableObjectPreEnable();
 9046            }
 47
 25248            for (int i = 0; i < objectsToEnable.Count; i++)
 9049            {
 9050                objectsToEnable[i].OnScriptableObjectEnable();
 9051            }
 52
 3653            objectsToEnable.Clear();
 3654        }
 55
 56        public static void RegisterForEnable(IScriptableValueCallbacks obj)
 9057        {
 58            // This is a bootstrapper, we can't register for enable if the application is already playing. The object sh
 9059            if (Application.isPlaying)
 060            {
 061                throw new InvalidOperationException("Cannot register for enable when the application is already playing.
 62            }
 63
 9064            if (!objectsToEnable.Contains(obj))
 9065            {
 9066                objectsToEnable.Add(obj);
 9067            }
 9068        }
 69
 70        public static void RegisterForDisable(IScriptableValueCallbacks obj)
 8471        {
 8472            if (!Application.isPlaying)
 073            {
 074                throw new InvalidOperationException("Cannot register for disable when the application is not playing.");
 75            }
 76
 8477            if (!objectsToDisable.Contains(obj))
 8478            {
 8479                objectsToDisable.Add(obj);
 8480            }
 8481        }
 82    }
 83}
 84#endif