< Summary

Information
Class: Hertzole.ScriptableValues.ScriptableListenerBase
Assembly: Hertzole.ScriptableValues
File(s): ./Packages/se.hertzole.scriptable-values/Runtime/Listeners/ScriptableListenerBase.cs
Tag: 52_28197466029
Line coverage
95%
Covered lines: 41
Uncovered lines: 2
Coverable lines: 43
Total lines: 98
Line coverage: 95.3%
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
ScriptableListenerBase()0%110100%
Awake()0%220100%
Start()0%330100%
OnEnable()0%330100%
OnDisable()0%330100%
OnDestroy()0%330100%
SetListening(...)0%110100%
ToggleListening(...)0%2100%

File(s)

./Packages/se.hertzole.scriptable-values/Runtime/Listeners/ScriptableListenerBase.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace Hertzole.ScriptableValues
 5{
 6    public abstract class ScriptableListenerBase : MonoBehaviour
 7    {
 8        [SerializeField]
 9        [EditorTooltip("When listeners should start listening.")]
 1063810        private StartListenEvents startListening = StartListenEvents.Awake;
 11        [SerializeField]
 12        [EditorTooltip("When listeners should stop listening.")]
 1063813        private StopListenEvents stopListening = StopListenEvents.OnDestroy;
 14
 15        /// <summary>
 16        ///     Is the listener currently listening to the target value?
 17        /// </summary>
 8039418        public bool IsListening { get; private set; }
 19
 20        /// <summary>
 21        ///     When listeners should start listening.
 22        /// </summary>
 23        public StartListenEvents StartListening
 24        {
 286225            get { return startListening; }
 286226            set { startListening = value; }
 27        }
 28        /// <summary>
 29        ///     When listeners should stop listening.
 30        /// </summary>
 31        public StopListenEvents StopListening
 32        {
 187233            get { return stopListening; }
 286234            set { stopListening = value; }
 35        }
 36
 37        protected virtual void Awake()
 1063838        {
 1063839            IsListening = false;
 40
 1063841            if (startListening == StartListenEvents.Awake)
 1000242            {
 1000243                SetListening(true);
 1000244            }
 1063845        }
 46
 47        protected void Start()
 98448        {
 98449            if (!IsListening && startListening == StartListenEvents.Start)
 31850            {
 31851                SetListening(true);
 31852            }
 98453        }
 54
 55        protected virtual void OnEnable()
 1095656        {
 1095657            if (!IsListening && startListening == StartListenEvents.OnEnable)
 63658            {
 63659                SetListening(true);
 63660            }
 1095661        }
 62
 63        protected virtual void OnDisable()
 1095664        {
 1095665            if (IsListening && stopListening == StopListenEvents.OnDisable)
 127266            {
 127267                SetListening(false);
 127268            }
 1095669        }
 70
 71        protected virtual void OnDestroy()
 1063872        {
 1063873            if (IsListening && stopListening == StopListenEvents.OnDestroy)
 968474            {
 968475                SetListening(false);
 968476            }
 1063877        }
 78
 79        /// <summary>
 80        ///     Sets the listening state of the object.
 81        /// </summary>
 82        /// <param name="listen">If the object should listen to the target value.</param>
 83        protected virtual void SetListening(bool listen)
 2191284        {
 2191285            IsListening = listen;
 2191286        }
 87
 88        #region Obsolete
 89#if UNITY_EDITOR // Don't include in builds.
 90        [Obsolete("Use 'SetListening' instead. This will be removed in build.", true)]
 91        protected virtual void ToggleListening(bool listen)
 092        {
 093            throw new NotSupportedException(nameof(ToggleListening) + " is obsolete. Use " + nameof(SetListening) + " in
 94        }
 95#endif // UNITY_EDITOR
 96        #endregion
 97    }
 98}