Coder Social home page Coder Social logo

clouddevstudios / unity-editor-ui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from real-serious-games/unity-editor-ui

0.0 1.0 0.0 1.65 MB

A wrapper around the Unity editor GUI system for constructing editor windows using a fluent API instead of Unity's `OnGUI` functions.

License: MIT License

C# 100.00%

unity-editor-ui's Introduction

UnityEditorUI

A wrapper around the Unity editor GUI system for constructing editor windows using a fluent API instead of Unity's OnGUI functions.

This system supports two-way data binding between the UI and a ViewModel class, allowing you to create simpler, unit testable code for editor extensions by moving the logic and the UI code into separate classes.

Constructing editor windows

Set up a simple editor window with a label and a button:

// Create an instance of the view you want to bind the UI to
var viewModel = new ExampleView();

// Create the UI
var gui = new UnityEditorUI.GUI();
gui.Root()
    .Label()
        .Text.Value("My new editor window")
    .End()
    .Button()
        .Text.Value("Do something!")
        .Click.Bind(() => viewModel.DoSomething())
        .Tooltip.Value("Click to trigger an event")
    .End()
    
// Bind the UI to the view
gui.BindViewModel(viewModel);

And then render and update it by adding the following line to your editor window's existing OnGUI() method:

gui.OnGUI();

Every property on a GUI widget can have its value set to a constant value using .Value(), or bound to another property using .Bind(). If the class being bound to implements INotifyPropertyChanged, this will set up a two way data binding, so that properties in the bound class get updated when the UI changes and the UI gets .

Examples

The project in the Examples directory has been tested with Unity 5.2.3p2 and should contain everything you need to load up and run the examples. Since this library is purely for Unity editor extensions, there is no scene included in the project.

Example 1

This example shows the most basic sample of a use case for the UnityEditorUI system, binding a Unity editor window to a simple view model class but not subscribing to property changed events.

Example 2

This example demonstrates how to set up a view model class that implements INotifyPropertyChanged and sends events back to the UI when properties are changed.

Widgets

Button

Clickable push button widget.

Bindable properties

  • Text : string
  • Tooltip : string
  • Width : int
  • Height : int

Bindable events

  • Click

Checkbox

Boolean check box widget.

Bindable properties

  • Checked : bool
  • Label : string

DateTimePicker

Widget for entering a date and time. Essentially a TextBox with date validation on it.

Bindable properties

  • Date : DateTime
  • Width : int
  • Height : int

DropdownBox

Drop-down selection field. Labels for individual items are set by calling the bound object's ToString() method.

Bindable properties

  • SelectedItem : object
  • Items : object[]
  • Label : string
  • Tooltip : string

Label

Widget for displaying read-only text.

Bindable properties

  • Text : string
  • Tooltip : string
  • Bold : bool
  • Width : int
  • Height : int

LayerPicker

Widget for selecting Unity layers.

Bindable properties

  • Label : string
  • SelectedLayers : string[]

Spacer

Inserts a space between other widgets

TextBox

Widget for entering text

Bindable properties

  • Text : string
  • Width : int
  • Height : int

Vector3Field

Widget for entering vectors with X, Y and Z coordinates.

Bindable properties

  • Label : string
  • Tooltip : string
  • Vector : Vector3

Layouts

RootLayout

HorizontalLayout

VerticalLayout

unity-editor-ui's People

Contributors

ashleydavis avatar rorydungan 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.