├── .gitignore
├── AbstractLayout.cs
├── AbstractWidget.cs
├── Button.cs
├── Checkbox.cs
├── DateTimePicker.cs
├── DropdownBox.cs
├── EventBinding.cs
├── Examples
├── Assets
│ ├── Example1.cs
│ ├── Example1.cs.meta
│ ├── Example2.cs
│ ├── Example2.cs.meta
│ ├── RSG.Toolkit.dll
│ ├── RSG.Toolkit.dll.meta
│ ├── UnityEditorUI_Editor.dll
│ └── UnityEditorUI_Editor.dll.meta
└── ProjectSettings
│ ├── AudioManager.asset
│ ├── DynamicsManager.asset
│ ├── EditorBuildSettings.asset
│ ├── EditorSettings.asset
│ ├── GraphicsSettings.asset
│ ├── InputManager.asset
│ ├── NavMeshAreas.asset
│ ├── NetworkManager.asset
│ ├── Physics2DSettings.asset
│ ├── ProjectSettings.asset
│ ├── ProjectVersion.txt
│ ├── QualitySettings.asset
│ ├── TagManager.asset
│ ├── TimeManager.asset
│ ├── UnityAdsSettings.asset
│ └── UnityAnalyticsManager.asset
├── GUI.cs
├── HorizontalLayout.cs
├── ILayout.cs
├── IWidget.cs
├── LICENSE
├── Label.cs
├── LayerPicker.cs
├── Properties
└── AssemblyInfo.cs
├── PropertyBinding.cs
├── README.md
├── RootLayout.cs
├── Spacer.cs
├── TextBox.cs
├── UnityEditorUI.csproj
├── UnityEditorUI.sln
├── Vector3Field.cs
├── VerticalLayout.cs
├── dlls
├── UnityEditor.dll
└── UnityEngine.dll
├── packages.config
└── packages
├── RSG.Toolkit.1.0.0.0
├── RSG.Toolkit.1.0.0.0.nupkg
└── lib
│ └── net35
│ └── RSG.Toolkit.dll
└── repositories.config
/.gitignore:
--------------------------------------------------------------------------------
1 | # OS generated files
2 | .DS_Store
3 | .DS_Store?
4 | ehthumbs.db
5 | Thumbs.db
6 | desktop.ini
7 |
8 | # Visual studio user specific files
9 | *.suo
10 | *.user
11 | *.userosscache
12 | *.sln.docstates
13 |
14 | # MonoDevelop user specific files
15 | *.userprefs
16 |
17 | # Build results
18 | [Dd]ebug/
19 | [Dd]ebugPublic/
20 | [Rr]elease/
21 | [Rr]eleases/
22 | x64/
23 | x86/
24 | build/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 |
29 | .vs/
30 |
31 | *.log
32 | *.orig
33 |
34 | # Unity
35 | **/Library/
36 | **/Temp/
37 | **/Builds/
38 | Examples/*.sln
39 | Examples/*.csproj
--------------------------------------------------------------------------------
/AbstractLayout.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using RSG.Utils;
6 |
7 | namespace UnityEditorUI
8 | {
9 | ///
10 | /// Layouts are widgets that can contain other child widgets. All layouts should inherit from AbstractLayout.
11 | ///
12 | internal abstract class AbstractLayout : AbstractWidget, ILayout
13 | {
14 | protected bool enabled = true;
15 |
16 | private PropertyBinding enabledProperty;
17 |
18 | ///
19 | /// Whether or not to draw this layout and its sub-widgets (default is true).
20 | ///
21 | public IPropertyBinding Enabled { get { return enabledProperty; } }
22 |
23 | private List children = new List();
24 |
25 | protected AbstractLayout(ILayout parent) :
26 | base(parent)
27 | {
28 | enabledProperty = new PropertyBinding(
29 | this,
30 | value => this.enabled = value
31 | );
32 | }
33 |
34 | public override void OnGUI()
35 | {
36 | children.Each(child => child.OnGUI());
37 | }
38 |
39 | public override void BindViewModel(object viewModel)
40 | {
41 | enabledProperty.BindViewModel(viewModel);
42 |
43 | children.Each(child => child.BindViewModel(viewModel));
44 | }
45 |
46 | ///
47 | /// Creates a new button and adds it to the layout.
48 | ///
49 | public IButton Button()
50 | {
51 | var newButton = new Button(this);
52 | children.Add(newButton);
53 | return newButton;
54 | }
55 |
56 | ///
57 | /// Creates a new label and adds it to the view.
58 | ///
59 | public ILabel Label()
60 | {
61 | var newLabel = new Label(this);
62 | children.Add(newLabel);
63 | return newLabel;
64 | }
65 |
66 | ///
67 | /// Creates a new TextBox and adds it to the layout.
68 | ///
69 | public ITextBox TextBox()
70 | {
71 | var newTextBox = new TextBox(this);
72 | children.Add(newTextBox);
73 | return newTextBox;
74 | }
75 |
76 | ///
77 | /// Widget for choosing dates, similar do TextBox except with date validation built-in.
78 | ///
79 | public IDateTimePicker DateTimePicker()
80 | {
81 | var newDateTimePicker = new DateTimePicker(this);
82 | children.Add(newDateTimePicker);
83 | return newDateTimePicker;
84 | }
85 |
86 | ///
87 | /// Creates a new drop-down selection box and adds it to the layout.
88 | ///
89 | public IDropdownBox DropdownBox()
90 | {
91 | var newDropdownBox = new DropdownBox(this);
92 | children.Add(newDropdownBox);
93 | return newDropdownBox;
94 | }
95 |
96 | ///
97 | /// Creates a new checkbox and adds it to the layout.
98 | ///
99 | public ICheckbox Checkbox()
100 | {
101 | var newCheckbox = new Checkbox(this);
102 | children.Add(newCheckbox);
103 | return newCheckbox;
104 | }
105 |
106 | ///
107 | /// Creates a Vector3 field with X, Y and Z entry boxes.
108 | ///
109 | public IVector3Field Vector3Field()
110 | {
111 | var newVector3Field = new Vector3Field(this);
112 | children.Add(newVector3Field);
113 | return newVector3Field;
114 | }
115 |
116 | ///
117 | /// Creates a widget for editing layer masks.
118 | ///
119 | public ILayerPicker LayerPicker()
120 | {
121 | var newLayerPicker = new LayerPicker(this);
122 | children.Add(newLayerPicker);
123 | return newLayerPicker;
124 | }
125 |
126 | ///
127 | /// Inserts a space between other widgets.
128 | ///
129 | public ILayout Spacer()
130 | {
131 | var newSpacer = new Spacer(this);
132 | children.Add(newSpacer);
133 | return this;
134 | }
135 |
136 | ///
137 | /// Creates a VerticalLayout and adds it to this layout.
138 | ///
139 | public ILayout VerticalLayout()
140 | {
141 | var newLayout = new VerticalLayout(this);
142 | children.Add(newLayout);
143 | return newLayout;
144 | }
145 |
146 | ///
147 | /// Creates a horizontal layout and adds it to this layout.
148 | ///
149 | public ILayout HorizontalLayout()
150 | {
151 | var newLayout = new HorizontalLayout(this);
152 | children.Add(newLayout);
153 | return newLayout;
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/AbstractWidget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace UnityEditorUI
7 | {
8 | ///
9 | /// Abstract class that all other widgets must implement.
10 | ///
11 | internal abstract class AbstractWidget : IWidget
12 | {
13 | ///
14 | /// Needed in order to get back to the parent via the End() method.
15 | ///
16 | private ILayout parent;
17 |
18 | ///
19 | /// Creates the widget and sets its parent.
20 | ///
21 | protected AbstractWidget(ILayout parent)
22 | {
23 | this.parent = parent;
24 | }
25 |
26 | ///
27 | /// Updates this widget and all children (if it is a layout)
28 | ///
29 | public abstract void OnGUI();
30 |
31 | ///
32 | /// Binds the properties and events in this widget to corrosponding ones in the supplied view model.
33 | ///
34 | public abstract void BindViewModel(object viewModel);
35 |
36 | ///
37 | /// Fluent API for getting the layout containing this widget.
38 | ///
39 | public ILayout End()
40 | {
41 | return parent;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Button.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using UnityEngine;
6 |
7 | namespace UnityEditorUI
8 | {
9 | ///
10 | /// Clickable push button widget.
11 | ///
12 | public interface IButton : IWidget
13 | {
14 | ///
15 | /// Text to be displayed on the button.
16 | ///
17 | IPropertyBinding Text { get; }
18 |
19 | ///
20 | /// Tooltip displayed on mouse hover.
21 | ///
22 | IPropertyBinding Tooltip { get; }
23 |
24 | ///
25 | /// Width of the widget in pixels. Default uses auto-layout.
26 | ///
27 | IPropertyBinding Width { get; }
28 |
29 | ///
30 | /// Height of the widget in pixels. Default uses auto-layout.
31 | ///
32 | IPropertyBinding Height { get; }
33 |
34 | ///
35 | /// Event invoked when the button is clicked.
36 | ///
37 | IEventBinding Click { get; }
38 | }
39 |
40 | ///
41 | /// Clickable push button widget.
42 | ///
43 | internal class Button : AbstractWidget, IButton
44 | {
45 | // Private members
46 | private string text = String.Empty;
47 | private string tooltip = String.Empty;
48 | private int width = -1;
49 | private int height = -1;
50 |
51 | // Concrete property bindings
52 | private PropertyBinding textProperty;
53 | private PropertyBinding tooltipProperty;
54 | private PropertyBinding widthProperty;
55 | private PropertyBinding heightProperty;
56 | private EventBinding clickEvent;
57 |
58 | // Public interfaces for getting PropertyBindings
59 | public IPropertyBinding Text { get { return textProperty; } }
60 | public IPropertyBinding Tooltip { get { return tooltipProperty; } }
61 | public IPropertyBinding Width { get { return widthProperty; } }
62 | public IPropertyBinding Height { get { return heightProperty; } }
63 | public IEventBinding Click { get { return clickEvent; } }
64 |
65 | internal Button(ILayout parent) : base(parent)
66 | {
67 | textProperty = new PropertyBinding(
68 | this,
69 | value => this.text = value
70 | );
71 |
72 | tooltipProperty = new PropertyBinding(
73 | this,
74 | value => this.tooltip = value
75 | );
76 |
77 | widthProperty = new PropertyBinding(
78 | this,
79 | value => this.width = value
80 | );
81 |
82 | heightProperty = new PropertyBinding(
83 | this,
84 | value => this.height = value
85 | );
86 |
87 | clickEvent = new EventBinding(this);
88 | }
89 |
90 | public override void OnGUI()
91 | {
92 | var layoutOptions = new List();
93 | if(width >= 0)
94 | {
95 | layoutOptions.Add(GUILayout.Width(width));
96 | }
97 | if(height >= 0)
98 | {
99 | layoutOptions.Add(GUILayout.Height(height));
100 | }
101 |
102 | if (GUILayout.Button(new GUIContent(text, tooltip), layoutOptions.ToArray()))
103 | {
104 | clickEvent.Invoke();
105 | }
106 | }
107 |
108 | public override void BindViewModel(object viewModel)
109 | {
110 | textProperty.BindViewModel(viewModel);
111 | tooltipProperty.BindViewModel(viewModel);
112 | widthProperty.BindViewModel(viewModel);
113 | heightProperty.BindViewModel(viewModel);
114 | clickEvent.BindViewModel(viewModel);
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Checkbox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using UnityEditor;
6 |
7 | namespace UnityEditorUI
8 | {
9 | ///
10 | /// Boolean check box widget.
11 | ///
12 | public interface ICheckbox : IWidget
13 | {
14 | ///
15 | /// Whether or not the box is checked.
16 | ///
17 | IPropertyBinding Checked { get; }
18 |
19 | ///
20 | /// Text to display to the left of the check box.
21 | ///
22 | IPropertyBinding Label { get; }
23 | }
24 |
25 | ///
26 | /// Boolean check box widget.
27 | ///
28 | internal class Checkbox : AbstractWidget, ICheckbox
29 | {
30 | private bool boxChecked = false;
31 | private string label = String.Empty;
32 |
33 | private PropertyBinding boxCheckedProperty;
34 | private PropertyBinding labelProperty;
35 |
36 | public IPropertyBinding Checked { get { return boxCheckedProperty; } }
37 | public IPropertyBinding Label { get { return labelProperty; } }
38 |
39 | internal Checkbox(ILayout parent) : base(parent)
40 | {
41 | boxCheckedProperty = new PropertyBinding(
42 | this,
43 | value => this.boxChecked = value
44 | );
45 |
46 | labelProperty = new PropertyBinding(
47 | this,
48 | value => this.label = value
49 | );
50 | }
51 |
52 | public override void OnGUI()
53 | {
54 | if (boxChecked != (boxChecked = EditorGUILayout.Toggle(label, boxChecked)))
55 | {
56 | boxCheckedProperty.UpdateView(boxChecked);
57 | }
58 | }
59 |
60 | public override void BindViewModel(object viewModel)
61 | {
62 | boxCheckedProperty.BindViewModel(viewModel);
63 | labelProperty.BindViewModel(viewModel);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/DateTimePicker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Text;
6 | using UnityEngine;
7 | using UnityEditor;
8 |
9 | namespace UnityEditorUI
10 | {
11 | ///
12 | /// Widget for entering a date and time.
13 | ///
14 | public interface IDateTimePicker : IWidget
15 | {
16 | ///
17 | /// Date and time currently being displayed in the widget.
18 | ///
19 | IPropertyBinding Date { get; }
20 |
21 | ///
22 | /// Widget width in pixels. Default uses auto-layout.
23 | ///
24 | IPropertyBinding Width { get; }
25 |
26 | ///
27 | /// Widget height in pixels. Default uses auto-layout.
28 | ///
29 | IPropertyBinding Height { get; }
30 | }
31 |
32 | ///
33 | /// Widget for entering a date and time.
34 | ///
35 | internal class DateTimePicker : AbstractWidget, IDateTimePicker
36 | {
37 | private DateTime date;
38 | private string text;
39 | private bool textValid = true;
40 | private int width = -1;
41 | private int height = -1;
42 | private CultureInfo culture;
43 |
44 | private PropertyBinding dateProperty;
45 | private PropertyBinding widthProperty;
46 | private PropertyBinding heightProperty;
47 |
48 | public IPropertyBinding Date { get { return dateProperty; } }
49 | public IPropertyBinding Width { get { return widthProperty; } }
50 | public IPropertyBinding Height { get { return heightProperty; } }
51 |
52 | internal DateTimePicker(ILayout parent) : base(parent)
53 | {
54 | culture = CultureInfo.CreateSpecificCulture("en-AU");
55 |
56 | dateProperty = new PropertyBinding(
57 | this,
58 | value =>
59 | {
60 | this.date = value;
61 | this.text = date.ToString(culture);
62 | }
63 | );
64 |
65 | widthProperty = new PropertyBinding(
66 | this,
67 | value => this.width = value
68 | );
69 |
70 | heightProperty = new PropertyBinding(
71 | this,
72 | value => this.height = value
73 | );
74 | }
75 |
76 | public override void OnGUI()
77 | {
78 | var layoutOptions = new List();
79 | if (width >= 0)
80 | {
81 | layoutOptions.Add(GUILayout.Width(width));
82 | }
83 | if (height >= 0)
84 | {
85 | layoutOptions.Add(GUILayout.Height(height));
86 | }
87 |
88 | // Make the background of the widget red if the date is invalid.
89 | var savedColour = UnityEngine.GUI.backgroundColor;
90 | if (!textValid)
91 | {
92 | UnityEngine.GUI.backgroundColor = Color.red;
93 | }
94 | string newText = GUILayout.TextField(text, layoutOptions.ToArray());
95 | UnityEngine.GUI.backgroundColor = savedColour;
96 |
97 | // Update the date
98 | if (newText != text)
99 | {
100 | text = newText;
101 |
102 | textValid = DateTime.TryParse(text, culture, DateTimeStyles.None, out date);
103 | if (textValid)
104 | {
105 | dateProperty.UpdateView(date);
106 | }
107 | }
108 | }
109 |
110 | public override void BindViewModel(object viewModel)
111 | {
112 | dateProperty.BindViewModel(viewModel);
113 | widthProperty.BindViewModel(viewModel);
114 | heightProperty.BindViewModel(viewModel);
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/DropdownBox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using UnityEditor;
7 | using UnityEngine;
8 |
9 | namespace UnityEditorUI
10 | {
11 | ///
12 | /// Drop-down selection field.
13 | ///
14 | public interface IDropdownBox : IWidget
15 | {
16 | ///
17 | /// Currently selected item.
18 | ///
19 | IPropertyBinding