/// <summary> /// Gets inspector data such as name and description for the /// specified type. /// </summary> /// <param name="type">Type to get inspector data for.</param> /// <param name="conditionalInspectors">Dictionary to be filled with conditions for inspectors to be shown.</param> /// <returns>Inspector data for the specified type.</returns> public static InspectorType GetInspectorType( Type type, ref Dictionary <InspectorPropertyAttribute, InspectorConditionalPropertyAttribute> conditionalInspectors) { List <InspectorPropertyAttribute> inspectorProperties = InspectorUtils.CollectInspectorProperties( type, ref conditionalInspectors); var inspectorTypeAttribute = type.GetAttribute <InspectorTypeAttribute>(); if (inspectorTypeAttribute == null) { return(null); } var inspectorTypeData = new InspectorType { Attribute = inspectorTypeAttribute, Name = type.Name, Description = inspectorTypeAttribute.Description, Properties = inspectorProperties, Type = type, }; return(inspectorTypeData); }
private void TestAddingDefaultItemToEmptyList(InspectorType inspectorType, string propertyName) { InspectorPropertyAttribute testAttribute = inspectorType.Properties.First(property => property.Name == propertyName); // Create list. var list = testAttribute.GetEmptyList(); list.Add(testAttribute.DefaultListItem); }
private void DrawInspector(InspectorType inspectorType, IAttributeTable configuration, InspectorTypeTable inspectorTypeTable, IBlueprintManager blueprintManager) { foreach (var inspectorProperty in inspectorType.Properties) { // Get current value. object currentValue = configuration.GetValueOrDefault(inspectorProperty.Name, inspectorProperty.Default); object newValue = EditorGUIUtils.LogicInspectorPropertyField(inspectorProperty, currentValue, inspectorTypeTable, blueprintManager); // Set new value if changed. if (!Equals(newValue, currentValue)) { configuration.SetValue(inspectorProperty.Name, newValue); } } }
/// <summary> /// Gets inspector data such as name and description for the /// specified type. /// </summary> /// <param name="type">Type to get inspector data for.</param> /// <param name="conditionalInspectors">Dictionary to be filled with conditions for inspectors to be shown.</param> /// <returns>Inspector data for the specified type.</returns> public static InspectorType GetInspectorType( Type type, ref Dictionary<InspectorPropertyAttribute, InspectorConditionalPropertyAttribute> conditionalInspectors) { List<InspectorPropertyAttribute> inspectorProperties = InspectorUtils.CollectInspectorProperties( type, ref conditionalInspectors); var inspectorTypeAttribute = type.GetAttribute<InspectorTypeAttribute>(); if (inspectorTypeAttribute == null) { return null; } var inspectorTypeData = new InspectorType { Attribute = inspectorTypeAttribute, Name = type.Name, Description = inspectorTypeAttribute.Description, Properties = inspectorProperties, Type = type, }; return inspectorTypeData; }
public void SetUp() { this.inspectorType = InspectorType.GetInspectorType(typeof(TestInspectorType)); this.testGame = new Game(); }
public void AddInspectorControls( InspectorType typeInfo, Panel panel, GetPropertyValueDelegate getPropertyValue, InspectorControlValueChangedDelegate onValueChanged, bool addNameLabel = true) { if (addNameLabel) { // Add label for component name. var componentName = typeInfo.Type.Name; componentName = componentName.Replace("Component", string.Empty); componentName = componentName.SplitByCapitalLetters(); Label componentLabel = new Label { Content = componentName, ToolTip = typeInfo.Description, FontWeight = FontWeights.Bold }; panel.Children.Add(componentLabel); } // Add inspectors for component properties. foreach (var inspectorProperty in typeInfo.Properties) { // Get current value. bool inherited = true; var propertyValue = getPropertyValue != null ? getPropertyValue(inspectorProperty, out inherited) : inspectorProperty.Default; // Create control for inspector property. IInspectorControl propertyControl = this.CreateInspectorControlFor( inspectorProperty, propertyValue, inherited); if (propertyControl == null) { continue; } if (onValueChanged != null) { // Subscribe for change of value. propertyControl.ValueChanged += onValueChanged; } // Create wrapper. InspectorWithLabel inspectorWrapper = new InspectorWithLabel { DataContext = ((FrameworkElement)propertyControl).DataContext, Control = propertyControl }; // Add to panel. panel.Children.Add(inspectorWrapper); } }
public void SetUp() { this.parentInspectorType = InspectorType.GetInspectorType(typeof(TestDataParent)); this.dataInspectorType = InspectorType.GetInspectorType(typeof(TestData)); this.testGame = new Game(); }