Exemple #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 Bound View-Model Property"
             );
     },
         bindableProperties
         .OrderBy(property => property.ViewModelTypeName)
         .ThenBy(property => property.MemberName)
         .ToArray()
         );
 }
Exemple #2
0
        /// <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, string undoActionName)
            where TValue : class
        {
            if (newValue == oldValue)
            {
                return;
            }

            Undo.RecordObject(target, undoActionName);

            setter(newValue);

            InspectorUtils.MarkSceneDirty(((Component)target).gameObject);
        }
Exemple #3
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 Bound View-Model Property"
                    ),
                new[] { noneOption }
                .Concat(options)
                .ToArray()
                );
        }
Exemple #4
0
 /// <summary>
 /// Draws the dropdown for selecting a method from bindableViewModelMethods
 /// </summary>
 private void ShowMethodMenu(
     EventBinding targetScript,
     BindableMember <MethodInfo>[] bindableMethods
     )
 {
     InspectorUtils.DoPopup(
         new GUIContent(targetScript.ViewModelMethodName),
         new GUIContent("View-Model Method", "Method on the view-model to bind to."),
         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()
         );
 }