/// <summary> /// Draws the node and it's ports to the GUI layer /// </summary> public virtual void Draw() { if (Application.isPlaying) { GUI.color = Color.white; } if (NameChanged) { float actualw = DefaultSize.x; float width = Mathf.Clamp(Style.CalcSize(new GUIContent(name)).x + 20, actualw, float.MaxValue); rect.width = width; NameChanged = false; } GUI.Box(rect, name, Style); GUIContent labelcont = new GUIContent((!string.IsNullOrEmpty(Tooltip) ? "// " + Tooltip : string.Empty)); Vector2 labelsize = EditorStyles.label.CalcSize(labelcont); float LW = labelsize.x + 5; float y = (tooltipPosition == TooltipPosition.Down) ? rect.yMax + 5 : (rect.y - 5) - labelsize.y; GUI.Label(new Rect((rect.x + rect.width) - LW, y, LW, labelsize.y), labelcont, new GUIStyle(EditorStyles.label) { normal = new GUIStyleState() { textColor = new Color(0.7f, 0.7f, 0.7f, 0.8f) } }); }
public CAbstractButton(string title) { Content = new GUIContent(title); Vector2 size = Style.CalcSize(Content); Width = size.x + 2 * CUISize.ButtonBorder; Height = CUISize.ButtonHeight; }
public Toggle(string title, bool isOn = false) { m_content = new GUIContent(title); IsOn = isOn; Vector2 size = Style.CalcSize(m_content); Width = size.x; Height = size.y; }
public override void SetStyle() { Style.normal.background = AssetDatabase.LoadAssetAtPath("Assets/Resources/Textures/grayTex.png", typeof(Texture2D)) as Texture2D; Style.normal.textColor = Color.white; Style.fontSize = 16; Style.alignment = TextAnchor.UpperCenter; GUIContent content = new GUIContent(Name); mOffset = Style.CalcSize(content).y; }
//-------------------------------------【OnDrawGizmos()函数】--------------------------------------------- // 说明:场景编辑器中GUI的显示 //------------------------------------------------------------------------------------------------------------------ void OnDrawGizmos() { //ShowInfoInSeneEditor为真时,才进行绘制 if (ShowInfoInSceneEditor) { //----------------------------------------【1.光线投射判断&计算位置坐标】---------------------------------- //定义一条射线 Ray ray = new Ray(transform.position + Camera.current.transform.up * 6f, -Camera.current.transform.up); //定义光线投射碰撞 RaycastHit raycastHit; //进行光线投射操作,第一个参数为光线的开始点和方向,第二个参数为光线碰撞器碰到哪里的输出信息,第三个参数为光线的长度 GetComponent <Collider>().Raycast(ray, out raycastHit, Mathf.Infinity); //计算距离,为当前摄像机位置减去碰撞位置的长度 float distance = (Camera.current.transform.position - raycastHit.point).magnitude; //设置字体大小,在26到12之间插值 float fontSize = Mathf.Lerp(26, 12, distance / 10f); //将得到的字体大小赋给Style.fontSize Style.fontSize = (int)fontSize; //将文字位置取为得到的光线碰撞位置上方一点 Vector3 worldPositon = raycastHit.point + Camera.current.transform.up * distance * 0.03f; //世界坐标转屏幕坐标 Vector3 screenPosition = Camera.current.WorldToScreenPoint(worldPositon); //z坐标值的判断,z值小于零就返回 if (screenPosition.z <= 0) { return; } //翻转Y坐标值 screenPosition.y = Screen.height - screenPosition.y; //获取文本尺寸 Vector2 stringSize = Style.CalcSize(new GUIContent(text)); //计算文本框坐标 Rect rect = new Rect(0f, 0f, stringSize.x + 6, stringSize.y + 4); //设定文本框中心坐标 rect.center = screenPosition - Vector3.up * rect.height * 0.5f; //----------------------------------【2.GUI绘制】--------------------------------------------- //开始绘制一个简单的文本框 // Handles.BeginGUI(); //绘制灰底背景 GUI.color = new Color(0f, 0f, 0f, 0.8f); GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); //绘制文字 GUI.color = new Color(1, 1, 1, 0.8f); GUI.Label(rect, text, Style); //结束绘制 // Handles.EndGUI(); } }
public void OnGUI() { var position = new Vector2(); var contentSize = Style.CalcSize(_content); if (!_positioner.GetPosition(ref position, _content, contentSize)) { Destroy(gameObject); return; } GUI.Label(new Rect(position.x, position.y, contentSize.x, contentSize.y), _content, Style); }
protected override void ResizeControl() { if (this.AutoSize) { try { Vector2 size = Style.CalcSize(Content); __Size = new System.Drawing.Size((int)size.x, (int)size.y); } catch { } } }
////////////////////////////////////////////////////////////////////////////// private Vector2 WordWrap(GUIContent content, float maxWidth) { string[] words = content.text.Split(' '); string result = ""; Vector2 size = new Vector2(); for (int i = 0; i < words.Length; ++i) { content.text = result + words [i] + ' '; size = Style.CalcSize(content); if (size.x > maxWidth) { result += ('\n' + words [i] + ' '); } else { result = content.text; } } return(size); }
/// <summary> /// Returns the size of the item /// </summary> /// <returns>the size the item needs</returns> public virtual Vector2 GetItemSize() { return(Style.CalcSize(Content)); }
public Vector2 CalcTextSize() { return(Style.CalcSize(m_content)); }
////////////////////////////////////////////////////////////////////////////// public float CalcTextWidth() { return(Style.CalcSize(m_content).x); }