Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
SliderBackgroundController.cs
Go to the documentation of this file.
1using System.Collections;
3using UnityEngine;
4using UnityEngine.UI;
5
7
8public class SliderBackgroundController : MonoBehaviour
9{
10 [SerializeField]
12
13 [SerializeField]
14 private RawImage sliderBackground;
15
17
18 private Color[] colorArray;
19
20 private void Awake()
21 {
22 colorPicker.ColorUpdated += UpdateBackround;
23 }
24
25 private void UpdateBackround(Color color)
26 {
28 }
29
30 private void GenerateSliderTexture()
31 {
32 Color[] array = ((parent.Type == SliderType.Hue) ? HueSlider.GenerateHsvSpectrum() : GenerateColorSpectrum());
33 Texture2D texture2D = new Texture2D(array.Length, 1);
34 for (int i = 0; i < texture2D.width; i++)
35 {
36 texture2D.SetPixel(i, 1, array[i]);
37 }
38 texture2D.Apply();
39 sliderBackground.texture = texture2D;
40 }
41
43 {
44 Color[] array = new Color[256];
45 for (int i = 0; i < 256; i++)
46 {
47 array[i] = GetColorByTypeAndIndex(i);
48 }
49 return array;
50 }
51
52 private Color GetColorByTypeAndIndex(int index)
53 {
54 Color selectedColor = colorPicker.SelectedColor;
55 switch (parent.Type)
56 {
57 case SliderType.Red:
58 return new Color((float)index / 255f, selectedColor.g, selectedColor.b, 1f);
59 case SliderType.Green:
60 return new Color(selectedColor.r, (float)index / 255f, selectedColor.b, 1f);
61 case SliderType.Blue:
62 return new Color(selectedColor.r, selectedColor.g, (float)index / 255f, 1f);
63 case SliderType.Sat:
64 {
65 float v = ((colorPicker.ValueHSV >= 0.3f) ? colorPicker.ValueHSV : 0.3f);
66 return new HSVColor(colorPicker.Hue, (float)index / 255f, v).ToRGB();
67 }
68 case SliderType.Val:
69 return new HSVColor(colorPicker.Hue, colorPicker.Saturation, (float)index / 255f).ToRGB();
70 case SliderType.Alpha:
71 return new Color(1f, 1f, 1f, (float)index / 255f);
72 default:
73 return Color.red;
74 }
75 }
76
78 {
79 this.parent = parent;
80 }
81
82 public void ToggleSliderMode()
83 {
84 StartCoroutine(DelayedUpdateBg());
85 }
86
87 private IEnumerator DelayedUpdateBg()
88 {
89 yield return null;
91 }
92}
static Color[] GenerateHsvSpectrum()
Definition: HueSlider.cs:55