/// <summary> /// /// </summary> static Rect ValueField(Rect pos, ref int value, string name, System.Action action, float extraSize = 0, System.Action deleteAction = null) { if (name == null) { name = ""; } pos.x -= extraSize; pos.width = ValueStyle.CalcSize(new GUIContent(name)).x + 19 + ((deleteAction == null) ? 0 : (21 - 3)) + extraSize; pos.height = 21; GUI.color = new Color(0.85f, 0.85f, 0.85f, 1); if (value != -1) { GUI.Label(pos, name, ValueStyle); } GUI.color = Color.white; if (value != -1) { // draw editbox Rect n1 = pos; n1.x += ValueStyle.CalcSize(new GUIContent(name)).x - 30; n1.y += 3; n1.width = 45 + extraSize; n1.height = 21; int oldValue = value; value = Mathf.Max(0, EditorGUI.IntField(n1, value, TextFieldStyle)); if ((value != oldValue) && (action != null)) { action.Invoke(); } } if (deleteAction != null) { Rect d = pos; d.x = pos.x + pos.width - 21; d.width = 21; //GUI.Label(d, "", ValueStyle); d.y += 3; d.x += 3; if (GUI.Button(d, "X", SmallButtonStyle) && (deleteAction != null)) { deleteAction.Invoke(); } d.x -= 3; d.y -= 3; } return(pos); }
/// <summary> /// /// </summary> static float CalcValueFieldSize(string name, bool hasDeleteButton = false) { float f = 0.0f; if (!string.IsNullOrEmpty(name)) { f = ValueStyle.CalcSize(new GUIContent(name)).x + 18; } if (hasDeleteButton) { f += 21; } return(f); }