protected virtual void BeginDrawMember(MightySerializedField serializedField, T attribute, MightyDrawer.PropertyDrawCallback propertyDrawCallback = null, BasePropertyDrawerAttribute drawerAttribute = null) { var property = serializedField.Property; if (!property.IsCollection()) { BeginDraw(serializedField, attribute); propertyDrawCallback?.Invoke(serializedField, property, drawerAttribute); return; } BeginDrawArray(serializedField, attribute); BeginDrawHeader(serializedField, attribute); if (!MightyGUIUtilities.DrawFoldout(property)) { EndDrawHeader(serializedField, attribute); EndDrawArray(serializedField, attribute); return; } EditorGUI.indentLevel++; MightyGUIUtilities.DrawArraySizeField(property); EndDrawHeader(serializedField, attribute); }
protected override InitState InitPropertyImpl(MightySerializedField serializedField, Ta attribute) { var property = serializedField.Property; if (!property.IsCollection()) { return(new InitState(false, $"\"{property.displayName}\" should be an array")); } if (!serializedField.PropertyType.IsSubclassOf(typeof(To))) { return(new InitState(false, $"\"{property.displayName}\" array type should inherit from {typeof(To).FullName}")); } var objects = GetFoundArray(serializedField, attribute); if (property.CompareArrays(objects)) { return(new InitState(true)); } property.ClearArray(); for (var i = 0; i < objects.Length; i++) { property.InsertArrayElementAtIndex(i); property.GetArrayElementAtIndex(i).objectReferenceValue = objects[i]; } return(new InitState(true)); }
public void BeginDrawHeader(MightySerializedField serializedField, BaseArrayDecoratorAttribute baseAttribute) { if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.BeforeHeader)) { DrawDecorator(serializedField, (T)baseAttribute); } }
protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, GetComponentButtonAttribute attribute) { if (property.propertyType != SerializedPropertyType.ObjectReference || !mightyMember.PropertyType.IsSubclassOf(typeof(Component))) { MightyGUIUtilities.DrawHelpBox($"{nameof(GetComponentButtonAttribute)} can be used only on Components fields"); return; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(property, !attribute.Options.Contains(FieldOption.HideLabel) ? EditorGUIUtility.TrTextContent(property.displayName) : GUIContent.none); if (GUILayout.Button("Get Component", GUILayout.Width(100))) { var component = property.GetGameObject().GetComponent(mightyMember.PropertyType); if (component != null) { property.objectReferenceValue = component; } } EditorGUILayout.EndHorizontal(); }
public void EndDrawElement(MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute) { if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.AfterElements)) { DrawDecoratorElement(serializedField, index, (T)baseAttribute); } }
protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, T attribute) { if (property.propertyType != SerializedPropertyType.String) { MightyGUIUtilities.DrawPropertyField(property); MightyGUIUtilities.DrawHelpBox($"{attribute.GetType()} can be used only on string fields"); return; } if (!m_pathCache.Contains(mightyMember)) { EnableDrawer(mightyMember, attribute); } var defaultPath = m_pathCache[mightyMember].Value; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(property); if (MightyGUIUtilities.DrawButton("...", GUILayout.Width(35))) { var value = property.stringValue; value = DisplayPanel(property.displayName, !string.IsNullOrWhiteSpace(value) ? FileUtilities.GetDirectoryPath(value) ?? value : defaultPath, mightyMember, attribute); if (!string.IsNullOrWhiteSpace(value)) { property.stringValue = value; } } EditorGUILayout.EndHorizontal(); }
protected override void ValidateProperty(MightySerializedField serializedField, MaxValueAttribute attribute) { var property = serializedField.Property; switch (property.propertyType) { case SerializedPropertyType.Integer: if (property.intValue > attribute.MaxValue) { property.intValue = (int)attribute.MaxValue; } break; case SerializedPropertyType.Float: if (property.floatValue > attribute.MaxValue) { property.floatValue = attribute.MaxValue; } break; default: MightyGUIUtilities.DrawHelpBox($"{nameof(MaxValueAttribute)} can be used only on int or float fields"); break; } }
public virtual void EndDrawMember(MightySerializedField serializedField, T attribute, MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null) { var property = serializedField.Property; if (!property.IsCollection()) { EndDraw(serializedField, attribute); return; } if (!property.isExpanded) { return; } MightyGUIUtilities.DrawArrayBody(property, index => { BeginDrawElement(serializedField, index, attribute); propertyDrawCallback?.Invoke(serializedField, property.GetArrayElementAtIndex(index), drawerAttribute); EndDrawElement(serializedField, index, attribute); }); EditorGUI.indentLevel--; EndDrawArray(serializedField, attribute); }
public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) { var propertyType = serializedField.GetElement(index).propertyType; return(propertyType != SerializedPropertyType.Integer && propertyType != SerializedPropertyType.Float ? MightyGUIUtilities.WARNING_HEIGHT : MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING); }
public override void EndDrawMember(MightySerializedField serializedField, T attribute, MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null) { if (!serializedField.Property.IsCollection()) { EndLayout(serializedField, attribute); } }
protected override void DrawProperty(MightySerializedField serializedField, SerializedProperty property, CustomDrawerAttribute attribute) { GetDrawerForMember(serializedField, m_propertyCallback, out var drawerMethod, attribute); InvokeDrawer(drawerMethod, $"void {attribute.DrawerCallback}(MightySerializedField serializedField)", serializedField); }
public Rect EndDrawElement(Rect rect, MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute) { if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.AfterElements)) { rect = DrawDecoratorElement(rect, serializedField, index, (T)baseAttribute); } return(rect); }
public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) { var element = serializedField.GetElement(index); return(element.propertyType != SerializedPropertyType.String ? MightyGUIUtilities.WARNING_HEIGHT : MightyGUIUtilities.TextHeight(element.stringValue, 3) + MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING * 2); }
public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) { var element = serializedField.GetElement(index); return(element.propertyType != SerializedPropertyType.ObjectReference ? MightyGUIUtilities.WARNING_HEIGHT : !AssetPreview.GetAssetPreview(element.objectReferenceValue) ? MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING : 64); }
protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, Rotation2DAttribute attribute) { if (property.IsCollection()) { MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute)); return; } DrawRotation2D(property, attribute); }
public void DrawElement(GUIContent label, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) { var attribute = (CustomDrawerAttribute)baseAttribute; GetDrawerForMember(serializedField, m_labeledElementCallback, out var drawerMethod, attribute); InvokeDrawer(drawerMethod, $"void {attribute.DrawerCallback}(GUIContent label, MightySerializedField serializedField, int index)", label, serializedField, index); }
public static void CacheArrayDrawerForField(this MightySerializedField serializedField, FieldInfo fieldInfo, IEnumerable <BaseMightyAttribute> wrappedAttributes) { if (serializedField.CacheSingleAttribute <BaseArrayAttribute>(fieldInfo.GetCustomAttributes <BaseArrayAttribute>(true))) { return; } serializedField.CacheSingleAttribute <BaseArrayAttribute>(wrappedAttributes); }
public void DrawElement(Rect position, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) { var attribute = (CustomDrawerAttribute)baseAttribute; GetDrawerForMember(serializedField, m_rectElementCallback, out var drawerMethod, attribute); InvokeDrawer(position, drawerMethod, $"Rect {attribute.DrawerCallback}(Rect position, MightySerializedField serializedField, int index)", position, serializedField, index); }
void IArrayDecoratorDrawer.EndDrawElement(MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute) { var decoratorPosition = PositionByMember(serializedField, baseAttribute); if (decoratorPosition.Contains(ArrayDecoratorPosition.After | ArrayDecoratorPosition.AfterElements)) { DrawDecoratorElement(serializedField, index, (ShowAssetPreviewAttribute)baseAttribute); } }
protected override void DrawProperty(MightySerializedField serializedField, SerializedProperty property, AssetOnlyAttribute attribute) { if (property.IsCollection()) { MightyGUIUtilities.DrawArray(property, index => DrawElement(serializedField, index, attribute)); return; } DrawAssetField(property, attribute); }
protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, ResizableTextAreaAttribute attribute) { if (property.IsCollection()) { MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute)); return; } DrawTextArea(property, attribute.Options); }
public void EndDrawHeader(MightySerializedField serializedField, BaseArrayDecoratorAttribute baseAttribute) { var position = PositionByMember(serializedField, baseAttribute); if (position.Contains(ArrayDecoratorPosition.AfterHeader) || position.Contains(ArrayDecoratorPosition.AfterHeaderFoldout) && serializedField.IsExpanded && serializedField.ArraySize > 0) { DrawDecorator(serializedField, (T)baseAttribute); } }
protected override void EndChangeCheck(bool changed, MightySerializedField mightyMember, LogOnChangedAttribute attribute) { if (!changed) { return; } var property = mightyMember.Property; Debug.Log($@"{property.displayName}: {PropertyUtilities.GetGenericValue(attribute.Target, property)}", mightyMember.Context.Object); }
Rect IArrayDecoratorDrawer.BeginDrawElement(Rect position, MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute) { var decoratorPosition = PositionByMember(serializedField, baseAttribute); if (decoratorPosition.Contains(ArrayDecoratorPosition.Before | ArrayDecoratorPosition.BeforeElements)) { position = DrawDecoratorElement(position, serializedField, index, (ShowAssetPreviewAttribute)baseAttribute); } return(position); }
protected override float GetDecoratorHeight(MightySerializedField serializedField, int index, ShowAssetPreviewAttribute attribute) { var element = serializedField.GetElement(index); Texture2D preview; if (element.propertyType != SerializedPropertyType.ObjectReference || element.objectReferenceValue == null || (preview = AssetPreview.GetAssetPreview(element.objectReferenceValue)) == null) { return(40); } return(GetClampedWidthAndHeight(preview.width, preview.height, attribute.Size).Item2 + MightyGUIUtilities.FIELD_SPACING); }
public static void CacheValidatorsForField(this MightySerializedField serializedField, FieldInfo fieldInfo, IEnumerable <BaseMightyAttribute> wrappedAttributes) { var validatorAttributes = new List <BaseValidatorAttribute>(); var any = PopulateAttributesList(validatorAttributes, fieldInfo.GetCustomAttributes <BaseValidatorAttribute>(true)); any = PopulateAttributesList(validatorAttributes, wrappedAttributes) || any; if (any) { serializedField.SetAttributes(validatorAttributes.ToArray()); } }
private float GetElementHeight(MightySerializedField serializedField, ReorderableListAttribute attribute, IArrayElementDrawer drawer, BasePropertyDrawerAttribute drawerAttribute, int index) { var decoratorAttributes = GetDecorationsForMember(serializedField, attribute); var height = drawer?.GetElementHeight(serializedField, index, drawerAttribute) ?? MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING; foreach (var decoratorAttribute in decoratorAttributes) { height += ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).GetElementHeight(serializedField, index, decoratorAttribute); } return(height + 2); }
protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, CustomDrawerAttribute attribute) { var target = attribute.Target; if (!serializedField.Property.IsCollection()) { InitCallback(serializedField, target, attribute.DrawerCallback, m_propertyCallback); } else { InitCallback(serializedField, target, attribute.DrawerCallback, m_elementCallback); InitCallback(serializedField, target, attribute.DrawerCallback, m_labeledElementCallback); InitCallback(serializedField, target, attribute.DrawerCallback, m_rectElementCallback); InitCallback(serializedField, target, attribute.ElementHeightCallback, m_elementHeightCallback); } }
public void BeginDrawElement(MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute) { var attribute = (T)baseAttribute; var position = PositionByMember(serializedField, attribute); if (position.Contains(ArrayDecoratorPosition.BeforeElements)) { DrawDecoratorElement(serializedField, index, attribute); } if (index != 0 && position.Contains(ArrayDecoratorPosition.BetweenElements)) { DrawDecoratorElement(serializedField, index, attribute); } }
protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, T attribute) { if (serializedField.Property.propertyType != SerializedPropertyType.String) { return; } if (!attribute.PathAsCallback || !serializedField.GetInfoFromMember <string>(attribute.Target, attribute.DefaultPath, out var pathInfo)) { pathInfo = new MightyInfo <string>(attribute.DefaultPath ?? Application.dataPath); } m_pathCache[serializedField] = pathInfo; }