-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreGUIBindToUIExample.cs
More file actions
34 lines (30 loc) · 1.04 KB
/
CoreGUIBindToUIExample.cs
File metadata and controls
34 lines (30 loc) · 1.04 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
using UnityEngine;
// Use new C# feature to shorten calls to CoreGUI
using static CoreGUI;
public class CoreGUIBindToUIExample : MonoBehaviour
{
// Padding around RectTransform
public float padding = 4;
// Shortcut to rect transform
RectTransform rectTransform => GetComponent<RectTransform>();
private void OnGUI()
{
// Convert this RectTransform to Screen coordinate
// (CoreGUI built-in utility)
var rect = Utility.BindFromUIOverlay(rectTransform, padding);
// Tell CoreGUI to begin GUI calculation
BeginGUI(this, rect.PixelPerfect());
// Tell to draw the label on top (instead of left, which is the default)
using (Scoped.LabelOption(Side.Top))
{
// Draw a message
Label(C("This GUI is Binded from Rect Transform!"));
// Stretch to the end
FlexibleSpace();
// Draw read-only rectangle field
RectField(C("Screen position:"), rect);
}
// Done!
EndGUI();
}
}