/// <summary>
        /// Draws the dropdown for selecting a method from bindableViewModelMethods
        /// </summary>
        private void ShowMethodMenu(EventBinding targetScript, MethodInfo[] bindableMethods)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("View-model method");

            var dropdownPosition = GUILayoutUtility.GetLastRect();

            dropdownPosition.x += dropdownPosition.width;

            if (GUILayout.Button(new GUIContent(targetScript.viewModelMethodName), EditorStyles.popup))
            {
                InspectorUtils.ShowMenu <MethodInfo>(
                    method => method.ReflectedType + "/" + method.Name,
                    method => true,
                    method => method.ReflectedType.Name + "." + method.Name == targetScript.viewModelMethodName,
                    method => UpdateProperty(
                        updatedValue => targetScript.viewModelMethodName = updatedValue,
                        targetScript.viewModelMethodName,
                        method.ReflectedType.Name + "." + method.Name
                        ),
                    bindableMethods,
                    dropdownPosition
                    );
            }

            EditorGUILayout.EndHorizontal();
        }
예제 #2
0
        /// <summary>
        /// Display a popup menu for selecting a property from a view-model.
        /// </summary>
        protected void ShowViewModelPropertyMenu(
            string label,
            AbstractMemberBinding target,
            PropertyInfo[] bindableProperties,
            Action <string> propertyValueSetter,
            string curPropertyValue,
            Func <PropertyInfo, bool> menuEnabled
            )
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(label);

            var dropdownPosition = GUILayoutUtility.GetLastRect();

            dropdownPosition.x += dropdownPosition.width;

            if (GUILayout.Button(new GUIContent(curPropertyValue), EditorStyles.popup))
            {
                InspectorUtils.ShowMenu <PropertyInfo>(
                    property => property.ReflectedType + "/" + property.Name + " : " + property.PropertyType.Name,
                    menuEnabled,
                    property => property.ReflectedType.Name + "." + property.Name == curPropertyValue,
                    property => UpdateProperty(
                        propertyValueSetter,
                        curPropertyValue,
                        property.ReflectedType.Name + "." + property.Name
                        ),
                    bindableProperties,
                    dropdownPosition
                    );
            }

            EditorGUILayout.EndHorizontal();
        }
        /// <summary>
        /// Sets the specified value and sets dirty to true if it doesn't match the old value.
        /// </summary>
        protected void UpdateProperty <TValue>(Action <TValue> setter, TValue oldValue, TValue newValue)
            where TValue : class
        {
            if (newValue != oldValue)
            {
                setter(newValue);

                InspectorUtils.MarkSceneDirty(((Component)target).gameObject);
            }
        }
예제 #4
0
        /// <summary>
        /// Draws the dropdown menu for picking a property in the view model to bind to.
        /// </summary>
        private void ShowViewModelPropertyDropdown(OneWayPropertyBinding target, PropertyInfo[] bindableProperties, Type viewPropertyType, Rect position)
        {
            var selectedIndex = Array.IndexOf(
                bindableProperties.Select(p => p.ReflectedType.Name + p.Name).ToArray(),
                target.viewModelName + target.viewModelPropertyName
                );

            var options = bindableProperties.Select(p =>
                                                    new InspectorUtils.MenuItem(
                                                        new GUIContent(p.ReflectedType.Name + "/" + p.Name + " : " + p.PropertyType.Name),
                                                        p.PropertyType == viewPropertyType
                                                        )
                                                    ).ToArray();

            InspectorUtils.ShowCustomSelectionMenu(index =>
                                                   SetViewModelProperty(target, bindableProperties[index]), options, selectedIndex, position);
        }