A C# UI component library, inspired by the design principles of shadcn/ui, providing a set of reusable and customizable GUI components for .NET applications.
To use shadcnui in your C# project:
-
Clone the repository:
git clone https://github.com/official-notfishvr/shadcn-ui.git cd shadcnui -
Open the solution: Open
shadcnui.slnin Visual Studio. -
Build the solution: Build the
shadcnuiproject to compile the component library. -
Reference the library: In your target C# project, add a reference to the compiled
shadcnui.dll(found inshadcnui/bin/Debug/orshadcnui/bin/Release/after building).
To embed shadcnui.dll into your project for a single-file distribution, follow these steps:
-
Copy the DLL: Copy
shadcnui.dllto a folder in your project, for example, aLibsfolder. -
Modify your
.csprojfile: Add the following to your.csprojfile, replacingLibs/shadcnui.dllwith the actual path to the DLL.<ItemGroup> <Reference Include="shadcnui"> <HintPath>Libs/shadcnui.dll</HintPath> <Private>false</Private> <!-- Do not copy to output --> </Reference> <EmbeddedResource Include="Libs/shadcnui.dll" /> </ItemGroup>
-
Add an Assembly Loader: Add the following
AssemblyLoaderclass to your project.using System; using System.Reflection; namespace YourProjectNamespace { public static class AssemblyLoader { static AssemblyLoader() { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { if (args.Name.Contains("shadcnui")) { // The resource name is YourProjectNamespace.Libs.shadcnui.dll // The name is constructed from the default namespace and the path to the file. using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("YourProjectNamespace.Libs.shadcnui.dll")) { if (stream == null) return null; byte[] assemblyData = new byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } } return null; }; } public static void Init() { } } }
Important: The resource name in
GetManifestResourceStreamis crucial. It is formed by combining the default namespace of your project and the path to the DLL file (with path separators replaced by dots). For example, if your project's default namespace isMyPluginand you placedshadcnui.dllin aLibsfolder, the resource name will beMyPlugin.Libs.shadcnui.dll. -
Initialize the Loader: Call
AssemblyLoader.Init()at your project's entry point.
Once referenced, you can integrate shadcnui components into your application. This library is designed with Unity's IMGUI system in mind, leveraging GUILayout for flexible UI layouts.
For more examples, please see the shadcnui testing project in the solution.
Here is a basic example of how to use the Button component:
using shadcnui;
using shadcnui.GUIComponents;
using UnityEngine;
public class ExampleUI : MonoBehaviour
{
private GUIHelper guiHelper;
private Rect windowRect = new Rect(20, 20, 400, 500);
private bool showWindow = true;
void Start()
{
guiHelper = new GUIHelper();
}
void OnGUI()
{
if (showWindow)
{
windowRect = GUI.Window(102, windowRect, (GUI.WindowFunction)DrawWindow, "Button Demo");
}
}
void DrawWindow(int windowID)
{
guiHelper.BeginVerticalGroup(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
guiHelper.Label("Button", LabelVariant.Default);
guiHelper.MutedLabel("Displays a button or a clickable element that activates an event.");
guiHelper.HorizontalSeparator();
guiHelper.Label("Button Variants", LabelVariant.Default);
guiHelper.BeginHorizontalGroup();
guiHelper.Button("Default");
guiHelper.Button("Destructive", ButtonVariant.Destructive);
guiHelper.Button("Outline", ButtonVariant.Outline);
guiHelper.Button("Secondary", ButtonVariant.Secondary);
guiHelper.Button("Ghost", ButtonVariant.Ghost);
guiHelper.Button("Link", ButtonVariant.Link);
guiHelper.EndHorizontalGroup();
guiHelper.Label("Code: guiHelper.Button(label, variant, size, onClick, disabled);", LabelVariant.Muted);
guiHelper.HorizontalSeparator();
guiHelper.Label("Button Sizes", LabelVariant.Default);
guiHelper.BeginHorizontalGroup();
guiHelper.Button("Default", ButtonVariant.Default, ButtonSize.Default);
guiHelper.Button("Small", ButtonVariant.Default, ButtonSize.Small);
guiHelper.Button("Large", ButtonVariant.Default, ButtonSize.Large);
guiHelper.Button("Icon", ButtonVariant.Default, ButtonSize.Icon);
guiHelper.EndHorizontalGroup();
guiHelper.Label("Code: guiHelper.Button(label, variant, size);", LabelVariant.Muted);
guiHelper.HorizontalSeparator();
GUILayout.EndVertical();
GUI.DragWindow();
}
}- Fix Styles that are borken if there is any
- Fix the Custom Font not working for IL2CPP
We welcome contributions to the shadcnui project! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-nameorbugfix/your-bug-fix. - Make your changes and ensure they adhere to the existing coding style.
- Write unit tests for new features or bug fixes.
- Ensure all tests pass.
- Commit your changes with a clear and concise commit message.
- Push your branch to your forked repository.
- Open a Pull Request to the
mainbranch of the original repository.
Please ensure your pull requests are well-documented and address a specific issue or feature.