-
Notifications
You must be signed in to change notification settings - Fork 7
Create Your Own
UdonToolkit is not just a set of prebuilt behaviours, but also a UI system built using Unity's Custom Property Drawers and Attributes that allows you to quickly create user friendly UI. It also manages all of the data syncing behind the scenes.
Creating a custom controller for your Udon Behaviour goes as follows
- Prepare a new GameObject with an UdonBehaviour you want to control
- Create a new folder called Controllers somewhere in your project
- Create a new C# class called
<YourBehaviourName>Controllerwhich inherits fromUTController
public class FogAdjustmentController : UTController {}- Define public variables in that class adding
[UdonPublic]attribute to them
[UdonPublic]
public float activeFogStart;- If you call the variables the same as in your Udon Behaviours - that's it. UTController class will take care of saving them on change for you. If you want to specify a different name for better readability in UI, while keeping the names inside of UdonBehaviours the same, you can pass a custom name
[UdonPublic("myCrypticName")]
public float userFriendlyNameHere;- And you're done! Now its time to add all the different variables and utilize attributes provided by UdonToolkit to make your UI shine.
- You can also use any of Unity's built-in attributes with
[UdonPublic], altho not everything is compatible with some of the more complex ones in the Toolkit, so just experiment and see what works! And if something breaks in the process - feel free to submit an issue ;)
Tip: You can use
UTTestControlleras a reference for your own
UTController provides some extra things apart from just syncing variables marked as [UdonPublic]. It stores a reference to the currently attached UdonBehaviour in the variable called uB so you can use it in your code, e.g. to make a button that sends a custom event in playmode.
[Button("Activate")]
public void Activate() {
if (uB == nul) return;
uB.SendCustomEvent("Activate");
}Another thing that might be useful when creating your own UIs is the SetupController override. This method is called every time before the main UI render so you can use it to check the current variables and maybe perform some actions based on that.
[HideInInspector] public bool isLinear;
// Udon Toolkit uses this in FogAdjustmentController to read the current fog mode and set an internal bool to display controls for the relevant fog type
public override void SetupController() {
isLinear = RenderSettings.fogMode == FogMode.Linear;
}
// Now we can use this value in [HideIf]
[HideIf("@isLinear")][UdonPublic] public float activeFogDensity;🚨 Found an issue? File an issue
💬 Join the Discord server
🕶 Support the project if you found it useful