summaryrefslogtreecommitdiff
path: root/Assets/Thirdparty/Tayx/Graphy - Ultimate Stats Monitor/Scene/Customization Scripts/ForceSliderToMultipleOf3.cs
blob: 8c7d2b351556d22872c5eb89be0d364e1e2e2784 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ---------------------------------------
 * Author:          Martin Pane (martintayx@gmail.com) (@tayx94)
 * Collaborators:   Lars Aalbertsen (@Rockylars)
 * Project:         Graphy - Ultimate Stats Monitor
 * Date:            05-Mar-18
 * Studio:          Tayx
 * 
 * This project is released under the MIT license.
 * Attribution is not required, but it is always welcomed!
 * -------------------------------------*/

using UnityEngine;
using UnityEngine.UI;

using System.Collections;

namespace Tayx.Graphy.CustomizationScene
{
	public class ForceSliderToMultipleOf3 : MonoBehaviour
	{
        /* ----- TODO: ----------------------------
         * Check if we can seal this class.
         * Add summaries to the variables.
         * Add summaries to the functions.
         * Check if we can remove "using System.Collections;".
         * Check if we should add "private" to the Unity Callbacks.
         * --------------------------------------*/

        #region Variables -> Serialized Private

        [SerializeField] private Slider m_slider = null;

        #endregion

        #region Methods -> Unity Callbacks

        void Start()
		{
			m_slider.onValueChanged.AddListener(UpdateValue);
		}

        #endregion

        #region Methods -> Private

        private void UpdateValue(float value)
		{
			int roundedValue = (int)value;
			
			// Forces the value to be a multiple of 3, this way the audio graph is painted correctly
			if (roundedValue % 3 != 0 && roundedValue < 300)
			{
				roundedValue += 3 - roundedValue % 3;
			}

			m_slider.value = roundedValue;
		}

        #endregion
    }
}