protected override void OnInspector() { UpdatePrefabModifiedProperties(); EditorStyles.label.fontStyle = viewPropertyPrefabModified ? FontStyle.Bold : DefaultFontStyle; var animatorParameters = GetAnimatorParameters(); if (animatorParameters == null || !animatorParameters.Any()) { EditorGUILayout.HelpBox("Animator has no parameters!", MessageType.Warning); return; } ShowAnimatorParametersMenu( new GUIContent("View property", "Property on the view to bind to"), updatedValue => { targetScript.AnimatorParameterName = updatedValue.Name; targetScript.AnimatorParameterType = updatedValue.Type; }, new AnimatorParameterTypeAndName(targetScript.AnimatorParameterName, targetScript.AnimatorParameterType), animatorParameters, out var viewPropertyType ); // Don't let the user set anything else until they've chosen a view property. var guiPreviouslyEnabled = GUI.enabled; if (string.IsNullOrEmpty(targetScript.AnimatorParameterName)) { GUI.enabled = false; } var viewAdapterTypeNames = TypeResolver.GetAdapterIds( adapterInfo => viewPropertyType == null || adapterInfo.OutType == 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."), viewAdapterTypeNames, targetScript.ViewAdapterId, newValue => { // 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"); targetScript.ViewAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ViewAdapterId = updatedValue, targetScript.ViewAdapterId, newValue, "Set view adapter" ); } ); viewAdapterOptionsFade.target = ShouldShowAdapterOptions(targetScript.ViewAdapterId, out var adapterType); EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle; ShowAdapterOptionsMenu( "View adapter options", adapterType, options => targetScript.ViewAdapterOptions = options, targetScript.ViewAdapterOptions, viewAdapterOptionsFade.faded ); EditorGUILayout.Space(); 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."), TypeResolver.FindBindableProperties(targetScript), updatedValue => targetScript.ViewModelPropertyName = updatedValue, targetScript.ViewModelPropertyName, property => property.PropertyType == adaptedViewPropertyType ); GUI.enabled = guiPreviouslyEnabled; EditorGUILayout.Space(); }
protected override void OnInspector() { UpdatePrefabModifiedProperties(); var viewPropertyType = typeof(bool); var viewAdapterTypeNames = TypeResolver.GetAdapterIds(o => o.OutType == 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." ), viewAdapterTypeNames, targetScript.ViewAdapterId, newValue => { // 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"); targetScript.ViewAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ViewAdapterId = updatedValue, targetScript.ViewAdapterId, newValue, "Set View Adapter" ); } ); Type adapterType; viewAdapterOptionsFade.target = ShouldShowAdapterOptions( targetScript.ViewAdapterId, out adapterType ); EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle; ShowAdapterOptionsMenu( "View Adapter Options", adapterType, options => targetScript.ViewAdapterOptions = options, targetScript.ViewAdapterOptions, viewAdapterOptionsFade.faded ); EditorGUILayout.Space(); 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." ), TypeResolver.FindBindableProperties(targetScript), updatedValue => targetScript.ViewModelPropertyName = updatedValue, targetScript.ViewModelPropertyName, property => property.PropertyType == adaptedViewPropertyType ); }
protected override void OnInspector() { UpdatePrefabModifiedProperties(); EditorStyles.label.fontStyle = viewEventPrefabModified ? FontStyle.Bold : DefaultFontStyle; ShowEventMenu( UnityEventWatcher.GetBindableEvents(targetScript.gameObject) .OrderBy(evt => evt.Name) .ToArray(), updatedValue => targetScript.ViewEventName = updatedValue, targetScript.ViewEventName ); EditorStyles.label.fontStyle = viewPropertyPrefabModified ? FontStyle.Bold : DefaultFontStyle; Type viewPropertyType; ShowViewPropertyMenu( new GUIContent("View Property", "Property on the view to bind to."), PropertyFinder.GetBindableProperties(targetScript.gameObject) .OrderBy(prop => prop.ViewModelTypeName) .ThenBy(prop => prop.MemberName) .ToArray(), updatedValue => targetScript.ViewPropertyName = updatedValue, targetScript.ViewPropertyName, out viewPropertyType ); // Don't let the user set other options until they've set the event and view property. var guiPreviouslyEnabled = GUI.enabled; if (string.IsNullOrEmpty(targetScript.ViewEventName) || string.IsNullOrEmpty(targetScript.ViewPropertyName)) { GUI.enabled = false; } var viewAdapterTypeNames = TypeResolver.GetAdapterIds( o => viewPropertyType == null || o.OutType == 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." ), viewAdapterTypeNames, targetScript.ViewAdapterId, newValue => { // 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"); targetScript.ViewAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ViewAdapterId = updatedValue, targetScript.ViewAdapterId, newValue, "Set View Adapter" ); } ); EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle; Type viewAdapterType; viewAdapterOptionsFade.target = ShouldShowAdapterOptions( targetScript.ViewAdapterId, out viewAdapterType ); ShowAdapterOptionsMenu( "View Adapter Options", viewAdapterType, options => targetScript.ViewAdapterOptions = options, targetScript.ViewAdapterOptions, viewAdapterOptionsFade.faded ); EditorGUILayout.Space(); 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." ), TypeResolver.FindBindableProperties(targetScript), updatedValue => targetScript.ViewModelPropertyName = updatedValue, targetScript.ViewModelPropertyName, prop => prop.PropertyType == adaptedViewPropertyType ); var viewModelAdapterTypeNames = TypeResolver.GetAdapterIds( o => adaptedViewPropertyType == null || o.OutType == adaptedViewPropertyType); EditorStyles.label.fontStyle = viewModelAdapterPrefabModified ? FontStyle.Bold : DefaultFontStyle; ShowAdapterMenu( new GUIContent( "View-Model Adapter", "Adapter that converts from the view back to the view-model." ), viewModelAdapterTypeNames, targetScript.ViewModelAdapterId, newValue => { if (newValue != targetScript.ViewModelAdapterId) { Undo.RecordObject(targetScript, "Set View-Model Adapter Options"); targetScript.ViewModelAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ViewModelAdapterId = updatedValue, targetScript.ViewModelAdapterId, newValue, "Set View-Model Adapter" ); } ); EditorStyles.label.fontStyle = viewModelAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle; Type viewModelAdapterType; viewModelAdapterOptionsFade.target = ShouldShowAdapterOptions( targetScript.ViewModelAdapterId, out viewModelAdapterType ); ShowAdapterOptionsMenu( "View-Model Adapter Options", viewModelAdapterType, options => targetScript.ViewModelAdapterOptions = options, targetScript.ViewModelAdapterOptions, viewModelAdapterOptionsFade.faded ); EditorGUILayout.Space(); var expectionAdapterTypeNames = TypeResolver.GetAdapterIds( o => o.InType == typeof(Exception)); EditorStyles.label.fontStyle = exceptionPropertyPrefabModified ? FontStyle.Bold : DefaultFontStyle; var adaptedExceptionPropertyType = AdaptTypeForward( typeof(Exception), targetScript.ExceptionAdapterTypeName ); ShowViewModelPropertyMenuWithNone( new GUIContent( "Exception Property", "Property on the view-model to bind the exception to." ), TypeResolver.FindBindableProperties(targetScript), updatedValue => targetScript.ExceptionPropertyName = updatedValue, targetScript.ExceptionPropertyName, prop => prop.PropertyType == adaptedExceptionPropertyType ); EditorStyles.label.fontStyle = exceptionAdapterPrefabModified ? FontStyle.Bold : DefaultFontStyle; ShowAdapterMenu( new GUIContent( "Exception Adapter", "Adapter that handles exceptions thrown by the view-model adapter." ), expectionAdapterTypeNames, targetScript.ExceptionAdapterTypeName, newValue => { if (newValue != targetScript.ExceptionAdapterTypeName) { Undo.RecordObject(targetScript, "Set Exception Adapter Options"); targetScript.ExceptionAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ExceptionAdapterTypeName = updatedValue, targetScript.ExceptionAdapterTypeName, newValue, "Set Exception Adapter" ); } ); EditorStyles.label.fontStyle = exceptionAdapterOptionsPrefabModified ? FontStyle.Bold : DefaultFontStyle; Type exceptionAdapterType; exceptionAdapterOptionsFade.target = ShouldShowAdapterOptions( targetScript.ExceptionAdapterTypeName, out exceptionAdapterType ); ShowAdapterOptionsMenu( "Exception Adapter Options", exceptionAdapterType, options => targetScript.ExceptionAdapterOptions = options, targetScript.ExceptionAdapterOptions, exceptionAdapterOptionsFade.faded ); GUI.enabled = guiPreviouslyEnabled; }
protected override void OnInspector() { UpdatePrefabModifiedProperties(); var defaultLabelStyle = EditorStyles.label.fontStyle; EditorStyles.label.fontStyle = viewPropertyPrefabModified ? FontStyle.Bold : defaultLabelStyle; Type viewPropertyType; ShowViewPropertyMenu( new GUIContent("View Property", "Property on the view to bind to."), PropertyFinder.GetBindableProperties(targetScript.gameObject) .OrderBy(prop => prop.ViewModelTypeName) .ThenBy(prop => prop.MemberName) .ToArray(), updatedValue => targetScript.ViewPropertyName = updatedValue, targetScript.ViewPropertyName, out viewPropertyType ); // Don't let the user set anything else until they've chosen a view property. var guiPreviouslyEnabled = GUI.enabled; if (string.IsNullOrEmpty(targetScript.ViewPropertyName)) { GUI.enabled = false; } var viewAdapterTypeNames = TypeResolver.GetAdapterIds( o => viewPropertyType == null || o.OutType == viewPropertyType); EditorStyles.label.fontStyle = viewAdapterPrefabModified ? FontStyle.Bold : defaultLabelStyle; ShowAdapterMenu( new GUIContent( "View Adapter", "Adapter that converts values sent from the view-model to the view." ), viewAdapterTypeNames, targetScript.ViewAdapterId, newValue => { // 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"); targetScript.ViewAdapterOptions = null; } UpdateProperty( updatedValue => targetScript.ViewAdapterId = updatedValue, targetScript.ViewAdapterId, newValue, "Set View Adapter" ); } ); Type adapterType; viewAdapterOptionsFade.target = ShouldShowAdapterOptions( targetScript.ViewAdapterId, out adapterType ); EditorStyles.label.fontStyle = viewAdapterOptionsPrefabModified ? FontStyle.Bold : defaultLabelStyle; ShowAdapterOptionsMenu( "View Adapter Options", adapterType, options => targetScript.ViewAdapterOptions = options, targetScript.ViewAdapterOptions, viewAdapterOptionsFade.faded ); EditorGUILayout.Space(); EditorStyles.label.fontStyle = viewModelPropertyPrefabModified ? FontStyle.Bold : defaultLabelStyle; var adaptedViewPropertyType = AdaptTypeBackward( viewPropertyType, targetScript.ViewAdapterId ); ShowViewModelPropertyMenu( new GUIContent( "View-Model 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; EditorStyles.label.fontStyle = defaultLabelStyle; }