private void HandleProperty(SerializedProperty prop) { if (prop.name.Equals("m_Script")) { return; } var disabledAttribute = UTUtils.GetPropertyAttribute <DisabledAttribute>(prop); propDisabled = false; if (disabledAttribute != null) { if (disabledAttribute.methodName != null) { propDisabled = UTUtils.GetVisibleThroughAttribute(prop, disabledAttribute.methodName, false); } else { propDisabled = true; } } if (prop.isArray && prop.propertyType != SerializedPropertyType.String) { HandleArray(prop); } else { EditorGUI.BeginChangeCheck(); EditorGUI.BeginDisabledGroup(propDisabled); EditorGUILayout.PropertyField(prop); EditorGUI.EndDisabledGroup(); if (!EditorGUI.EndChangeCheck()) { return; } var changeCallback = UTUtils.GetPropertyAttribute <OnValueChangedAttribute>(prop); if (changeCallback == null) { return; } var m = prop.serializedObject.targetObject.GetType().GetMethod(changeCallback.methodName, UTUtils.flags); if (m == null) { return; } if (m.GetParameters().Length > 1) { m.Invoke( serializedObject.targetObject, new object[] { serializedObject, prop }); } else { m.Invoke( serializedObject.targetObject, new object[] { prop }); } } propDisabled = false; }
private void RenderHelpBox(SerializedProperty prop) { var helpBoxAttr = UTUtils.GetPropertyAttribute <HelpBoxAttribute>(prop); if (helpBoxAttr != null) { if (helpBoxAttr.methodName.Length > 0 && !UTUtils.GetVisibleThroughAttribute(prop, helpBoxAttr.methodName, false)) { return; } UTStyles.RenderNote(helpBoxAttr.text); } }
public override void AfterGUI(Rect position, SerializedProperty property, GUIContent label) { if (!isVisible) { return; } if (property.name == "data" && property.depth > 0) { return; } var rect = EditorGUI.IndentedRect(position); // check for section header var secHeader = UTUtils.GetPropertyAttribute <SectionHeaderAttribute>(property); rect.yMin += secHeader != null ? fieldHeight / 2 + 2 : fieldHeight + 2; rect.height = boxHeight; UTStyles.RenderNote(ref rect, text); }
private void RenderArray(SerializedProperty prop, string changedCallback) { var formatted = Regex.Split(prop.name, @"(?<!^)(?=[A-Z])"); formatted[0] = formatted[0].Substring(0, 1).ToUpper() + formatted[0].Substring(1); var disabledString = propDisabled ? "[Read Only]" : ""; prop.isExpanded = UTStyles.FoldoutHeader($"{String.Join(" ", formatted)} [{prop.arraySize}] {disabledString}", prop.isExpanded); var foldoutRect = GUILayoutUtility.GetLastRect(); if (!propDisabled) { HandleDragAndDrop(foldoutRect, prop); if (droppedObjects) { return; } } if (!prop.isExpanded) { return; } EditorGUI.BeginDisabledGroup(propDisabled); var popup = UTUtils.GetPropertyAttribute <PopupAttribute>(prop); for (int i = 0; i < prop.arraySize; i++) { EditorGUILayout.BeginHorizontal(); if (RenderPositionControls(i, new[] { prop })) { break; } EditorGUI.BeginChangeCheck(); if (popup == null) { EditorGUILayout.PropertyField(prop.GetArrayElementAtIndex(i), new GUIContent()); } else { var options = UTUtils.GetPopupOptions(prop.GetArrayElementAtIndex(i), null, popup, out var selectedIndex); selectedIndex = EditorGUILayout.Popup(selectedIndex, options); prop.GetArrayElementAtIndex(i).stringValue = options[selectedIndex]; } if (EditorGUI.EndChangeCheck()) { HandleChangeCallback(t, changedCallback, prop, null, new object[] { prop.GetArrayElementAtIndex(i), i }); } if (RenderRemoveControls(i, new[] { prop })) { HandleChangeCallback(t, changedCallback, prop, null, new object[] { null, i }); break; } EditorGUILayout.EndHorizontal(); } if (!propDisabled) { EditorGUILayout.BeginHorizontal(); if (RenderAddControls(new[] { prop }, "Add Element", null)) { HandleChangeCallback(t, changedCallback, prop, null, new object[] { prop.GetArrayElementAtIndex(prop.arraySize - 1), prop.arraySize - 1 }); } if (GUILayout.Button("Clear", GUILayout.MaxWidth(60))) { prop.arraySize = 0; HandleChangeCallback(t, changedCallback, prop, null, new object[] { null, 0 }); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); }
private void HandleArray(SerializedProperty prop) { var attrs = UTUtils.GetPropertyAttributes(prop); var modifierAttrs = UTUtils.GetPropertyAttributes <Attribute>(prop); var isGroup = attrs.Where(a => a is ListViewAttribute).ToArray().Length > 0; var groupAttribute = attrs.Select(a => a as ListViewAttribute).ToArray(); var onValueChangedAttribute = UTUtils.GetPropertyAttribute <OnValueChangedAttribute>(prop); // hideIf attribute var hideIfAttribute = modifierAttrs.OfType <HideIfAttribute>().ToArray(); var isHidden = hideIfAttribute.Length > 0 && UTUtils.GetVisibleThroughAttribute(prop, hideIfAttribute[0].methodName, false); // handling for regular arrays, make nicer down the line if (!isGroup) { if (isHidden) { return; } RenderArray(prop, onValueChangedAttribute?.methodName); if (droppedObjects) { return; } RenderHelpBox(prop); return; } var groupName = groupAttribute[0].name; var items = cT.GetFields().Where(f => f.GetAttribute <ListViewAttribute>() != null && f.GetAttribute <ListViewAttribute>().name == groupName) .ToList(); // fast exit on 1 element with list view if (items.Count < 2) { if (isHidden) { return; } RenderArray(prop, onValueChangedAttribute?.methodName); if (droppedObjects) { return; } RenderHelpBox(prop); return; } var index = items.FindIndex(a => a.Name == prop.name); if (index > 0) { return; } var sectionHeaderAttribute = UTUtils.GetPropertyAttribute <SectionHeaderAttribute>(prop); if (sectionHeaderAttribute != null) { UTStyles.RenderSectionHeader(sectionHeaderAttribute.text); } if (isHidden) { return; } var otherProp = serializedObject.FindProperty(items[1].Name); var leftPopupAttribute = UTUtils.GetPropertyAttribute <PopupAttribute>(prop); var rightPopupAttribute = UTUtils.GetPropertyAttribute <PopupAttribute>(otherProp); if (rightPopupAttribute != null || leftPopupAttribute != null) { RenderStackedArray(groupAttribute[0].name, prop, otherProp, leftPopupAttribute, rightPopupAttribute, groupAttribute[0].addMethodName, groupAttribute[0].addButtonText, onValueChangedAttribute?.methodName); if (droppedObjects) { return; } RenderHelpBox(prop); return; } RenderStackedArray(groupAttribute[0].name, prop, otherProp, groupAttribute[0].addMethodName, groupAttribute[0].addButtonText, onValueChangedAttribute?.methodName); if (droppedObjects) { return; } RenderHelpBox(prop); }