Exemple #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);
        }
Exemple #2
0
        public ConnectionDropDownItem(string content, int connectionId, string subGroup, ConnectionMajorGroup topLevelGroup, Func <bool> connected, Action onSelected,
                                      bool isDevice = false, string iconString = null)
        {
            var idString = ConnectionUIHelper.GetIdString(content);

            DisplayName     = subGroup == ConnectionUIHelper.kDevices ? content : ConnectionUIHelper.GetPlayerNameFromIDString(idString);
            DisplayNameSize = ConnectionDropDownStyles.sTVLine.CalcSize(GUIContent.Temp(DisplayName)).x;

            ProjectName     = subGroup == ConnectionUIHelper.kDevices ? "" : ConnectionUIHelper.GetProjectNameFromConnectionIdentifier(connectionId);
            ProjectNameSize = ConnectionDropDownStyles.sTVLine.CalcSize(GUIContent.Temp(ProjectName)).x;

            IP     = ConnectionUIHelper.GetIP(connectionId);
            IPSize = ConnectionDropDownStyles.sTVLine.CalcSize(GUIContent.Temp(IP)).x;

            Port     = ConnectionUIHelper.GetPort(connectionId);
            PortSize = ConnectionDropDownStyles.sTVLine.CalcSize(GUIContent.Temp(Port)).x;

            m_ConnectionId  = connectionId;
            m_Connected     = connected;
            m_OnSelected    = onSelected;
            m_SubGroup      = string.IsNullOrEmpty(subGroup) ? ConnectionUIHelper.GetRuntimePlatformFromIDString(idString) : subGroup;
            m_TopLevelGroup = topLevelGroup == ConnectionMajorGroup.Unknown ? (m_SubGroup == Content.DirectConnection ? ConnectionMajorGroup.Direct : (ProfilerDriver.IsIdentifierOnLocalhost(connectionId) ? ConnectionMajorGroup.Local : ConnectionMajorGroup.Remote)) : topLevelGroup;

            if (m_TopLevelGroup == ConnectionMajorGroup.Direct)
            {
                DisplayName = content;
            }

            if (string.IsNullOrEmpty(m_SubGroup))
            {
                if (idString == "Editor" || idString == "Main Editor Process")
                {
                    m_TopLevelGroup = ConnectionMajorGroup.Editor;
                    m_SubGroup      = "Editor";
                }
                else
                {
                    DisplayName         = content;
                    m_TopLevelGroup     = ConnectionMajorGroup.ConnectionsWithoutID;
                    OldConnectionFormat = true;
                }
            }

            displayName = DisplayName + ProjectName;
            id          = GenerateID();
            IsDevice    = isDevice;
            if (isDevice)
            {
                IconContent = ConnectionUIHelper.GetIcon(iconString);
            }
        }
Exemple #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);
            }
        }