Tanoda
ColorPresetManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
4
5namespace Assets.HSVPicker
6{
7 public static class ColorPresetManager
8 {
9 private static readonly Dictionary<string, ColorPresetList>
10 _presets = new Dictionary<string, ColorPresetList>();
11
12 public static ColorPresetList Get(string listId = "default")
13 {
14 ColorPresetList preset;
15 if (!_presets.TryGetValue(listId, out preset))
16 {
17 preset = new ColorPresetList(listId);
18 _presets.Add(listId, preset);
19 }
20
21 return preset;
22 }
23 }
24
25 public class ColorPresetList
26 {
27 public string ListId { get; }
28 public List<Color> Colors { get; }
29
30 public event UnityAction<List<Color>> OnColorsUpdated;
31
32 public ColorPresetList(string listId, List<Color> colors = null)
33 {
34 if (colors == null) colors = new List<Color>();
35
36 Colors = colors;
37 ListId = listId;
38 }
39
40 public void AddColor(Color color)
41 {
42 Colors.Add(color);
43 if (OnColorsUpdated != null) OnColorsUpdated.Invoke(Colors);
44 }
45
46 public void UpdateList(IEnumerable<Color> colors)
47 {
48 Colors.Clear();
49 Colors.AddRange(colors);
50
51 if (OnColorsUpdated != null) OnColorsUpdated.Invoke(Colors);
52 }
53 }
54}
UnityEngine.Color Color
Definition: TestScript.cs:32
ColorPresetList(string listId, List< Color > colors=null)
UnityAction< List< Color > > OnColorsUpdated
void UpdateList(IEnumerable< Color > colors)