Skip to content

Commit c20b90f

Browse files
Merge pull request 54739 from feature/sampleScene into master
1 parent ea7e305 commit c20b90f

File tree

12 files changed

+313
-32
lines changed

12 files changed

+313
-32
lines changed
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MonoBehaviour:
1212
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
1313
m_Name: Panel Settings
1414
m_EditorClassIdentifier:
15-
themeUss: {fileID: -4733365628477956816, guid: c46080814dc260f1a9419bf0e639a60b, type: 3}
15+
themeUss: {fileID: -4733365628477956816, guid: 999af05a3e7a25744b50c66afc0ac938, type: 3}
1616
m_TargetTexture: {fileID: 0}
1717
m_ScaleMode: 2
1818
m_Scale: 1

Assets/UI Theme.tss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import url("unity-theme://default");
2+
3+
@import url("/Packages/com.trackman.figma/Assets/UnityBase.uss");
4+
5+
VisualElement {}

Assets/UI Theme.tss.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/UnityBase.uss

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
:root {
2+
--selection-color: #5890DE;
3+
--cursor-color: #FFFFFF;
4+
}
5+
6+
.unity-base-field {
7+
flex-direction: row;
8+
margin: initial;
9+
overflow: hidden;
10+
flex-shrink: 0;
11+
--unity-sync-text-editor-engine: true;
12+
}
13+
14+
.unity-base-text-field {
15+
white-space: nowrap;
16+
--unity-selection-color: var(--selection-color);
17+
--unity-cursor-color: var(--cursor-color);
18+
}
19+
20+
.unity-base-field__input {
21+
flex: 1 0 0;
22+
overflow: hidden;
23+
margin: initial;
24+
}
25+
26+
.unity-base-text-field__input {
27+
padding: initial;
28+
border-radius: initial;
29+
cursor: initial;
30+
-unity-overflow-clip-box: content-box;
31+
flex: 1 1 auto;
32+
background-color: initial;
33+
border-color: initial;
34+
border-width: initial;
35+
margin: initial;
36+
--unity-sync-text-editor-engine: true;
37+
}
38+
39+
.unity-base-text-field__input:focus,
40+
.unity-base-text-field__input:hover,
41+
.unity-base-text-field:focus > .unity-base-text-field__input,
42+
.unity-base-text-field:hover > .unity-base-text-field__input {
43+
border-color: var(--selection-color);
44+
}
45+
46+
.unity-base-slider, .unity-base-slider__dragger, .unity-base-slider__tracker {
47+
border-width: initial;
48+
border-color: initial;
49+
background-color: initial;
50+
}
51+
.unity-base-slider:focus, .unity-base-slider__dragger, .unity-base-slider__tracker {
52+
border-color: initial;
53+
}
54+
55+
.unity-base-slider--vertical, .unity-base-slider__dragger, .unity-base-slider__tracker {
56+
margin: initial;
57+
}
58+
59+
.unity-scroller, .unity-base-slider__dragger, .unity-base-slider__tracker {
60+
border-color: initial;
61+
background-color: initial;
62+
}
63+
64+
.unity-scroller--vertical, .unity-base-slider__dragger, .unity-base-slider__tracker {
65+
left: initial;
66+
top: initial;
67+
margin: initial;
68+
border-width: initial;
69+
border-color: initial;
70+
background-color: initial;
71+
}
72+
.unity-scroller--vertical > .unity-scroller__slider {
73+
margin: initial;
74+
width: initial;
75+
}

Assets/UnityBase.uss.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Prefabs/Figma.prefab

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MonoBehaviour:
4545
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
4646
m_Name:
4747
m_EditorClassIdentifier:
48-
m_PanelSettings: {fileID: 0}
48+
m_PanelSettings: {fileID: 11400000, guid: f486055d8ec653edc96c3f3c38380c8f, type: 2}
4949
m_ParentUI: {fileID: 0}
5050
sourceAsset: {fileID: 0}
5151
m_SortingOrder: 0
@@ -63,3 +63,5 @@ MonoBehaviour:
6363
m_EditorClassIdentifier:
6464
title:
6565
filter: 0
66+
reorder: 0
67+
fontsDirs: []

Readme.md

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,76 @@ To start using Figma Inspector, a Figma Personal Access Token is needed for API
7171
4. Locate the Figma script in Unity's Inspector.
7272
5. Paste the token into the designated field.
7373

74-
## Figma class (TODO)
75-
## Element class (OnInitialize, OnRebuild, Custom Elements) (TODO)
74+
## Figma class (TOBEREVIEWED)
75+
During the update process the Figma class retrieves data based on the Uxml and Query attributes of the Element scripts. It then utilizes this data while producing UXML asset.
76+
> [!WARNING]
77+
> Element scripts should be attached to the same game object to which the Figma script is also attached.
78+
79+
## Element class (OnInitialize, OnRebuild, Custom Elements) (TOBEREVIEWED)
80+
The Uxml and Query attributes define the structure of the Uxml asset and, consequently, the appearance of your UI.
81+
The type of the field following the Query attribute defines the UI element itself and, consequently, its behavior (VisualElement, Button, Label, etc.). Field types are written into UXML. Therefore, if you change the field type (for example, from VisualElement to Button), you will need to perform a Figma Update to regenerate the UXML.
82+
Each element can override OnInitialize and OnRebuild methods which can be used to do any initial setup operations.
83+
7684
``` csharp
77-
[Uxml("SamplePage/SampleFrame", UxmlDownloadImages.Everything, UxmlElementTypeIdentification.ByElementType)]
78-
public class SampleFrame : Element
85+
[Uxml("TestPage/TestFrame", UxmlDownloadImages.Everything, UxmlElementTypeIdentification.ByElementType)]
86+
[AddComponentMenu("Figma/Samples/Test")]
87+
public class Test : Element
7988
{
80-
#region Fields
81-
[Query("SampleButton", Clicked = nameof(Test))] Button sampleButton;
82-
#endregion
89+
const int minCircles = 1;
90+
const int maxCircles = 7;
91+
92+
#region Fields
93+
[Query("Header")] Label header;
94+
95+
[Query("CloneButton", Clicked = nameof(Clone))] Button cloneButton;
96+
[Query("RemoveButton", Clicked = nameof(Remove))] Button removeButton;
97+
[Query("CloneContainer", StartRoot = true)] VisualElement cloneContainer;
98+
[Query("CloneCircle", EndRoot = true)] PerfectCircle cloneCircle;
99+
100+
[Query("SyncButton", Clicked = nameof(Sync))] Button syncButton;
101+
[Query("SyncContainer")] VisualElement syncContainer;
102+
[Query("SyncContainer/SyncCircle")] PerfectCircle syncCircle;
103+
104+
[Query("FunctionDescription", Hide = true)] Label functionDescription;
105+
#endregion
106+
107+
#region Methods
108+
protected override void OnInitialize() => cloneContainer.style.flexWrap = Wrap.NoWrap;
109+
protected override void OnRebuild() => header.text = "Welcome to Figma Test Frame!";
83110

84-
#region Methods
85-
void Test() => Debug.Log("Test");
86-
#endregion
111+
void Clone()
112+
{
113+
if (cloneContainer.childCount == maxCircles) return;
114+
115+
cloneCircle.Clone(cloneContainer);
116+
}
117+
void Remove()
118+
{
119+
if (cloneContainer.childCount == minCircles) return;
120+
121+
cloneContainer.Remove(cloneContainer.Children().First());
122+
}
123+
void Sync()
124+
{
125+
void RandomColor(int index) => syncContainer.Children().ElementAt(index).style.backgroundColor = Random.ColorHSV();
126+
127+
syncCircle.Sync(syncContainer, RandomColor, Enumerable.Range(0, Random.Range(1, maxCircles + 1)));
128+
syncCircle.Hide();
129+
130+
functionDescription.Show();
131+
}
132+
#endregion
133+
}
134+
```
135+
### Custom element example
136+
``` csharp
137+
public class PerfectCircle : SyncButtonSimple<int>
138+
{
139+
public new class UxmlFactory : UxmlFactory<PerfectCircle> { }
87140

141+
#region Methods
142+
public override bool IsVisible(int index, int data) => true;
143+
#endregion
88144
}
89145
```
90146

@@ -159,7 +215,7 @@ This interface serves as an identifier, signifying that within the IRootElement
159215
## IRootElement
160216
This interface acts as a marker, indicating that an element within the IRootElement hierarchy is capable of functioning as a component derived from the VisualElement class.
161217

162-
## Visual Element Style (TOBEREVIEWED)
218+
## Visual Element Style
163219
The imported USS file contains all the classes used by Visual Elements. USS is inspired by CSS and has a similar syntax. To manipulate properties in your code, you should use the techniques described below.
164220
### Changing Element Appearance
165221
To change the appearance of a VisualElement, you should manipulate its style properties. For example, to set the top margin of an element to 3:
@@ -173,7 +229,7 @@ float margin = element.resolvedStyle.marginTop;
173229
```
174230
> You can find the list of all supported properties in the official Unity documentation.
175231
176-
## Visual Element Extensions (TOBEREVIEWED)
232+
## Visual Element Extensions
177233
When working with VisualElements, there are various visual element extensions that allow you to find/clone/replace/etc elements:
178234
```csharp
179235
VisualElement rectangle = element.Find<VisualElement>("Rectangle");

~Samples/Images.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)