Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            // Initialise reference to target script
            var targetScript = (OneWayPropertyBinding)target;

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(property => property.ReflectedType.Name)
                .ThenBy(property => property.Name)
                .ToArray(),
                updatedValue => targetScript.uiPropertyName = updatedValue,
                targetScript.uiPropertyName,
                out viewPropertyType
                );

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            ShowAdapterMenu(
                new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
                viewAdapterTypeNames,
                targetScript.viewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.viewAdapterTypeName)
                {
                    targetScript.viewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.viewAdapterTypeName = updatedValue,
                    targetScript.viewAdapterTypeName,
                    newValue
                    );
            }
                );

            ShowAdapterOptionsMenu(
                "View adapter options",
                targetScript.viewAdapterTypeName,
                options => targetScript.viewAdapterOptions = options,
                targetScript.viewAdapterOptions
                );

            var adaptedViewPropertyType = AdaptTypeBackward(viewPropertyType, targetScript.viewAdapterTypeName);

            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
                );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find the adapter attribute for a named adapter type.
        /// </summary>
        protected static AdapterAttribute FindAdapterAttribute(string adapterName)
        {
            if (!string.IsNullOrEmpty(adapterName))
            {
                var adapterType = TypeResolver.FindAdapterType(adapterName);
                if (adapterType != null)
                {
                    return(TypeResolver.FindAdapterAttribute(adapterType));
                }
            }

            return(null);
        }
        public override void OnInspectorGUI()
        {
            var defaultLabelStyle = EditorStyles.label.fontStyle;

            Type viewPropertyType = typeof(bool);

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            EditorStyles.label.fontStyle = DoesFieldOverridePrefab() ? FontStyle.Bold : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
                viewAdapterTypeNames,
                targetScript.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            EditorStyles.label.fontStyle = DoesFieldOverridePrefab() ? FontStyle.Bold : defaultLabelStyle;

            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 == typeof(bool)
                );

            EditorStyles.label.fontStyle = defaultLabelStyle;
        }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            if (CannotModifyInPlayMode())
            {
                GUI.enabled = false;
            }

            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

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

            ShowEventMenu(
                UnityEventWatcher.GetBindableEvents(targetScript.gameObject)
                .OrderBy(evt => evt.Name)
                .ToArray(),
                updatedValue => targetScript.ViewEventName = updatedValue,
                targetScript.ViewEventName
                );

            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.ViewPropertName = updatedValue,
                targetScript.ViewPropertName,
                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.ViewPropertName))
            {
                GUI.enabled = false;
            }

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.IsTypeCastableTo(TypeResolver.FindAdapterAttribute(type).OutputType, 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.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

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

            Type viewAdapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                out viewAdapterType
                );
            ShowAdapterOptionsMenu(
                "View adapter options",
                viewAdapterType,
                options => targetScript.ViewAdapterOptions = options,
                targetScript.ViewAdapterOptions,
                viewAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

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

            var adaptedViewPropertyType = AdaptTypeBackward(
                viewPropertyType,
                targetScript.ViewAdapterTypeName
                );

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

            var viewModelAdapterTypeNames = GetAdapterTypeNames(
                type => adaptedViewPropertyType == null ||
                TypeResolver.IsTypeCastableTo(adaptedViewPropertyType, TypeResolver.FindAdapterAttribute(type).OutputType)
                );

            EditorStyles.label.fontStyle = viewModelAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            ShowAdapterMenu(
                new GUIContent(
                    "View-model adapter",
                    "Adapter that converts from the view back to the view-model"
                    ),
                viewModelAdapterTypeNames,
                targetScript.ViewModelAdapterTypeName,
                newValue =>
            {
                if (newValue != targetScript.ViewModelAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view-model adapter options");
                    targetScript.ViewModelAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewModelAdapterTypeName = updatedValue,
                    targetScript.ViewModelAdapterTypeName,
                    newValue,
                    "Set view-model adapter"
                    );
            }
                );

            EditorStyles.label.fontStyle = viewModelAdapterOptionsPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            Type viewModelAdapterType;

            viewModelAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewModelAdapterTypeName,
                out viewModelAdapterType
                );
            ShowAdapterOptionsMenu(
                "View-model adapter options",
                viewModelAdapterType,
                options => targetScript.ViewModelAdapterOptions = options,
                targetScript.ViewModelAdapterOptions,
                viewModelAdapterOptionsFade.faded
                );

            EditorGUILayout.Space();

            var expectionAdapterTypeNames = GetAdapterTypeNames(
                type => TypeResolver.IsTypeCastableTo(TypeResolver.FindAdapterAttribute(type).InputType, typeof(Exception))
                );

            EditorStyles.label.fontStyle = exceptionPropertyPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            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 => TypeResolver.IsTypeCastableTo(prop.PropertyType, adaptedExceptionPropertyType)
                );

            EditorStyles.label.fontStyle = exceptionAdapterPrefabModified
                ? FontStyle.Bold
                : defaultLabelStyle;

            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
                : defaultLabelStyle;

            Type exceptionAdapterType;

            exceptionAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ExceptionAdapterTypeName,
                out exceptionAdapterType
                );
            ShowAdapterOptionsMenu(
                "Exception adapter options",
                exceptionAdapterType,
                options => targetScript.ExceptionAdapterOptions = options,
                targetScript.ExceptionAdapterOptions,
                exceptionAdapterOptionsFade.faded
                );

            EditorStyles.label.fontStyle = defaultLabelStyle;

            GUI.enabled = guiPreviouslyEnabled;
        }
        public override void OnInspectorGUI()
        {
            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 = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == 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.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                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.ViewAdapterTypeName
                );

            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;
        }
Ejemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            if (CannotModifyInPlayMode())
            {
                GUI.enabled = false;
            }

            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 = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

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

            /*
             * for (int i = 0; i < viewAdapterTypeNames.Length; i++)
             * {
             *  var name = viewAdapterTypeNames[i].Split('.').LastOrDefault()?.Replace("Adapter", "");
             *  viewAdapterTypeNames[i] = name == default(string) ? viewAdapterTypeNames[i] : name;
             * }
             */

            ShowAdapterMenu(
                new GUIContent(
                    "View adapter",
                    "Adapter that converts values sent from the view-model to the view."
                    ),
                viewAdapterTypeNames,
                targetScript.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                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.ViewAdapterTypeName
                );

            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 || adaptedViewPropertyType == typeof(object)
                );

            // About adaptedViewPropertyType == typeof(object) :
            // If the view adapter can take typeof(object) then allow user to select it
            // If the view adapter isn't typeof(object), user wil not be able to select this property.
            // This is awesome to show as string any object with Unity

            GUI.enabled = guiPreviouslyEnabled;

            EditorStyles.label.fontStyle = defaultLabelStyle;
        }
        public override void OnInspectorGUI()
        {
            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

            Type viewPropertyType = typeof(bool);

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == 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.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(
                targetScript.ViewAdapterTypeName,
                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.ViewAdapterTypeName
                );

            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
                );

            EditorStyles.label.fontStyle = defaultLabelStyle;
        }
        public override void OnInspectorGUI()
        {
            if (CannotModifyInPlayMode())
            {
                return;
            }

            UpdatePrefabModifiedProperties();

            var defaultLabelStyle = EditorStyles.label.fontStyle;

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

            var animatorParameters = GetAnimatorParameters();

            if (animatorParameters == null || !animatorParameters.Any())
            {
                EditorGUILayout.HelpBox("Animator has no parameters!", MessageType.Warning);
                return;
            }

            Type viewPropertyType;

            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 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 = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == 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.ViewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.ViewAdapterTypeName)
                {
                    Undo.RecordObject(targetScript, "Set view adapter options");
                    targetScript.ViewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.ViewAdapterTypeName = updatedValue,
                    targetScript.ViewAdapterTypeName,
                    newValue,
                    "Set view adapter"
                    );
            }
                );

            Type adapterType;

            viewAdapterOptionsFade.target = ShouldShowAdapterOptions(targetScript.ViewAdapterTypeName, 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.ViewAdapterTypeName);

            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;

            EditorGUILayout.Space();
        }
Ejemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            var targetScript = (TwoWayPropertyBinding)target;

            ShowEventMenu(
                UnityEventWatcher.GetBindableEvents(targetScript.gameObject)
                .OrderBy(evt => evt.Name)
                .ToArray(),
                updatedValue => targetScript.uiEventName = updatedValue,
                targetScript.uiEventName
                );

            Type viewPropertyType;

            ShowViewPropertyMenu(
                new GUIContent("View property", "Property on the view to bind to"),
                PropertyFinder.GetBindableProperties(targetScript.gameObject)
                .OrderBy(property => property.ReflectedType.Name)
                .ThenBy(property => property.Name)
                .ToArray(),
                updatedValue => targetScript.uiPropertyName = updatedValue,
                targetScript.uiPropertyName,
                out viewPropertyType
                );

            var viewAdapterTypeNames = GetAdapterTypeNames(
                type => viewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == viewPropertyType
                );

            ShowAdapterMenu(
                new GUIContent("View adapter", "Adapter that converts values sent from the view-model to the view."),
                viewAdapterTypeNames,
                targetScript.viewAdapterTypeName,
                newValue =>
            {
                // Get rid of old adapter options if we changed the type of the adapter.
                if (newValue != targetScript.viewAdapterTypeName)
                {
                    targetScript.viewAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.viewAdapterTypeName = updatedValue,
                    targetScript.viewAdapterTypeName,
                    newValue
                    );
            }
                );

            ShowAdapterOptionsMenu(
                "View adapter options",
                targetScript.viewAdapterTypeName,
                options => targetScript.viewAdapterOptions = options,
                targetScript.viewAdapterOptions
                );

            var adaptedViewPropertyType = AdaptTypeBackward(viewPropertyType, targetScript.viewAdapterTypeName);

            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
                );

            var viewModelAdapterTypeNames = GetAdapterTypeNames(
                type => adaptedViewPropertyType == null ||
                TypeResolver.FindAdapterAttribute(type).OutputType == adaptedViewPropertyType
                );

            ShowAdapterMenu(
                new GUIContent("View-model adapter", "Adapter that converts from the view back to the view-model"),
                viewModelAdapterTypeNames,
                targetScript.viewModelAdapterTypeName,
                newValue =>
            {
                if (newValue != targetScript.viewModelAdapterTypeName)
                {
                    targetScript.viewModelAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.viewModelAdapterTypeName = updatedValue,
                    targetScript.viewModelAdapterTypeName,
                    newValue
                    );
            }
                );

            ShowAdapterOptionsMenu(
                "View-model adapter options",
                targetScript.viewModelAdapterTypeName,
                options => targetScript.viewModelAdapterOptions = options,
                targetScript.viewModelAdapterOptions
                );

            var expectionAdapterTypeNames = GetAdapterTypeNames(
                type => TypeResolver.FindAdapterAttribute(type).InputType == typeof(Exception)
                );

            ShowAdapterMenu(
                new GUIContent("Exception adapter", "Adapter that handles exceptions thrown by the view-model adapter"),
                expectionAdapterTypeNames,
                targetScript.exceptionAdapterTypeName,
                newValue =>
            {
                if (newValue != targetScript.exceptionAdapterTypeName)
                {
                    targetScript.exceptionAdapterOptions = null;
                }

                UpdateProperty(
                    updatedValue => targetScript.exceptionAdapterTypeName = updatedValue,
                    targetScript.exceptionAdapterTypeName,
                    newValue
                    );
            }
                );

            ShowAdapterOptionsMenu(
                "Exception adapter options",
                targetScript.exceptionAdapterTypeName,
                options => targetScript.exceptionAdapterOptions = options,
                targetScript.exceptionAdapterOptions
                );

            var adaptedExceptionPropertyType = AdaptTypeForward(typeof(Exception), targetScript.exceptionAdapterTypeName);

            ShowViewModelPropertyMenu(
                new GUIContent("Exception property", "Property on the view-model to bind the exception to."),
                TypeResolver.FindBindableProperties(targetScript),
                updatedValue => targetScript.exceptionPropertyName = updatedValue,
                targetScript.exceptionPropertyName,
                property => property.PropertyType == adaptedExceptionPropertyType
                );
        }