コード例 #1
0
        public void AddItem(ConnectionDropDownItem connectionDropDownItem)
        {
            // *begin-nonstandard-formatting*
            connectionItems ??= new List <ConnectionDropDownItem>();
            // *end-nonstandard-formatting*
            // this is a hack to show switch connected over ethernet in devices
            if (connectionDropDownItem.IP == "127.0.0.1" && ProfilerDriver.GetConnectionIdentifier(connectionDropDownItem.m_ConnectionId).StartsWith("Switch"))
            {
                connectionDropDownItem.m_TopLevelGroup = ConnectionDropDownItem.ConnectionMajorGroup.Local;
                connectionDropDownItem.m_SubGroup      = "Devices";
                connectionDropDownItem.IsDevice        = true;
                connectionDropDownItem.IconContent     = ConnectionUIHelper.GetIcon("Switch");
                var fullName = ProfilerDriver.GetConnectionIdentifier(connectionDropDownItem.m_ConnectionId);
                var start    = fullName.IndexOf('-') + 1;
                var end      = fullName.IndexOf('(');
                connectionDropDownItem.DisplayName = $"{fullName.Substring(start, end - start)} - {ProfilerDriver.GetProjectName(connectionDropDownItem.m_ConnectionId)}";
            }

            var dupes = connectionItems.FirstOrDefault(x => x.DisplayName == connectionDropDownItem.DisplayName && x.IP == connectionDropDownItem.IP && x.Port == connectionDropDownItem.Port);

            if (dupes != null)
            {
                connectionItems.Remove(dupes);
            }

            connectionItems.Add(connectionDropDownItem);
        }
コード例 #2
0
 public void AddDisabledItem(ConnectionDropDownItem connectionDropDownItem)
 {
     connectionDropDownItem.m_Disabled = true;
     AddItem(connectionDropDownItem);
 }
コード例 #3
0
        void CellGUI(Rect cellRect, TreeViewItem item, ConnectionDropDownColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);
            ConnectionDropDownItem cddi = null;

            if (item is ConnectionDropDownItem downItem)
            {
                cddi = downItem;
            }

            switch (column)
            {
            case ConnectionDropDownColumns.DisplayName:
                if (cddi != null)
                {    //actual connections
                    var rect = cellRect;
                    rect.x += GetContentIndent(item) - foldoutWidth;

                    EditorGUI.BeginChangeCheck();
                    rect.width = ConnectionDropDownStyles.ToggleRectWidth;
                    var isConnected = cddi.m_Connected?.Invoke() ?? false;
                    GUI.Label(rect, (isConnected ? EditorGUIUtility.IconContent("Valid") : GUIContent.none));
                    rect.x += ConnectionDropDownStyles.ToggleRectWidth;
                    if (cddi.IsDevice)
                    {
                        EditorGUI.LabelField(new Rect(rect.x, rect.y, rowHeight, rowHeight), cddi.IconContent);
                        rect.x += rowHeight;
                    }
                    var textRect = cellRect;
                    textRect.x     = rect.x;
                    textRect.width = cellRect.width - (textRect.x - cellRect.x);

                    GUI.Label(textRect, ConnectionUIHelper.TruncateString(cddi.DisplayName, ConnectionDropDownStyles.sTVLine, textRect.width));
                    if (EditorGUI.EndChangeCheck())
                    {
                        cddi.m_OnSelected.Invoke();
                    }
                }
                else
                {
                    var r = cellRect;
                    if (item.depth <= 0)
                    {    // major group headers
                        if (args.row != 0)
                        {
                            EditorGUI.DrawRect(new Rect(r.x, r.y, args.rowRect.width, 1f), ConnectionDropDownStyles.SeparatorColor);
                        }
                        r.x    += GetContentIndent(item);
                        r.width = args.rowRect.width - GetContentIndent(item);
                        GUI.Label(r, item.displayName, EditorStyles.boldLabel);
                    }
                    else
                    {    // sub group headers
                        r.x += GetContentIndent(item);
                        EditorGUI.LabelField(new Rect(r.x, r.y, rowHeight, rowHeight), ConnectionUIHelper.GetIcon(item.displayName));
                        GUI.Label(new Rect(r.x + rowHeight, r.y, r.width - rowHeight, r.height), item.displayName, EditorStyles.miniBoldLabel);
                    }
                }
                break;

            case ConnectionDropDownColumns.ProjectName:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.ProjectName, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            case ConnectionDropDownColumns.IP:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.IP, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            case ConnectionDropDownColumns.Port:
                if (item.depth > 1)
                {
                    DrawVerticalSeparatorLine(cellRect);
                    GUI.Label(cellRect, ConnectionUIHelper.TruncateString(cddi.Port, ConnectionDropDownStyles.sTVLine, cellRect.width));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(column), column, null);
            }
        }