Skip to content

breadnone/UTK-Fluent-extension-for-UIToolkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

UTK-Fluent-extension-for-UIToolkit

A simple fluent extension for UIToolkit in Unity3D.
UTK is just a simple c# extension to make working with c# in UIToolkit bearable. You can still use UIToolkit documentation to work with this extension.

Requirement:
Unity 2022.2 and above.

sampleUtk

Example syntaxes:

//Set width & height property of VisualElement  
visualElement.Size(100, 100); //Pizel based size
visualElement.Size(100, 100, true, true) //Percent based size

//Or via width / height property
visualElement.Width(100, true).Height(100, true); //Uses boolean overload set to true for Percent/dynamic style

//Chaining  
visualElement.FlexRow().FlexGrow(1).BcgColor(Color.yellow);

//Will always return self can safely be cached when/wherever
var vis = visualElement.Margin(5, true).Padding(12); // sets margin on all sides with dynamic size.  

//Parenting. set parent flex in the end (AddChild will return the parent)
myParent.AddChild(vis1).AddChild(vis2).AddChild(vis3);

//Returns the parent
var visParent = myParent.AddChild(vis2); 

myChild.AddParent(myParent); //Sets parent from directly from child

//Hex color support
visualElement.BcgColor("#0063B1"); //Invalid hex code, will fallback to Color.clear.

//Rounded Corners + border
visualElement.RoundCorner(12, true).Border(12, Color.white);

//Events
//All events starts with `On`.. e.g: OnMouseEnter, OnFocusOut, OnPointerEnter
myTextField.OnValueChanged(x=>{Debug.Log(x.newValue);}); //Equal to RegisterValueChanged<T>.

//Equal to registerCallback<MouseDownEvent>();
visualElement.OnMouseDown(x=> {Debug.Log("Click!");}); 

//All registered events will be unregistered via DetachPanel (Or when removed from hierarchy)

Custom controls made with this extension(available in templates folder)
hXfRpQuBMNHawSiIB9TnSYbDUn5twnOdq7DtujgR FAvrHSn47NZk110dQuMbBBPAuj1OzUmWMNg3EnKN

About

A simple fluent extension for UIToolkit in Unity3D.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages