-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleRule.cs
More file actions
38 lines (33 loc) · 1.03 KB
/
StyleRule.cs
File metadata and controls
38 lines (33 loc) · 1.03 KB
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
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
namespace CodeName.Styling
{
[InlineProperty]
[Serializable]
public class StyleRule<T>
{
[ListDrawerSettings(CustomAddFunction = nameof(Inspector_AddSelector))]
[SerializeField] private List<StyleRuleSelector<T>> selectors = new();
public List<StyleRuleSelector<T>> Selectors => selectors;
public T GetValue(IStyleClassNode node)
{
// Selectors at the end of the list override the ones before.
// Only the last selector matters -> Use reverse for loop.
for (var i = selectors.Count - 1; i >= 0; i--)
{
var selector = selectors[i];
if (selector.IsMatch(node))
{
return selector.Value;
}
}
return default;
}
private void Inspector_AddSelector()
{
selectors.Add(new StyleRuleSelector<T>());
}
}
}