Skip to content

Commit 4e52ea3

Browse files
committed
Update: README
1 parent 3363326 commit 4e52ea3

12 files changed

Lines changed: 460 additions & 1 deletion

README.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,233 @@
11
# DebugUI
22
A framework for building debugging tools built on Unity UI Toolkit.
33

4+
[![license](https://img.shields.io/badge/LICENSE-MIT-green.svg)](LICENSE)
5+
![unity-version](https://img.shields.io/badge/unity-2022.1+-000.svg)
6+
[![releases](https://img.shields.io/github/release/AnnulusGames/DebugUI.svg)](https://github.com/AnnulusGames/DebugUI/releases)
7+
8+
[日本語版READMEはこちら](README_JA.md)
9+
10+
DebugUI is a framework for building debugging tools on Unity UI Toolkit. You can easily and quickly create runtime debugging tools using its dedicated builder.
11+
12+
```cs
13+
public class DemoUIBuilder : DebugUIBuilderBase
14+
{
15+
...
16+
17+
protected override void Configure(IDebugUIBuilder builder)
18+
{
19+
builder.ConfigureWindowOptions(options =>
20+
{
21+
options.Title = "Demo";
22+
options.Draggable = true;
23+
});
24+
25+
builder.AddFoldout("Physics", builder =>
26+
{
27+
builder.AddSlider("Time Scale", 0f, 3f, () => Time.timeScale, x => Time.timeScale = x);
28+
builder.AddSlider("Gravity Scale", 0f, 3f, () => GravityScale, x => GravityScale = x);
29+
builder.AddButton("Add Circle", () => Instantiate(prefab));
30+
builder.AddButton("Reload Scene", () => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex));
31+
});
32+
33+
builder.AddFoldout("Post-processing", builder =>
34+
{
35+
builder.AddSlider("Hue Shift", -180f, 180f, () => colorAdjustments.hueShift.value, x => colorAdjustments.hueShift.value = x);
36+
builder.AddSlider("Bloom Intensity", 0f, 10f, () => bloom.intensity.value, x => bloom.intensity.value = x);
37+
});
38+
}
39+
}
40+
```
41+
42+
![img](docs/images/img1.png)
43+
44+
## Setup
45+
46+
### Requirements
47+
48+
* Unity 2022.1 or later
49+
50+
### Installation
51+
52+
1. Open the Package Manager from Window > Package Manager.
53+
2. Click the "+" button > Add package from git URL.
54+
3. Enter the following URL:
55+
56+
```
57+
https://github.com/AnnulusGames/DebugUI.git?path=src/DebugUI/Assets/DebugUI
58+
```
59+
60+
Alternatively, open Packages/manifest.json and add the following to the dependencies block:
61+
62+
```json
63+
{
64+
"dependencies": {
65+
"com.annulusgames.debug-ui": "https://github.com/AnnulusGames/DebugUI.git?path=src/DebugUI/Assets/DebugUI"
66+
}
67+
}
68+
```
69+
70+
## Creating a Debug Window
71+
72+
To create a debug window using DebugUI, follow these steps.
73+
74+
### 1A. Create a component that inherits from DebugUIBuilderBase
75+
76+
Inherit from the `DebugUIBuilderBase` class, and by implementing the `Configure()` method, you can easily configure a debug window.
77+
78+
```cs
79+
using UnityEngine;
80+
using DebugUI;
81+
82+
public class DebugUIBuilerExample : DebugUIBuilderBase
83+
{
84+
[SerializeField] float field;
85+
86+
protected override void Configure(IDebugUIBuilder builder)
87+
{
88+
builder.AddLabel("Label");
89+
builder.AddButton("Button", () => Debug.Log("Hello!"));
90+
builder.AddField("Field", () => field, x => field = x);
91+
}
92+
}
93+
```
94+
95+
![img](docs/images/img2.png)
96+
97+
Attach this component to a suitable GameObject and specify the target UIDocument in the Inspector.
98+
99+
`DebugUIBuilderBase` is a class that inherits from `MonoBehaviour`. It creates a debug window on the UIDocument set at Awake time.
100+
101+
### 1B. Use the DebugUIBuilder class
102+
103+
If you want to avoid adding a new component, you can also create a debug window using the `DebugUIBuilder` class.
104+
105+
```cs
106+
UIDocument uiDocument;
107+
108+
var builder = new DebugUIBuilder();
109+
builder.AddLabel("Label");
110+
builder.AddButton("Button", () => Debug.Log("Hello!"));
111+
builder.AddField("Field", () => field, x => field = x);
112+
builder.BuildWith(uiDocument);
113+
```
114+
115+
To build the configured debug window, call the `BuildWith()` method.
116+
117+
### 2. Apply the Theme Style Sheet
118+
119+
DebugUI provides a StyleSheet (uss) and Theme StyleSheet (tss) for a modern GUI style. (The files are located in the `Packages/com.annulusgames.debug-ui/Package Resources` folder.)
120+
121+
You can change the theme you want to use in the Panel Settings asset generated in the Assets folder when you introduce the UI Toolkit.
122+
123+
![img](docs/images/img3.png)
124+
125+
If you want to use an existing theme, add the DebugUI uss to the Style Sheets of the tss asset you want to use.
126+
127+
## Available Elements
128+
129+
### Label
130+
131+
![img](docs/images/example-label.png)
132+
133+
```cs
134+
builder.AddLabel("Label");
135+
```
136+
137+
### Button
138+
139+
![img](docs/images/example-button.png)
140+
141+
```cs
142+
builder.AddButton("Button", () => Debug.Log("Hello!"));
143+
```
144+
145+
### Field
146+
147+
![img](docs/images/example-field.png)
148+
149+
```cs
150+
float floatValue;
151+
152+
builder.AddField("Field", () => floatValue, x => floatValue = x);
153+
builder.AddField("Read-Only Field", () => floatValue);
154+
```
155+
156+
> [!NOTE]
157+
> `AddField()` currently supports `bool`, `int`, `float`, `string`, `Vector2`, `Vector3`, `Vector4`, `Vector2Int`, `Vector3Int`, `Rect`, `RectInt`, `Bounds`, and `BoundsInt`.
158+
159+
> [!TIP]
160+
> Fields created with `AddField()` are bidirectionally bound to the target value. Changes made to either the field or the original value are automatically reflected in the other.
161+
162+
### Slider
163+
164+
![img](docs/images/example-slider.png)
165+
166+
```cs
167+
float floatValue;
168+
int intValue;
169+
170+
builder.AddSlider("Slider", 0f, 1f, () => floatValue, x => floatValue = x);
171+
builder.AddSlider("Slider Int", 0, 100, () => intValue, x => intValue = x);
172+
```
173+
174+
### Progress Bar
175+
176+
![img](docs/images/example-progress.png)
177+
178+
```cs
179+
float floatValue;
180+
181+
builder.AddProgressBar("Progress", 0f, 1f, () => floatValue);
182+
```
183+
184+
### Image
185+
186+
![img](docs/images/example-image.png)
187+
188+
```cs
189+
Texture2D texture2D;
190+
Sprite sprite;
191+
RenderTexture renderTexture;
192+
SpriteRenderer spriteRenderer;
193+
194+
builder.AddImage("Texture2D", texture2D);
195+
builder.AddImage("Sprite", sprite);
196+
builder.AddImage("Render Texture", renderTexture);
197+
builder.AddImage("Dynamic", () => spriteRenderer.sprite);
198+
```
199+
200+
### Foldout
201+
202+
![img](docs/images/example-foldout.png)
203+
204+
```cs
205+
float floatValue;
206+
207+
builder.AddFoldout("Foldout", builder =>
208+
{
209+
builder.AddField("Field", () => floatValue, x => floatValue = x);
210+
builder.AddButton("Button", () => Debug.Log("Hello!"));
211+
});
212+
```
213+
214+
## Window Settings
215+
216+
You can configure window display options and other settings using `ConfigureWindowOptions()`.
217+
218+
```cs
219+
builder.ConfigureWindowOptions(options =>
220+
{
221+
options.Title = "Custom Title";
222+
options.Draggable = false;
223+
});
224+
```
225+
226+
| Property | Description |
227+
| --------- | ------------------------------------------------------- |
228+
| Draggable | Whether the window is draggable (default value is true) |
229+
| Title | Title of the window |
230+
231+
## License
232+
233+
[MIT License](LICENSE)

0 commit comments

Comments
 (0)