< Summary

Class:DCL.UIComponents.CodeStyleExample
Assembly:Assembly-CSharp
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/CodeStyleExample.cs
Covered lines:0
Uncovered lines:29
Coverable lines:29
Total lines:130
Line coverage:0% (0 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CodeStyleExample()0%2100%
CodeStyleExample()0%2100%
Initialize()0%2100%
ApplyDamage(...)0%2100%
ComputeDamage(...)0%2100%
TakeHit(...)0%2100%
Hide()0%2100%
SetVisibility(...)0%2100%
Awake()0%2100%
Start()0%6200%
OnEnable()0%2100%
OnClosed(...)0%2100%
OnDisable()0%2100%
OnDestroy()0%6200%
Method1()0%2100%
Method2()0%2100%
Method3()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/CodeStyleExample.cs

#LineLine coverage
 1// NOTE: following separation lines are used only for clarity and do not take part of our commenting code style!
 2
 3//----------------------------------------------------------------------------------------------------  Usings group
 4using System;
 5using System.Collections.Generic;
 6using JetBrains.Annotations;
 7using UnityEngine;
 8using UnityEngine.Events;
 9
 10namespace DCL.UIComponents
 11{
 12    //------------------------------------------------------------------------------------------------  Enum, delegates,
 13    public enum Side { Left, Right }
 14
 15    public delegate void Destroction<T> (T current);
 16
 17    public interface IInitializable
 18    {
 19        bool IsInitialized { get; }
 20
 21        void Initialize();
 22    }
 23
 24    [RequireComponent(typeof(Animation))]
 25    public class CodeStyleExample : MonoBehaviour, IInitializable
 26    {
 27        //----------------------------------------------------------------------------------------  Enum, delegates decl
 28        private enum Direction { North, South, West, East }
 29        private delegate void Interaction<T> (T current);
 30
 31        //----------------------------------------------------------------------------------------  Const and static rea
 32        public const string ASSET_PATH = "AvatarPrefab";
 33        private const float MAX_TIMER = 10f;
 34
 035        public static readonly int WAVE_ANIM_HASH = Animator.StringToHash("Wave");
 036        private static readonly int DANCE_ANIM_HASH = Animator.StringToHash("Dance");
 37
 38        //----------------------------------------------------------------------------------------  Events and UnityEven
 39        public event Destroction<CodeStyleExample> Destroyed;
 40        [NonSerialized] public UnityEvent<bool> Closed; // use [NonSerialized] or [HideInInspector] for UnityEvents
 41
 42        //----------------------------------------------------------------------------------------  Fields group (other 
 043        public readonly List<int> CachedNumbers = new List<int>();
 044        protected readonly List<Vector2> poistions = new List<Vector2>();
 45
 46        public int Timer;
 47
 48        [SerializeField] private AnimationClip[] clips;
 49        [SerializeField] private float armor;
 50        [SerializeField] private float health;
 51        [SerializeField] private bool isVisitble;
 52
 53        protected float cooldown;
 54
 55        private Animation animation;
 56        private Interaction<int> interactionsBuffer;
 57
 58        //----------------------------------------------------------------------------------------  Properties group
 059        public bool IsInitialized { get; private set; }
 60
 61        [PublicAPI]
 062        public bool IsVisitble => isVisitble; // [PublicAPI] Public - used only from outside of Unity solution (by other
 63
 64        //----------------------------------------------------------------------------------------  Public methods group
 65        public void Initialize() =>
 066            IsInitialized = true;
 67
 68        public void ApplyDamage(float damage) // Public - called from outside of the class (by other class)
 69        {
 070            float resultDamage = ComputeDamage(damage);
 071            TakeHit(resultDamage);
 072        }
 73
 74        private float ComputeDamage(float damage) => // Called by ApplyDamage
 075            damage - armor;
 76
 77        private void TakeHit(float amount) => // Called by ApplyDamage
 078            health -= amount;
 79
 80        [UsedImplicitly]
 81        public void Hide() => // [UsedImplicitly] Public - called implicitly, for example, by Unity animation events or 
 082            SetVisibility(visible: true);
 83
 84        private void SetVisibility(bool visible) => // Called by Hide
 085            isVisitble = visible;
 86
 87        //----------------------------------------------------------------------------------------  Unity callbacks meth
 88        private void Awake() // is used for getting references
 89        {
 090            animation = GetComponent<Animation>();
 091        }
 92
 93        private void Start() // is used for initialization logic
 94        {
 095            foreach (AnimationClip clip in clips)
 096                animation.AddClip(clip, clip.name);
 097        }
 98
 99        private void OnEnable() // is used for events subscription
 100        {
 0101            Closed.AddListener(OnClosed);
 0102        }
 103
 104        private void OnClosed(bool _) => // use _, __, ___ for parameters name if required parameters are not used insid
 0105            cooldown = MAX_TIMER;
 106
 107        private void OnDisable() // is used for events unsubscription
 108        {
 0109            Closed.RemoveListener(OnClosed);
 0110        }
 111
 112        private void OnDestroy() // is used for any needed clean-up
 113        {
 0114            Destroyed?.Invoke(this);
 0115        }
 116
 117        //----------------------------------------------------------------------------------------  internal-protected-p
 118        // methods that weren't called inside methods above 👆
 0119        internal void Method1() { }
 0120        protected void Method2() { }
 0121        private void Method3() { }
 122
 123        //----------------------------------------------------------------------------------------  Nested classes/struc
 124        private struct Data
 125        {
 126            public int A;
 127            public bool B;
 128        }
 129    }
 130}