Code Monkey home page Code Monkey logo

unity-uitoolkit-base-field-example's Introduction

Unity Scaling Custom Base field Example

This repository contains the example and source used to create an unity base field. A blog post about how it was created and how it works can be found on codinglike.lieke.lgbt.

Problem

When creating your own custom fields in Unity UIToolkit they are hard to style like the default Unity fields. Unity uses the base-field class to style the fields. Unfortunately, how the base-field works is undocumented and difficult to emulate. This becomes a problem primarily during scaling as the fields will look quite different and not line up.

Solution

This USS let's you scale and style custom fields according to the unity standard. Letting you style your fields fast and easy.

Example

Possible fields that can be made with the USS:

Fields possible to make with the uss

Scaling the base fields in action:

The base field scaling correctly

What is it doing?

The USS was extracted by creating a IntegerField. Then going to the UI Toolkit Debugger and for each class copying the Unity USS. The classes it was copied from can be found in the USS. The total process and how it can be used is described in the blog post on codinglike.lieke.lgbt.

How to use it?

  • Copy the Uss from Assets/Editor/custom-base-field.uss into your project.
  • Add the classes custom-unity-field-container, custom-unity-field-label and custom-unity-field-value to the VisualElements.

Example usage:

<engine:VisualElement class="custom-unity-field-container">
    <engine:Label class="custom-unity-field-label" text="Custom integer field"></engine:Label>
    <editor:IntegerField class="custom-unity-field-value"></editor:IntegerField>
</engine:VisualElement>

More examples can be found in Assets/Editor/custom-base-field-layout.uxml

Problems with special custom fields

When creating special custom fields they sometimes have problems with the margins not being set to 0px. You can find more about this in the blog post.

unity-uitoolkit-base-field-example's People

Contributors

liekevanmulken avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.