Пример #1
0
 /// <summary>
 /// Display a popup menu for selecting a property from a view-model.
 /// </summary>
 protected void ShowViewModelPropertyMenu(
     GUIContent label,
     BindableMember <PropertyInfo>[] bindableProperties,
     Action <string> propertyValueSetter,
     string curPropertyValue,
     Func <PropertyInfo, bool> menuEnabled
     )
 {
     InspectorUtils.DoPopup(
         new GUIContent(curPropertyValue),
         label,
         prop => string.Concat(prop.ViewModelType, "/", prop.MemberName, " : ", prop.Member.PropertyType.Name),
         prop => menuEnabled(prop.Member),
         prop => prop.ToString() == curPropertyValue,
         prop =>
     {
         UpdateProperty(
             propertyValueSetter,
             curPropertyValue,
             prop.ToString(),
             "Set view-model property"
             );
     },
         bindableProperties
         .OrderBy(property => property.ViewModelTypeName)
         .ThenBy(property => property.MemberName)
         .ToArray()
         );
 }
Пример #2
0
        /// <summary>
        /// Draws the dropdown for selecting a method from bindableViewModelMethods
        /// </summary>
        private void ShowMethodMenu(
            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),
                m => m.ViewModelType + "/" + m.MemberName,
                m => true,
                m => m.ToString() == targetScript.ViewModelMethodName,
                m => UpdateProperty(
                    updatedValue => targetScript.ViewModelMethodName = updatedValue,
                    targetScript.ViewModelMethodName,
                    m.ToString(),
                    "Set bound view-model method"
                    ),
                bindableMethods
                .OrderBy(m => m.ViewModelTypeName)
                .ThenBy(m => m.MemberName)
                .ToArray()
                );
        }
 /// <summary>
 /// Display a popup menu for selecting a property from a view-model.
 /// </summary>
 protected void ShowViewModelPropertyMenu(
     GUIContent label,
     PropertyInfo[] bindableProperties,
     Action <string> propertyValueSetter,
     string curPropertyValue,
     Func <PropertyInfo, bool> menuEnabled
     )
 {
     InspectorUtils.DoPopup(
         new GUIContent(curPropertyValue),
         label,
         property => string.Concat(property.ReflectedType, "/", property.Name, " : ", property.PropertyType.Name),
         menuEnabled,
         property => MemberInfoToString(property) == curPropertyValue,
         property => UpdateProperty(
             propertyValueSetter,
             curPropertyValue,
             MemberInfoToString(property),
             "Set view-model property"
             ),
         bindableProperties
         .OrderBy(property => property.ReflectedType.Name)
         .ThenBy(property => property.Name)
         .ToArray()
         );
 }
Пример #4
0
        /// <summary>
        /// Draws the dropdown for selecting a method from bindableViewModelMethods
        /// </summary>
        private void ShowMethodMenu(EventBinding targetScript, MethodInfo[] bindableMethods)
        {
            var tooltip = "Method on the view-model to bind to.";

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(new GUIContent("View-model method", tooltip));

            var dropdownPosition = GUILayoutUtility.GetLastRect();

            dropdownPosition.x += dropdownPosition.width;

            if (GUILayout.Button(new GUIContent(targetScript.viewModelMethodName, tooltip), EditorStyles.popup))
            {
                InspectorUtils.ShowMenu(
                    method => method.ReflectedType + "/" + method.Name,
                    method => true,
                    method => MemberInfoToString(method) == targetScript.viewModelMethodName,
                    method => UpdateProperty(
                        updatedValue => targetScript.viewModelMethodName = updatedValue,
                        targetScript.viewModelMethodName,
                        MemberInfoToString(method)
                        ),
                    bindableMethods
                    .OrderBy(method => method.ReflectedType.Name)
                    .ThenBy(method => method.Name)
                    .ToArray(),
                    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)
            {
                return;
            }

            setter(newValue);

            InspectorUtils.MarkSceneDirty(((Component)target).gameObject);
        }
Пример #6
0
        /// <summary>
        /// Display a popup menu for selecting a property from a view-model.
        /// </summary>
        protected void ShowViewModelPropertyMenuWithNone(
            GUIContent label,
            BindableMember <PropertyInfo>[] bindableProperties,
            Action <string> propertyValueSetter,
            string curPropertyValue,
            Func <PropertyInfo, bool> menuEnabled
            )
        {
            var options = bindableProperties
                          .Select(prop => new OptionInfo(
                                      string.Concat(prop.ViewModelType, "/", prop.MemberName, " : ", prop.Member.PropertyType.Name),
                                      prop
                                      ))
                          .OrderBy(option => option.Property.ViewModelTypeName)
                          .ThenBy(option => option.Property.MemberName);

            var noneOption = new OptionInfo(NoneOptionString, null);

            InspectorUtils.DoPopup(
                new GUIContent(string.IsNullOrEmpty(curPropertyValue) ? NoneOptionString : curPropertyValue),
                label,
                option => option.MenuName,
                option => option.MenuName == NoneOptionString ? true : menuEnabled(option.Property.Member),
                option =>
            {
                if (option == noneOption)
                {
                    return(string.IsNullOrEmpty(curPropertyValue));
                }

                return(option.Property.ToString() == curPropertyValue);
            },
                option => UpdateProperty(
                    propertyValueSetter,
                    curPropertyValue,
                    option.Property == null ? string.Empty : option.Property.ToString(),
                    "Set view-model property"
                    ),
                new[] { noneOption }
                .Concat(options)
                .ToArray()
                );
        }
        /// <summary>
        /// Display a popup menu for selecting a property from a view-model.
        /// </summary>
        protected void ShowViewModelPropertyMenu(
            GUIContent label,
            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, label.tooltip), EditorStyles.popup))
            {
                InspectorUtils.ShowMenu(
                    property => string.Concat(property.ReflectedType, "/", property.Name, " : ", property.PropertyType.Name),
                    menuEnabled,
                    property => MemberInfoToString(property) == curPropertyValue,
                    property => UpdateProperty(
                        propertyValueSetter,
                        curPropertyValue,
                        MemberInfoToString(property)
                        ),
                    bindableProperties
                    .OrderBy(property => property.ReflectedType.Name)
                    .ThenBy(property => property.Name)
                    .ToArray(),
                    dropdownPosition
                    );
            }

            EditorGUILayout.EndHorizontal();
        }