Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Editor/AnimatorParameterBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ protected override void OnInspector()
return;
}

BeginArea(new GUIContent("View"));

ShowAnimatorParametersMenu(
new GUIContent("View property", "Property on the view to bind to"),
new GUIContent("Property", "Property on the View to bind to"),
updatedValue =>
{
targetScript.AnimatorParameterName = updatedValue.Name;
Expand All @@ -74,7 +76,7 @@ out var viewPropertyType
EditorStyles.label.fontStyle = viewAdapterPrefabModified ? FontStyle.Bold : DefaultFontStyle;

ShowAdapterMenu(
new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
new GUIContent("Adapter", "Adapter that converts Values sent from the View-Model to the View."),
viewAdapterTypeNames,
targetScript.ViewAdapterId,
newValue =>
Expand All @@ -100,30 +102,35 @@ out var viewPropertyType
EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle;

ShowAdapterOptionsMenu(
"View adapter options",
"Options",
adapterType,
options => targetScript.ViewAdapterOptions = options,
targetScript.ViewAdapterOptions,
viewAdapterOptionsFade.faded
);

EndArea();

EditorGUILayout.Space();

BeginArea(new GUIContent("View-Model"));

EditorStyles.label.fontStyle = viewModelPropertyPrefabModified ? FontStyle.Bold : DefaultFontStyle;

var adaptedViewPropertyType = AdaptTypeBackward(viewPropertyType, targetScript.ViewAdapterId);
ShowViewModelPropertyMenu(
new GUIContent("View-model property", "Property on the view-model to bind to."),
new GUIContent("Property", "Property on the View-Model to bind to."),
TypeResolver.FindBindableProperties(targetScript),
updatedValue => targetScript.ViewModelPropertyName = updatedValue,
targetScript.ViewModelPropertyName,
property => property.PropertyType == adaptedViewPropertyType
);

GUI.enabled = guiPreviouslyEnabled;
EndArea();

EditorGUILayout.Space();
GUI.enabled = guiPreviouslyEnabled;

//EditorGUILayout.Space();
}

private void ShowAnimatorParametersMenu(
Expand Down
20 changes: 18 additions & 2 deletions Editor/BaseBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public sealed override void OnInspectorGUI()

if (_autoConnectionProperty != null)
{
EditorGUILayout.PropertyField(_autoConnectionProperty);
EditorGUILayout.PropertyField(_autoConnectionProperty, new GUIContent("Auto Connect", "Automatically bind once on \"OnEnable()\""));
}

OnInspector();
Expand Down Expand Up @@ -166,6 +166,21 @@ public OptionInfo(string menuName, BindableMember<PropertyInfo> property)
/// </summary>
private static readonly string NoneOptionString = "None";

protected void BeginArea(GUIContent label)
{
var style = EditorStyles.label.fontStyle;
EditorStyles.label.fontStyle = FontStyle.Bold;

EditorGUILayout.LabelField(label);
EditorGUI.indentLevel++;

EditorStyles.label.fontStyle = style;
}
protected void EndArea()
{
EditorGUI.indentLevel--;
}

/// <summary>
/// Display a popup menu for selecting a property from a view-model.
/// </summary>
Expand Down Expand Up @@ -267,6 +282,7 @@ out Type selectedPropertyType
/// Show dropdown for selecting a UnityEvent to bind to.
/// </summary>
protected void ShowEventMenu(
GUIContent label,
BindableEvent[] events,
Action<string> propertyValueSetter,
string curPropertyValue
Expand All @@ -281,7 +297,7 @@ string curPropertyValue
.ToArray();

var newSelectedIndex = EditorGUILayout.Popup(
new GUIContent("View event", "Event on the view to bind to."),
label,
selectedIndex,
content
);
Expand Down
21 changes: 16 additions & 5 deletions Editor/CollectionBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

EditorGUILayout.PropertyField(_templateInitialPoolCountProperty);
EditorGUILayout.PropertyField(_itemsContainerProperty);
EditorGUILayout.PropertyField(_templatesProperty, true);

BeginArea(new GUIContent("View-Model"));

EditorStyles.label.fontStyle = _viewModelPrefabModified ? FontStyle.Bold : DefaultFontStyle;
ShowViewModelPropertyMenu(
new GUIContent("View-model property", "Property on the view-model to bind to."),
new GUIContent("Property", "Property on the View-Model to bind to."),
TypeResolver.FindBindableCollectionProperties(_targetScript),
updatedValue => _targetScript.ViewModelPropertyName = updatedValue,
_targetScript.ViewModelPropertyName,
property => true
);

EndArea();

EditorGUILayout.Space();

BeginArea(new GUIContent("Templates Settings"));

EditorGUILayout.PropertyField(_templateInitialPoolCountProperty, new GUIContent("Initial Pool Count"));
EditorGUILayout.PropertyField(_itemsContainerProperty, new GUIContent("Container"));

EditorGUILayout.PropertyField(_templatesProperty, new GUIContent("Templates", "Templates for Collection"), true);

EndArea();
}

/// <summary>
Expand Down
18 changes: 14 additions & 4 deletions Editor/EventBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,48 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

BeginArea(new GUIContent("View"));

EditorStyles.label.fontStyle = viewEventPrefabModified
? FontStyle.Bold
: DefaultFontStyle;

ShowEventMenu(
new GUIContent("Event", "Event on the View to bind to."),
UnityEventWatcher.GetBindableEvents(targetScript.gameObject)
.OrderBy(evt => evt.Name)
.ToArray(),
updatedValue => targetScript.ViewEventName = updatedValue,
targetScript.ViewEventName
);

EndArea();

EditorGUILayout.Space();

BeginArea(new GUIContent("View-Model"));

EditorStyles.label.fontStyle = viewModelMethodPrefabModified
? FontStyle.Bold
: DefaultFontStyle;

ShowMethodMenu(targetScript, TypeResolver.FindBindableMethods(targetScript));
ShowMethodMenu(new GUIContent("Method", "Method on the view - model to bind to."), targetScript, TypeResolver.FindBindableMethods(targetScript));

EndArea();
}

/// <summary>
/// Draws the dropdown for selecting a method from bindableViewModelMethods
/// </summary>
private void ShowMethodMenu(
GUIContent label,
EventBinding targetScript,
BindableMember<MethodInfo>[] bindableMethods
)
{
var tooltip = "Method on the view-model to bind to.";

InspectorUtils.DoPopup(
new GUIContent(targetScript.ViewModelMethodName),
new GUIContent("View-model method", tooltip),
label,
m => m.ViewModelType + "/" + m.MemberName,
m => true,
m => m.ToString() == targetScript.ViewModelMethodName,
Expand Down
37 changes: 23 additions & 14 deletions Editor/OneWayPropertyBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

var defaultLabelStyle = EditorStyles.label.fontStyle;
//var defaultLabelStyle = EditorStyles.label.fontStyle;

BeginArea(new GUIContent("View"));

EditorStyles.label.fontStyle = viewPropertyPrefabModified
? FontStyle.Bold
: defaultLabelStyle;
: DefaultFontStyle;

Type viewPropertyType;
ShowViewPropertyMenu(
new GUIContent("View property", "Property on the view to bind to"),
new GUIContent("Property", "Property on the View to bind to"),
PropertyFinder.GetBindableProperties(targetScript.gameObject),
updatedValue => targetScript.ViewPropertyName = updatedValue,
targetScript.ViewPropertyName,
Expand All @@ -65,12 +68,12 @@ out viewPropertyType

EditorStyles.label.fontStyle = viewAdapterPrefabModified
? FontStyle.Bold
: defaultLabelStyle;
: DefaultFontStyle;

ShowAdapterMenu(
new GUIContent(
"View adapter",
"Adapter that converts values sent from the view-model to the view."
"Adapter",
"Adapter that converts values sent from the View-Model to the View."
),
viewAdapterTypeNames,
targetScript.ViewAdapterId,
Expand All @@ -79,15 +82,15 @@ out viewPropertyType
// Get rid of old adapter options if we changed the type of the adapter.
if (newValue != targetScript.ViewAdapterId)
{
Undo.RecordObject(targetScript, "Set view adapter options");
Undo.RecordObject(targetScript, "Set view adapter Options");
targetScript.ViewAdapterOptions = null;
}

UpdateProperty(
updatedValue => targetScript.ViewAdapterId = updatedValue,
targetScript.ViewAdapterId,
newValue,
"Set view adapter"
"Set View Adapter"
);
}
);
Expand All @@ -100,40 +103,46 @@ out adapterType

EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified
? FontStyle.Bold
: defaultLabelStyle;
: DefaultFontStyle;

ShowAdapterOptionsMenu(
"View adapter options",
"Options",
adapterType,
options => targetScript.ViewAdapterOptions = options,
targetScript.ViewAdapterOptions,
viewAdapterOptionsFade.faded
);

EndArea();

EditorGUILayout.Space();

BeginArea(new GUIContent("View-Model"));

EditorStyles.label.fontStyle = viewModelPropertyPrefabModified
? FontStyle.Bold
: defaultLabelStyle;
: DefaultFontStyle;

var adaptedViewPropertyType = AdaptTypeBackward(
viewPropertyType,
targetScript.ViewAdapterId
);
ShowViewModelPropertyMenu(
new GUIContent(
"View-model property",
"Property on the view-model to bind to."
"Property",
"Property on the View-Model to bind To."
),
TypeResolver.FindBindableProperties(targetScript),
updatedValue => targetScript.ViewModelPropertyName = updatedValue,
targetScript.ViewModelPropertyName,
property => property.PropertyType == adaptedViewPropertyType
);

EndArea();

GUI.enabled = guiPreviouslyEnabled;

EditorStyles.label.fontStyle = defaultLabelStyle;
//EditorStyles.label.fontStyle = DefaultFontStyle;
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions Editor/SubViewModelBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

BeginArea(new GUIContent("Sub View-Model"));

var bindableProperties = FindBindableProperties();

EditorStyles.label.fontStyle = propertyPrefabModified
Expand All @@ -37,8 +39,8 @@ protected override void OnInspector()

ShowViewModelPropertyMenu(
new GUIContent(
"Sub view-model property",
"The property on the top level view model containing the sub view-model"
"Property",
"The Property on the top level View-Model containing the Sub View-Model"
),
bindableProperties,
updatedValue =>
Expand All @@ -52,6 +54,8 @@ protected override void OnInspector()
targetScript.ViewModelPropertyName,
p => true
);

EndArea();
}

private BindableMember<PropertyInfo>[] FindBindableProperties()
Expand Down
10 changes: 7 additions & 3 deletions Editor/TemplateBindingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

BeginArea(new GUIContent("Template"));

EditorStyles.label.fontStyle = viewModelPrefabModified
? FontStyle.Bold
: DefaultFontStyle;

ShowViewModelPropertyMenu(
new GUIContent(
"Template property",
"Property on the view model to use for selecting templates."
"Property",
"Property on the View-Model to use for selecting Templates."
),
TypeResolver.FindBindableProperties(targetScript),
updatedValue => targetScript.ViewModelPropertyName = updatedValue,
targetScript.ViewModelPropertyName,
property => true
);

EditorGUILayout.PropertyField(_templatesProperty, true);
EndArea();

EditorGUILayout.PropertyField(_templatesProperty, new GUIContent("Templates", "Templates for Collection"), true);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions Editor/TemplateEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ protected override void OnInspector()
{
UpdatePrefabModifiedProperties();

BeginArea(new GUIContent("Template"));

var availableViewModels = TypeResolver.TypesWithBindingAttribute
.Select(type => type.ToString())
.OrderBy(name => name)
Expand All @@ -46,8 +48,8 @@ protected override void OnInspector()

var newSelectedIndex = EditorGUILayout.Popup(
new GUIContent(
"Template view model",
"Type of the view model that this template will be bound to when it is instantiated."
"View-Model",
"Type of the View-Model that this Template will be bound to when it is instantiated."
),
selectedIndex,
availableViewModels
Expand All @@ -66,6 +68,8 @@ protected override void OnInspector()
: availableViewModels[newSelectedIndex],
"Set bound view-model for template"
);

EndArea();
}

/// <summary>
Expand Down
Loading