-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathTest.cs
More file actions
66 lines (52 loc) · 2.15 KB
/
Test.cs
File metadata and controls
66 lines (52 loc) · 2.15 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Linq;
using UnityEngine.UIElements;
using Random = UnityEngine.Random;
namespace Figma.Samples
{
using Attributes;
[Uxml("TestPage/TestFrame", UxmlDownloadImages.Everything, UxmlElementTypeIdentification.ByElementType)]
public class Test : Element
{
const int minCircles = 1;
const int maxCircles = 7;
#region Fields
[Query("Header")] Label header;
[Query("CloneButton", Clicked = nameof(Clone))] Button cloneButton;
[Query("RemoveButton", Clicked = nameof(Remove))] Button removeButton;
[Query("CloneContainer", StartRoot = true)] VisualElement cloneContainer;
[Query("CloneCircle", EndRoot = true)] PerfectCircle cloneCircle;
[Query("SyncButton", Clicked = nameof(Sync))] Button syncButton;
[Query("SyncContainer")] VisualElement syncContainer;
[Query("SyncContainer/SyncCircle")] PerfectCircle syncCircle;
[Query("FunctionDescription", Hide = true)] Label functionDescription;
#endregion
#region Methods
protected override void OnInitialize() => cloneContainer.style.flexWrap = Wrap.NoWrap;
protected override void OnRebuild() => header.text = "Welcome to Figma Test Frame!";
void Clone()
{
if (cloneContainer.childCount == maxCircles) return;
cloneCircle.Clone(cloneContainer);
}
void Remove()
{
if (cloneContainer.childCount == minCircles) return;
cloneContainer.Remove(cloneContainer.Children().First());
}
void Sync()
{
void RandomColor(int index) => syncContainer.Children().ElementAt(index).style.backgroundColor = Random.ColorHSV();
syncCircle.Sync(syncContainer, RandomColor, Enumerable.Range(0, Random.Range(1, maxCircles + 1)));
syncCircle.Hide();
functionDescription.Show();
}
#endregion
}
public class PerfectCircle : SyncButtonSimple<int>
{
public new class UxmlFactory : UxmlFactory<PerfectCircle> { }
#region Methods
public override bool IsVisible(int index, int data) => true;
#endregion
}
}