public override void OnGUI( Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.Integer) { var attr = attribute as SwfPowerOfTwoIfAttribute; var bool_prop = FindNextBoolProperty(property, attr.BoolProp); var need_pow2 = (bool_prop != null && (bool_prop.boolValue || bool_prop.hasMultipleDifferentValues)); ValidateProperty(property, need_pow2, attr.MinPow2, attr.MaxPow2); SwfEditorUtils.DoWithMixedValue( property.hasMultipleDifferentValues, () => { if (need_pow2) { var values = GenPowerOfTwoValues(attr.MinPow2, attr.MaxPow2); var vnames = values.Select(p => new GUIContent(p.ToString())).ToArray(); EditorGUI.IntPopup(position, property, vnames, values, label); } else { EditorGUI.PropertyField(position, property, label, true); } }); } else { EditorGUI.LabelField(position, label.text, "Use SwfPowerOfTwoIf with integer attribute."); } }
public override void OnGUI( Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.String) { ValidateProperty(property); SwfEditorUtils.DoWithMixedValue( property.hasMultipleDifferentValues, () => { label = EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginChangeCheck(); var all_sorting_layers = GetAllSortingLayers(true); var sorting_layer_index = EditorGUI.Popup( position, label, property.hasMultipleDifferentValues ? all_sorting_layers.FindIndex(p => string.IsNullOrEmpty(p)) : all_sorting_layers.FindIndex(p => p == property.stringValue), all_sorting_layers.Select(p => new GUIContent(p)).ToArray()); if (EditorGUI.EndChangeCheck()) { if (sorting_layer_index >= 0 && sorting_layer_index < all_sorting_layers.Count) { var new_value = all_sorting_layers[sorting_layer_index]; if (!string.IsNullOrEmpty(new_value)) { if (property.hasMultipleDifferentValues) { property.stringValue = string.Empty; } property.stringValue = new_value; property.serializedObject.ApplyModifiedProperties(); } } } EditorGUI.EndProperty(); }); } else { EditorGUI.LabelField(position, label.text, "Use SwfSortingLayer with string attribute."); } }