public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { HelpBoxAttribute helpBox = (HelpBoxAttribute)attribute; string content = ""; if (property.propertyType == SerializedPropertyType.String) { content = property.stringValue; } else if (property.propertyType == SerializedPropertyType.Integer) { content = property.intValue.ToString(); } else if (property.propertyType == SerializedPropertyType.Float) { content = property.floatValue.ToString(); } else { content = "Use helpbox with string, int and float values only."; } EditorGUI.HelpBox(position, content, GUIHelper.UnityMessageTypeConverter(helpBox.msgType)); }
// Make your own IMGUI based GUI for the property public override void OnGUI(Rect _position) { _position.height -= EditorGUIUtility.standardVerticalSpacing; HelpBoxAttribute _attribute = (HelpBoxAttribute)attribute; EditorGUI.HelpBox(_position, _attribute.Label, (MessageType)(int)_attribute.Type); }
public override void OnGUI(Rect position) { if (myattribute == null) { myattribute = attribute as HelpBoxAttribute; } Rect arect = position; arect.height = myattribute.line * 14f; EditorGUI.HelpBox(arect, myattribute.note, (MessageType)myattribute.messageType); }
/// <summary> 單行緊縮模式判斷 </summary> private bool isOneMiniLine(HelpBoxAttribute helpBox) { if (helpBox.isAlwaysOpen) { if (BoxHeight < 30) { return(true); } } return(false); }
public override float GetHeight() { float rt = 14f; if (myattribute == null) { myattribute = attribute as HelpBoxAttribute; } rt = myattribute.line * 14f; rt += 2f; return(rt); }
/// <summary> 初始化訊息欄風格 </summary> /// <param name="helpBox"> 參考風格 </param> private void InitStyle(HelpBoxAttribute helpBox) { if (HelpBoxStyle == null) { HelpBoxStyle = new GUIStyle(EditorStyles.helpBox); HelpBoxStyle.fontSize = 13; HelpBoxStyle.wordWrap = false; HelpBoxStyle.padding = new RectOffset(4, 4, 4, 4); //文字部分跟周圍邊框的間距 HelpBoxStyle.border = new RectOffset(4, 4, 4, 4); HelpBoxStyle.margin = new RectOffset(4, 4, 3, 3); } }
/// <summary> /// Get the <see cref="MessageType" /> that fits to the <see cref="HelpBoxAttribute" /> of <paramref name="attr" />. /// </summary> /// <param name="attr">Attribute</param> /// <returns>The appropriate <see cref="MessageType" />.</returns> private MessageType GetTypeForBox(HelpBoxAttribute attr) { switch (attr.Type) { case HelpBoxAttribute.HelpBoxType.Info: return(MessageType.Info); case HelpBoxAttribute.HelpBoxType.Warning: return(MessageType.Warning); case HelpBoxAttribute.HelpBoxType.Error: return(MessageType.Error); default: return(MessageType.None); } }
public override void OnGUI( Rect position, SerializedProperty property, GUIContent label) { // Let's start by calculating the rectangle in which we'll draw the // help box. // 'position' is the rectangle that we've been given to draw // everything to do with this property. It's calculated by taking // the width of the Inspector tab, and the height returned by // GetPropertyHeight. // The help box will be at the top of the property, so we just take // the original position, and reduce the height. var helpBoxPosition = position; helpBoxPosition.height = HelpBoxHeight; // Next, we figure out the rectangle we need to draw the property // in. // We'll start with the entire available area... var propertyPosition = position; // Shift it down by the help box's height, plus line spacing propertyPosition.y += EditorGUIUtility.standardVerticalSpacing + helpBoxPosition.height; // And update its height to be however tall the property wants to // be, including any child properties. propertyPosition.height = EditorGUI.GetPropertyHeight(property, includeChildren: true); // Get the text from the HelpBoxAttribute. HelpBoxAttribute helpBox = (attribute as HelpBoxAttribute); string text = helpBox.text; // Draw the help box itself. EditorGUI.HelpBox(helpBoxPosition, text, MessageType.Info); // Draw the original property underneath. EditorGUI.PropertyField( propertyPosition, property, includeChildren: true); }
public override float GetHeight() { HelpBoxAttribute helpBox = (HelpBoxAttribute)attribute; InitStyle(helpBox); BoxHeight = HelpBoxStyle.CalcHeight(new GUIContent(helpBox.text), EditorGUIUtility.currentViewWidth); //None 類型由於沒有圖示無法產生折疊按鍵,故直接返回預設大小 if (helpBox.BoxType == HelpBoxType.None) { return(BoxHeight); } //關閉摺疊功能的話也直接返回預設大小 if (helpBox.isAlwaysOpen) { return(BoxHeight); } //至少要有指定的最小高度使介面看起來一致 if (BoxHeight < minHeight) { return(minHeight); } //如果高度有超過最小高度的話,依折疊狀態顯示高度 if (helpBox.isFoldout) { return(BoxHeight); } else { return(minHeight); } }
/*************************** ******* METHODS ******* **************************/ // Specify how tall the GUI for this decorator is in pixels public override float GetHeight() { HelpBoxAttribute _attribute = (HelpBoxAttribute)attribute; return(Mathf.Max(EditorGUIUtilityEnhanced.DefaultHelpBoxHeight, EditorStyles.helpBox.CalcHeight(new GUIContent(_attribute.Label), EditorGUIUtility.currentViewWidth - WidthSubtractor)) + EditorGUIUtility.standardVerticalSpacing); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { HelpBoxAttribute helpBox = (HelpBoxAttribute)attribute; return(EditorGUI.GetPropertyHeight(property, label) * helpBox.overrideHeight); }
//這裡不直接使用 EditorGUI.HelpBox 以方便擴展 public override void OnGUI(Rect position) { //取得訊息、初始化 UI風格 HelpBoxAttribute helpBox = (HelpBoxAttribute)attribute; InitStyle(helpBox); //與下方參數的距離 = 2 position.height -= 2; position = EditorGUI.IndentedRect(position); //背景圖 (無框風格) //Texture2D originTex = HelpBoxStyle.normal.background; //HelpBoxStyle.normal.background = originTex; //HelpBoxStyle.normal.background = EditorGUIUtility.whiteTexture; //Color tColor = GUI.color; //GUI.color = helpBoxBackGroundColor; //GUI.DrawTexture(position, HelpBoxStyle.normal.background); //GUI.color = tColor; //背景圖 (有黑色邊框) GUI.Box(position, "", EditorStyles.helpBox); //None 類型文字置左+置中,介面比較好看 if (helpBox.BoxType == HelpBoxType.None) { HelpBoxStyle.alignment = TextAnchor.MiddleLeft; } //其它類型如果高度不高,文字也置左+置中 else { if (BoxHeight < minHeight) { HelpBoxStyle.alignment = TextAnchor.MiddleLeft; } else { HelpBoxStyle.alignment = TextAnchor.UpperLeft; } } //顯示文字訊息 HelpBoxStyle.normal.background = null; tmpContent.text = helpBox.text; tmpContent.tooltip = ""; tmpContent.image = null; if (helpBox.BoxType == HelpBoxType.None) { position.x += 2; } else { position.x += 30; } position.width = EditorGUIUtility.currentViewWidth - 50; EditorGUI.LabelField(position, tmpContent, HelpBoxStyle); if (helpBox.BoxType == HelpBoxType.None) { position.x -= 2; } else { position.x -= 30; } //顯示資訊類型的圖示 HelpBoxStyle.imagePosition = ImagePosition.ImageOnly; HelpBoxStyle.normal.background = null; tmpContent.image = GetHelpIcon(helpBox.BoxType); position.y += position.height * 0.5f; position.y -= 18; position.width = 36; position.height = 36; if (isOneMiniLine(helpBox)) { //單行緊縮模式下,特定類型的圖片稍作調整,使介面美觀 if (helpBox.BoxType == HelpBoxType.Warning) { position.y += 1; position.width = 35; position.height = 35; } else if (helpBox.BoxType == HelpBoxType.Error) { position.y += 2; position.width = 35; position.height = 35; } } EditorGUI.LabelField(position, tmpContent, HelpBoxStyle); HelpBoxStyle.imagePosition = ImagePosition.ImageLeft; //None 類型由於沒有圖示無法產生折疊按鍵,故下面不做處理,並恢復文字對齊方式 if (helpBox.BoxType == HelpBoxType.None) { HelpBoxStyle.alignment = TextAnchor.UpperLeft; return; } //如果高度不高,沒有摺疊的問題,故下面也不做處理 if (BoxHeight < minHeight) { return; } //如果關閉摺疊功能,也不處理摺疊開關 if (helpBox.isAlwaysOpen) { return; } //調整折疊關的風格 (隱藏 HelpBox背景圖) HelpBoxStyle.normal.background = null; //折疊時的提示 if (!helpBox.isFoldout) { //折疊時的顯示「---」表示摺疊中 tmpContent.text = "---"; tmpContent.image = null; position.width = 30; position.height = 16; HelpBoxStyle.alignment = TextAnchor.MiddleLeft; position.x += 4; position.y += 20; EditorGUI.LabelField(position, tmpContent, HelpBoxStyle); position.y -= 20; position.x -= 4; //針對按鍵位置的位移,使折疊與非折疊時按鍵位置一致 position.y += 10; } //折疊按鍵 position.x += 6f; position.y += position.height * 0.5f; position.y -= 10; position.width = 22; position.height = 22; if (GUI.Button(position, "", HelpBoxStyle)) { helpBox.isFoldout = !helpBox.isFoldout; } }