Different utilities that simplify development in Unity3D. They include extensions for common Unity structures such as Rect and Texture2D, different methods that make it easier to develop custom interfaces and property drawers, etc.
You can read the full documentation on the repository Wiki.
I'm adding new utilities as I write code for other Unity3D projects and discover some common patterns/methods I use throughout the codebase.
Once you have the OpenUPM cli, run the following command:
openupm install com.solidalloy.util
Or if you don't have it, add the scoped registry to manifest.json with the desired dependency semantic version:
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"com.solidalloy",
"com.openupm"
]
}
],
"dependencies": {
"com.solidalloy.util": "1.39.0"
},
Project supports Unity Package Manager. To install the project as a Git package do the following:
Creates padding to the left and right of a rectangle by narrowing it down.
Name | Description |
---|---|
rect | UnityEngine.Rect The bigger rect to create padding for. |
leftPadding | System.Single Width of the left padding in pixels. |
rightPadding | System.Single Width of the right padding in pixels. |
The smaller rect that appeared after creating paddings.
Rect innerToolbarArea = outerToolbarArea.AddHorizontalPadding(10f, 2f);
Places a rect with a smaller height vertically in the middle of a bigger rect.
Name | Description |
---|---|
rect | UnityEngine.Rect The bigger rect. |
height | System.Single The height of a smaller rect. |
The smaller rect with a given height that was aligned vertically in the middle of a bigger rect.
Rect innerToolbarArea = outerToolbarArea.AlignMiddleVertically(DropdownStyle.LabelHeight);
Cuts a big rect into two smaller ones by placing a vertical cut at cutDistance from the left or right border of the rect.
Name | Description |
---|---|
originalRect | UnityEngine.Rect The rect that should be split. |
cutDistance | System.Single The distance from the left or right border of the rect where to place vertical cut. |
fromRightBorder | System.Boolean Whether to count the distance from left or right border. |
Left and right rects that appeared after the cut.
(Rect searchFieldArea, Rect buttonArea) = innerToolbarArea.CutVertically(DropdownStyle.IconSize, true);
Rounds up x, y, width, and height of the rect.
Name | Description |
---|---|
rect | UnityEngine.Rect@ Rect to round coordinates for. |
popupArea.RoundUpCoordinates();
Implementation of the fuzzy search algorithm.
Determines if an item should be included in the search result and outputs its score (its position in the list of matching items.)
Name | Description |
---|---|
searchString | System.String Search string to compare the item to. |
itemName | System.String Name of the item to include in the result list. |
score | System.Int32@ Score of the item that determines how high in the result list it should be placed. |
Whether to include the result in the list.
EnumerateTree()
.Where(node => node.Type != null)
.Select(node =>
{
bool includeInSearch = FuzzySearch.CanBeIncluded(_searchString, node.FullTypeName, out int score);
return new { score, item = node, include = includeInSearch };
})
.Where(x => x.include)
.OrderByDescending(x => x.score)
.Select(x => x.item));
Different useful methods that simplify UnityEngine.GUILayout API.
Draws content in the horizontal direction.
Name | Description |
---|---|
drawContent | System.Action Action that draws the content. |
DrawHelper.DrawHorizontally(() =>
{
selectedValue = DrawSelectorDropdownAndGetSelectedValue();
if (Event.current.type == EventType.Repaint)
DrawHamburgerMenuButton();
});
Draws content in the vertical direction.
Name | Description |
---|---|
drawContent | System.Action Action that draws the content. |
DrawHelper.DrawVertically(() =>
{
EditorDrawHelper.DrawInfoMessage("No types to select.");
});