protected void DrawBox(Rect pos, SerializedProperty prop, ref GUIContent label, float indent1, bool displayedValue) { string lbl = label.text; string tooltip = label.tooltip; float h = CalculateHeight(prop, displayedValue); label.text = lbl; label.tooltip = tooltip; pos.x = indent1; pos.width -= GUITools.iconButtonWidth; pos.height = h + GUITools.singleLineHeight * .1f; GUITools.Box(pos, GUITools.shade); }
protected void DrawAddElement(Rect pos, SerializedProperty prop, float indent1, bool displayedValue) { GUI.enabled = displayedValue; if (GUITools.IconButton(indent1, pos.y, addContent, displayedValue ? GUITools.green : GUITools.white)) { prop.InsertArrayElementAtIndex(prop.arraySize); SerializedProperty p = prop.GetArrayElementAtIndex(prop.arraySize - 1); if (p.propertyType == SerializedPropertyType.ObjectReference) { p.objectReferenceValue = null; } OnAddNewElement(p); } GUI.enabled = true; }
public Object Draw(Object current, GUIContent gui, Func <List <AssetSelectorElement>, List <AssetSelectorElement> > onAssetsLoaded) { EditorGUILayout.BeginHorizontal(); //draw field int selected = EditorGUILayout.Popup(gui, GetActiveIndex(current), allNames); // draw reset button if (GUITools.IconButton(resetButtonContent, GUITools.white)) { UpdateAssetReferences(true, onAssetsLoaded); } EditorGUILayout.EndHorizontal(); return(selected < 0 ? null : elements[selected].asset); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { NeatArrayAttribute att = attribute as NeatArrayAttribute; int origIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; float indent1, indent2, indent2Width; bool displayedValue; string lbl = label.text; StartArrayDraw(pos, ref prop, out indent1, out indent2, out indent2Width, out displayedValue); if (att != null) { MakeSureSizeIsOK(prop, att.enforceSize); } if (att == null || att.enforceSize < 0) { DrawAddElement(pos, prop, indent1, displayedValue); } float xOffset = (att == null || att.enforceSize < 0 ? indent2 : indent1) + GUITools.toolbarDividerSize; // DrawArrayTitle ( pos, prop.arraySize, lbl, att != null ? att.tooltip : string.Empty, xOffset ); string tooltip = att != null ? att.tooltip : string.Empty; lbl += " [" + prop.arraySize + "] "; GUITools.Label(new Rect(xOffset, pos.y, pos.width, pos.height), new GUIContent(lbl), GUITools.black, GUITools.boldLabel); bool showsTooltip = false; if (displayedValue && !string.IsNullOrEmpty(tooltip)) { showsTooltip = true; GUIContent ttGUI = new GUIContent(tooltip); // float ttWidth = tooltipStyle.CalcSize(ttGUI).x; // GUITools.Label(new Rect(pos.x + pos.width - ttWidth, pos.y, ttWidth, pos.height), ttGUI, GUITools.black, tooltipStyle); GUITools.Label(new Rect(xOffset, pos.y + EditorGUIUtility.singleLineHeight, pos.width, pos.height), ttGUI, GUITools.black, tooltipStyle); } if (displayedValue) { int indexToDelete = -1; pos.x = xOffset; pos.y += GUITools.singleLineHeight * (showsTooltip ? 2 : 1); pos.width = indent2Width - GUITools.toolbarDividerSize * 2; pos.height = EditorGUIUtility.singleLineHeight; GUIContent deleteContent = BuiltInIcons.GetIcon("Toolbar Minus", "Delete Element"); for (int i = 0; i < prop.arraySize; i++) { if (att == null || att.enforceSize < 0) { if (GUITools.IconButton(indent1, pos.y, deleteContent, GUITools.red)) { indexToDelete = i; } } SerializedProperty p = prop.GetArrayElementAtIndex(i); EditorGUI.PropertyField(pos, p, GUITools.noContent, true); pos.y += EditorGUI.GetPropertyHeight(p, true); } if (indexToDelete != -1) { SerializedProperty p = prop.GetArrayElementAtIndex(indexToDelete); if (p.propertyType == SerializedPropertyType.ObjectReference) { if ((prop.objectReferenceValue) != null) { prop.DeleteArrayElementAtIndex(indexToDelete); } } prop.DeleteArrayElementAtIndex(indexToDelete); } } EditorGUI.indentLevel = origIndentLevel; }
protected void DrawArrayTitle(Rect pos, SerializedProperty prop, GUIContent label, float xOffset) { label.text += " [" + prop.arraySize + "]"; pos.x = xOffset; GUITools.Label(pos, label, GUITools.black, GUITools.boldLabel); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { NeatArrayAttribute att = attribute as NeatArrayAttribute; float indent1, indent2, indent2Width; bool displayedValue; StartArrayDraw(pos, ref prop, ref label, out indent1, out indent2, out indent2Width, out displayedValue); if (att != null) { MakeSureSizeIsOK(prop, att.enforceSize); } if (att == null || att.enforceSize < 0) { DrawAddElement(pos, prop, indent1, displayedValue); } float xOffset = (att == null || att.enforceSize < 0 ? indent2 : indent1) + GUITools.toolbarDividerSize; DrawArrayTitle(pos, prop, label, xOffset); if (displayedValue) { int indexToDelete = -1; pos.x = xOffset; pos.y += GUITools.singleLineHeight; pos.width = indent2Width - GUITools.toolbarDividerSize * 2; pos.height = EditorGUIUtility.singleLineHeight; for (int i = 0; i < prop.arraySize; i++) { if (att == null || att.enforceSize < 0) { if (GUITools.IconButton(indent1, pos.y, deleteContent, GUITools.red)) { indexToDelete = i; } } SerializedProperty p = prop.GetArrayElementAtIndex(i); EditorGUI.PropertyField(pos, p, true); pos.y += EditorGUI.GetPropertyHeight(p, true); } if (indexToDelete != -1) { SerializedProperty p = prop.GetArrayElementAtIndex(indexToDelete); OnDeleteElement(p); if (p.propertyType == SerializedPropertyType.ObjectReference) { prop.DeleteArrayElementAtIndex(indexToDelete); } prop.DeleteArrayElementAtIndex(indexToDelete); } } EditorGUI.EndProperty(); }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width - GUITools.iconButtonWidth, EditorGUIUtility.singleLineHeight), prop.FindPropertyRelative("buildTarget"), true); GUITools.DrawIconToggle(prop.FindPropertyRelative("autoRun"), new GUIContent("A", "Auto Run"), pos.x + (pos.width - GUITools.iconButtonWidth), pos.y); EditorGUI.PropertyField(new Rect(pos.x, pos.y + EditorGUIUtility.singleLineHeight, pos.width, EditorGUIUtility.singleLineHeight), prop.FindPropertyRelative("customDefines"), true); }
bool DrawButton(float x, Rect pos, GUIContent gui) { return(GUITools.Button(x, pos.y, pos.width - ((x - pos.x) + GUITools.iconButtonWidth), GUITools.singleLineHeight, gui, GUITools.popup)); }