Esempio n. 1
0
        public void DrawGUILine()
        {
            bool showWindow  = IsVisualizingUI;
            bool showDrawing = IsVisualizingDrawing;

            bool canShowWindow  = CanShowWindow;
            bool canShowDrawing = CanShowDrawing;

            var hasWindow  = showWindow;
            var hasDrawing = showDrawing;

            if (m_LineStyle == null)
            {
                InitLineStyle();
            }

            GUILayout.BeginHorizontal(m_IsHovering ? m_HoverStyle : m_LineStyle);
            if (hasWindow || canShowWindow)
            {
                showWindow = GUILayout.Toggle(showWindow, "", GUILayout.Width(15));
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(15));
            }

            if (hasDrawing || canShowDrawing)
            {
                showDrawing = GUILayout.Toggle(showDrawing, "", GUILayout.Width(15));
            }
            else
            {
                GUILayout.Label("", GUILayout.Width(15));
            }

            var baseColor = GUI.color;

            GUI.color = canShowWindow ? baseColor : Color.grey;

            GUILayout.Space(40);
            Rect space = GUILayoutUtility.GetLastRect();

            ROSConnection.DrawConnectionArrows(false,
                                               space.x + 5, space.y,
                                               Time.realtimeSinceStartup - TopicState.LastMessageReceivedRealtime,
                                               Time.realtimeSinceStartup - TopicState.LastMessageSentRealtime,
                                               TopicState.IsPublisher,
                                               TopicState.SentSubscriberRegistration,
                                               m_TopicState.Connection.HasConnectionError);

            if (GUILayout.Button(Title, m_LineStyle, GUILayout.Width(240)))
            {
                if (!canShowWindow)
                {
                    Debug.LogError($"No message class registered for type {RosMessageName}");
                }
                else if (!canShowDrawing)
                {
                    showWindow = !showWindow;
                }
                else
                {
                    var toggleOn = !showWindow || !showDrawing;
                    showWindow  = toggleOn;
                    showDrawing = toggleOn;
                }
            }

            GUI.color = baseColor;
            GUILayout.EndHorizontal();

            Rect horizontalRect = GUILayoutUtility.GetLastRect();

#if UNITY_EDITOR
            Rect buttonRect = new Rect(horizontalRect.xMax - 20, horizontalRect.center.y - 10, 20, 20);
            if (GUI.Button(buttonRect, "\u2630"))
            {
                ShowOptionsMenu(buttonRect);
            }
#endif

            if (m_IsHovering)
            {
                string  labelText = RosMessageName;
                Vector2 labelSize = GUI.skin.box.CalcSize(new GUIContent(labelText));

                GUI.Box(new Rect(horizontalRect.xMax - labelSize.x, horizontalRect.yMax - 10, labelSize.x, horizontalRect.height), labelText);
            }

            if (Event.current.type == EventType.Repaint)
            {
                m_IsHovering = horizontalRect.Contains(Event.current.mousePosition);
            }

            if (showDrawing != m_IsVisualizingDrawing || showWindow != m_IsVisualizingUI)
            {
                SetVisualizing(showWindow, showDrawing);
            }
        }