Exemplo n.º 1
0
    private void OnGUI()
    {
        if (s_Styles == null)
        {
            s_Styles = new Styles();
        }
        m_ListView.totalRows = m_MsgList.Count;

        Event current = Event.current;

        EditorGUILayout.BeginVertical();
        GUIContent textContent = new GUIContent();

        foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, m_ColWidths, s_Styles.listBackgroundStyle))
        {
            if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2)
            {
                Debug.Log("点中了" + "行" + el.row + "列" + el.column);
            }
            if (current.type == EventType.Repaint)
            {
                textContent.text = GetRowText(el);

                // 交替显示不同背景色
                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                style.Draw(el.position, false, false, m_ListView.row == el.row, false);
                s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus);
            }
        }
        EditorGUILayout.EndVertical();
    }
    private void OnGUI()
    {
        if (s_Styles == null)
        {
            s_Styles = new Styles();
        }
        s_Styles.listItem.fixedHeight = 22f;
        m_ListView.totalRows          = m_MsgList.Count;
        m_ListView.rowHeight          = 22;

        Event current = Event.current;

        EditorGUILayout.BeginVertical();
        GUIContent textContent = new GUIContent();
        Rect       btnRect     = new Rect();

        foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, s_Styles.listBackgroundStyle))
        {
            btnRect        = el.position;
            btnRect.x     += btnRect.width - 32f;
            btnRect.y     += 2f;
            btnRect.width  = 30f;
            btnRect.height = 18f;

            if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition))
            {
                if (btnRect.Contains(current.mousePosition))
                {
                    Debug.Log("点击第" + el.row + "的按钮");
                }
                else if (current.clickCount == 2)
                {
                    Debug.Log(el.row);
                }
            }
            if (current.type == EventType.Repaint)
            {
                textContent.text = GetRowText(el);

                // 交替显示不同背景色
                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                style.Draw(el.position, false, false, m_ListView.row == el.row, false);
                s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus);


                textContent.text = ">>";
                GUI.skin.button.Draw(btnRect, textContent, false, false, false, false);
            }
        }
        EditorGUILayout.EndVertical();
        s_Styles.listItem.fixedHeight = 16f;
    }
    private void OnGUI()
    {
        if (s_Styles == null)
        {
            s_Styles = new Styles();
        }
        m_ListView.totalRows = m_MsgList.Count;

        Event current = Event.current;

        EditorGUILayout.BeginVertical();
        GUIContent textContent = new GUIContent();

        foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsReordering, s_Styles.listBackgroundStyle))
        {
            if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2)
            {
                Debug.Log(el.row);
            }
            if (current.type == EventType.Repaint)
            {
                textContent.text = GetRowText(el);

                // 交替显示不同背景色
                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                style.Draw(el.position, false, false, m_ListView.row == el.row, false);
                s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus);
            }
        }
        EditorGUILayout.EndVertical();

        if (m_ListView.totalRows > 0 && m_ListView.selectionChanged)
        {
            // 拖动更新
            if (m_ListView.draggedFrom != -1 && m_ListView.draggedTo != -1)
            {
                var tmp = m_MsgList[m_ListView.draggedFrom];
                m_MsgList[m_ListView.draggedFrom] = m_MsgList[m_ListView.row];
                m_MsgList[m_ListView.row]         = tmp;
            }
        }
    }
    private void OnGUI()
    {
        if (s_Styles == null)
        {
            s_Styles = new Styles();
        }
        m_ListView.totalRows = m_MsgList.Count;

        Event current = Event.current;

        EditorGUILayout.BeginVertical();
        GUIContent textContent = new GUIContent();

        foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, ListViewOptions.wantsExternalFiles, s_Styles.listBackgroundStyle))
        {
            if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 2)
            {
                Debug.Log(el.row);
            }
            if (current.type == EventType.Repaint)
            {
                textContent.text = GetRowText(el);

                // 交替显示不同背景色
                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                style.Draw(el.position, false, false, m_ListView.row == el.row, false);
                s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus);
            }
        }
        EditorGUILayout.EndVertical();

        {
            // 拖动文件
            if (m_ListView.fileNames != null)
            {
                m_MsgList.InsertRange(m_ListView.row, m_ListView.fileNames);
            }
        }
    }
Exemplo n.º 5
0
        void OnGUI()
        {
            Event e = Event.current;

            LoadIcons();
            LogEntries.wrapped.UpdateEntries();

            if (!m_HasUpdatedGuiStyles)
            {
                m_LineHeight   = Mathf.RoundToInt(Constants.ErrorStyle.lineHeight);
                m_BorderHeight = Constants.ErrorStyle.border.top + Constants.ErrorStyle.border.bottom;
                UpdateListView();
            }

            GUILayout.BeginHorizontal(Constants.Toolbar);

            if (GUILayout.Button(Constants.ClearLabel, Constants.MiniButton))
            {
                LogEntries.Clear();
                GUIUtility.keyboardControl = 0;
            }

            int currCount = LogEntries.wrapped.GetCount();

            if (m_ListView.totalRows != currCount && m_ListView.totalRows > 0)
            {
                // scroll bar was at the bottom?
                if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                {
                    m_ListView.scrollPos.y = currCount * RowHeight - ms_LVHeight;
                }
            }

            if (LogEntries.wrapped.searchFrame)
            {
                LogEntries.wrapped.searchFrame = false;
                int selectedIndex = LogEntries.wrapped.GetSelectedEntryIndex();
                if (selectedIndex != -1)
                {
                    int showIndex = selectedIndex + 1;
                    if (currCount > showIndex)
                    {
                        int showCount = ms_LVHeight / RowHeight;
                        showIndex = showIndex + showCount / 2;
                    }
                    m_ListView.scrollPos.y = showIndex * RowHeight - ms_LVHeight;
                }
            }

            EditorGUILayout.Space();

            bool wasCollapsed = LogEntries.wrapped.collapse;

            LogEntries.wrapped.collapse = GUILayout.Toggle(wasCollapsed, Constants.CollapseLabel, Constants.MiniButton);

            bool collapsedChanged = (wasCollapsed != LogEntries.wrapped.collapse);

            if (collapsedChanged)
            {
                // unselect if collapsed flag changed
                m_ListView.row = -1;

                // scroll to bottom
                m_ListView.scrollPos.y = LogEntries.wrapped.GetCount() * RowHeight;
            }

            SetFlag(ConsoleFlags.ClearOnPlay, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnPlay), Constants.ClearOnPlayLabel, Constants.MiniButton));
#if UNITY_2019_1_OR_NEWER
            SetFlag(ConsoleFlags.ClearOnBuild, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnBuild), Constants.ClearOnBuildLabel, Constants.MiniButton));
#endif
            SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPauseLabel, Constants.MiniButton));

#if UNITY_2018_3_OR_NEWER
            ConnectionGUILayout.AttachToPlayerDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown);
#endif

            EditorGUILayout.Space();

            if (m_DevBuild)
            {
                GUILayout.FlexibleSpace();
                SetFlag(ConsoleFlags.StopForAssert, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForAssert), Constants.StopForAssertLabel, Constants.MiniButton));
                SetFlag(ConsoleFlags.StopForError, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForError), Constants.StopForErrorLabel, Constants.MiniButton));
            }

            GUILayout.FlexibleSpace();

            // Search bar
            GUILayout.Space(4f);
            SearchField(e);

            int errorCount = 0, warningCount = 0, logCount = 0;
            LogEntries.wrapped.GetCountsByType(ref errorCount, ref warningCount, ref logCount);
            EditorGUI.BeginChangeCheck();
            bool setLogFlag     = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelLog), new GUIContent((logCount <= 999 ? logCount.ToString() : "999+"), logCount > 0 ? iconInfoSmall : iconInfoMono), Constants.MiniButton);
            bool setWarningFlag = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelWarning), new GUIContent((warningCount <= 999 ? warningCount.ToString() : "999+"), warningCount > 0 ? iconWarnSmall : iconWarnMono), Constants.MiniButton);
            bool setErrorFlag   = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButton);
            // Active entry index may no longer be valid
            if (EditorGUI.EndChangeCheck())
            {
            }

            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelLog, setLogFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelWarning, setWarningFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelError, setErrorFlag);

            if (GUILayout.Button(new GUIContent(errorCount > 0 ? iconFirstErrorSmall : iconFirstErrorMono, Constants.FirstErrorLabel), Constants.MiniButton))
            {
                int firstErrorIndex = LogEntries.wrapped.GetFirstErrorEntryIndex();
                if (firstErrorIndex != -1)
                {
                    SetActiveEntry(firstErrorIndex);
                    LogEntries.wrapped.searchFrame = true;
                }
            }

            GUILayout.EndHorizontal();

            SplitterGUILayout.BeginVerticalSplit(spl);
            int rowHeight = RowHeight;
            EditorGUIUtility.SetIconSize(new Vector2(rowHeight, rowHeight));
            GUIContent tempContent      = new GUIContent();
            int        id               = GUIUtility.GetControlID(0);
            int        rowDoubleClicked = -1;

            /////@TODO: Make Frame selected work with ListViewState
            using (new GettingLogEntriesScope(m_ListView))
            {
                int  selectedRow      = -1;
                bool openSelectedItem = false;
                bool collapsed        = LogEntries.wrapped.collapse;
                foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, Constants.Box))
                {
                    if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
                    {
                        m_ListView.row = el.row;
                        selectedRow    = el.row;
                        if (e.clickCount == 2)
                        {
                            openSelectedItem = true;
                        }
                    }
                    else if (e.type == EventType.Repaint)
                    {
                        int    mode           = 0;
                        int    entryCount     = 0;
                        int    searchIndex    = 0;
                        int    searchEndIndex = 0;
                        string text           = LogEntries.wrapped.GetEntryLinesAndFlagAndCount(el.row, ref mode, ref entryCount,
                                                                                                ref searchIndex, ref searchEndIndex);
                        ConsoleFlags flag       = (ConsoleFlags)mode;
                        bool         isSelected = LogEntries.wrapped.IsEntrySelected(el.row);

                        // Draw the background
                        GUIStyle s = el.row % 2 == 0 ? Constants.OddBackground : Constants.EvenBackground;
                        s.Draw(el.position, false, false, isSelected, false);

                        // Draw the icon
#if !UNITY_2017_3_OR_NEWER
                        if (Constants.LogStyleLineCount == 1)
                        {
                            Rect rt = el.position;
                            rt.x     += 6f;
                            rt.y     += 2f;
                            rt.width  = 16f;
                            rt.height = 16f;
                            GUI.DrawTexture(rt, GetIconForErrorMode(flag, false));
                        }
                        else
#endif
                        {
                            GUIStyle iconStyle = GetStyleForErrorMode(flag, true, Constants.LogStyleLineCount == 1);
                            iconStyle.Draw(el.position, false, false, isSelected, false);
                        }

                        // Draw the text
                        tempContent.text = text;
                        GUIStyle errorModeStyle = GetStyleForErrorMode(flag, false, Constants.LogStyleLineCount == 1);

                        if (string.IsNullOrEmpty(LogEntries.wrapped.searchString) || searchIndex == -1 || searchIndex >= text.Length)
                        {
                            errorModeStyle.Draw(el.position, tempContent, id, isSelected);
                        }
                        else
                        {
                            errorModeStyle.DrawWithTextSelection(el.position, tempContent, GUIUtility.keyboardControl, searchIndex, searchEndIndex);
                        }

                        if (collapsed)
                        {
                            Rect badgeRect = el.position;
                            tempContent.text = entryCount.ToString(CultureInfo.InvariantCulture);
                            Vector2 badgeSize = Constants.CountBadge.CalcSize(tempContent);
                            badgeRect.xMin  = badgeRect.xMax - badgeSize.x;
                            badgeRect.yMin += ((badgeRect.yMax - badgeRect.yMin) - badgeSize.y) * 0.5f;
                            badgeRect.x    -= 5f;
                            GUI.Label(badgeRect, tempContent, Constants.CountBadge);
                        }
                    }
                }

                if (selectedRow != -1)
                {
                    if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                    {
                        m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1;
                    }
                }

                // Make sure the selected entry is up to date
                if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
                {
                }
                else
                {
                    if (m_ListView.selectionChanged)
                    {
                        SetActiveEntry(m_ListView.row);
                    }
                }

                // Open entry using return key
                if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) && (e.keyCode == KeyCode.Return) && (m_ListView.row != 0))
                {
                    selectedRow      = m_ListView.row;
                    openSelectedItem = true;
                }

                if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
                {
                    ms_LVHeight = ListViewGUI.ilvState.rectHeight;
                }

                if (openSelectedItem)
                {
                    rowDoubleClicked = selectedRow;
                    e.Use();
                }

                if (selectedRow != -1)
                {
                    SetActiveEntry(selectedRow);
                }
            }

            // Prevent dead locking in EditorMonoConsole by delaying callbacks (which can log to the console) until after LogEntries.EndGettingEntries() has been
            // called (this releases the mutex in EditorMonoConsole so logging again is allowed). Fix for case 1081060.
            if (rowDoubleClicked != -1)
            {
                LogEntries.wrapped.StacktraceListView_RowGotDoubleClicked();
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);

            StacktraceListView(e, tempContent);

            SplitterGUILayout.EndVerticalSplit();

            // Copy & Paste selected item
            if ((e.type == EventType.ValidateCommand || e.type == EventType.ExecuteCommand) && e.commandName == "Copy")
            {
                if (e.type == EventType.ExecuteCommand)
                {
                    LogEntries.wrapped.StacktraceListView_CopyAll();
                }
                e.Use();
            }
        }
Exemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            //定义每一行的高度
            s_Styles.listItem.fixedHeight = 22f;

            if (false == IsDataInitFlag)
            {
                AllModelsLogic.GroupName.Clear();
                GroupFoldOutFlag.Clear();

                AllModelsLogic.GroupName.Add("Group0");
                GroupFoldOutFlag.Add(true);

                int GroupMaxNum = 0;
                for (int j = 0; j < GlobalVar._AllModelsLogic.GetModelList().Count; j++)
                {
                    if (GlobalVar._AllModelsLogic.GetModelList()[j].GroupNum > GroupMaxNum)
                    {
                        GroupMaxNum = GlobalVar._AllModelsLogic.GetModelList()[j].GroupNum;
                    }
                }
                for (int j = 1; j < GroupMaxNum + 1; j++)
                {
                    AllModelsLogic.GroupName.Add("Group" + j);
                    GroupFoldOutFlag.Add(false);
                }
                GroupCountChangeFlag = true;

                IsDataInitFlag = true;

                AllModelsLogic.NameDisplayModelList.Add("方式1");

                AllModelsLogic.MoveModelList.Add("直接飞走");                     //默认渐入渐出方式
            }
            Event current = Event.current;

            EditorGUILayout.BeginVertical();
            //根
            EditorGUILayout.BeginHorizontal();
            RootFoldOutFlag = EditorGUILayout.Foldout(RootFoldOutFlag, RootName);

            if (GUILayout.Button("上一步"))                   //点击上一步
            {
                GlobalVar._PlayerManager.OnPlayLastManager();
                System.Threading.Thread.Sleep(50);
            }
            if (GUILayout.Button("下一步"))                    //点击下一步
            {
                GlobalVar._PlayerManager.OnPlayNextManager();
                System.Threading.Thread.Sleep(50);
            }

            if (GUILayout.Button("添加组"))
            {
                AllModelsLogic.GroupName.Add("Group" + (AllModelsLogic.GroupName.Count));
                GroupFoldOutFlag.Add(true);
                GroupCountChangeFlag = true;
            }

            EditorGUILayout.EndHorizontal();
            if (RootFoldOutFlag)
            {
                if (GroupCountChangeFlag)
                {
                    Engine_ListView.Clear();
                    for (int i = 0; i < AllModelsLogic.GroupName.Count; i++)
                    {
                        ListViewState EngineView = new ListViewState();
                        Engine_ListView.Add(EngineView);
                    }
                    GroupCountChangeFlag = false;
                }

                GlobalVar._AllModelsLogic.GetModelList().Sort();            //排序,先按组,后按ID

                int rowNum = -1;
                rowNum = GetSelectRow();

                for (int i = 0; i < AllModelsLogic.GroupName.Count; i++)
                {
                    //相同的组,放入相同的List中,便于ListView显示
                    List <ModelClass> listTemp = new List <ModelClass>();
                    for (int j = 0; j < GlobalVar._AllModelsLogic.GetModelList().Count; j++)
                    {
                        if (AllModelsLogic.GroupName[i] == "Group" + GlobalVar._AllModelsLogic.GetModelList()[j].GroupNum)
                        {
                            listTemp.Add(GlobalVar._AllModelsLogic.GetModelList()[j]);
                            GlobalVar._AllModelsLogic.GetModelList()[j].PlayOrderId = listTemp.Count;
                        }
                    }

                    Engine_ListView[i].rowHeight = 22;
                    Engine_ListView[i].totalRows = listTemp.Count;
                    if (rowNum >= 0 && (rowNum + 1 <= Engine_ListView[i].totalRows))
                    {
                        Engine_ListView[i].row = rowNum;
                        rowNum = -1;
                    }
                    else
                    {
                        rowNum = rowNum - Engine_ListView[i].totalRows;
                    }
                    EditorGUILayout.BeginVertical();

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(10);

                    EditorGUILayout.BeginVertical();

                    //每个Group内容
                    GroupFoldOutFlag[i] = EditorGUILayout.Foldout(GroupFoldOutFlag[i], AllModelsLogic.GroupName[i] + "    (共有" + Engine_ListView[i].totalRows + "个零件模型)");
                    if (GroupFoldOutFlag[i])
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.SelectableLabel("", GUILayout.Width(20), GUILayout.Height(25));
                        EditorGUILayout.SelectableLabel("零件名称", GUILayout.Width(80), GUILayout.Height(25));
                        EditorGUILayout.SelectableLabel("渐入渐出方式", GUILayout.Width(100), GUILayout.Height(25));
                        EditorGUILayout.SelectableLabel("名称显示方式", GUILayout.Width(100), GUILayout.Height(25));
                        EditorGUILayout.SelectableLabel("所在的组", GUILayout.Width(100), GUILayout.Height(25));
                        EditorGUILayout.SelectableLabel("修改播放次序", GUILayout.Width(100), GUILayout.Height(25));
                        EditorGUILayout.EndHorizontal();

                        Rect       playNumRect          = new Rect();
                        GUIContent textContent          = new GUIContent();
                        Rect       moveModelRect        = new Rect();
                        Rect       nameDisplayModelRect = new Rect();
                        Rect       groupNameRect        = new Rect();
                        Rect       upNameRect           = new Rect();
                        Rect       downNameRect         = new Rect();
                        foreach (ListViewElement el in ListViewGUI.ListView(Engine_ListView[i], ListViewOptions.wantsReordering, m_ColWidths, "", s_Styles.listBackgroundStyle, GUILayout.Height((Engine_ListView[i].totalRows > 10) ? (200) : (Engine_ListView[i].totalRows * 22))))
                        {
                            playNumRect        = el.position;
                            playNumRect.x     += playNumRect.width - 480;
                            playNumRect.y     += 2;
                            playNumRect.width  = 70;
                            playNumRect.height = 18;

                            moveModelRect        = el.position;
                            moveModelRect.x     += moveModelRect.width - 400;
                            moveModelRect.y     += 2;
                            moveModelRect.width  = 60;
                            moveModelRect.height = 18;

                            nameDisplayModelRect        = el.position;
                            nameDisplayModelRect.x     += nameDisplayModelRect.width - 290;
                            nameDisplayModelRect.y     += 2;
                            nameDisplayModelRect.width  = 50;
                            nameDisplayModelRect.height = 18;

                            groupNameRect        = el.position;
                            groupNameRect.x     += groupNameRect.width - 195;
                            groupNameRect.y     += 2;
                            groupNameRect.width  = 60;
                            groupNameRect.height = 18;

                            upNameRect        = el.position;
                            upNameRect.x     += upNameRect.width - 90;
                            upNameRect.y     += 2;
                            upNameRect.width  = 30;
                            upNameRect.height = 18;

                            downNameRect        = el.position;
                            downNameRect.x     += downNameRect.width - 50;
                            downNameRect.y     += 2;
                            downNameRect.width  = 30;
                            downNameRect.height = 18;

                            if (current.type == EventType.mouseDown && current.button == 0 && el.position.Contains(current.mousePosition))
                            {
                                if (current.clickCount == 2)
                                {
                                    //双击跳转到相应的物体上
                                    Selection.activeGameObject = GameObject.Find(GetRowText(listTemp, el));
                                }
                                else if (current.clickCount == 1)
                                {
                                    EditorGUIUtility.PingObject(GameObject.Find(GetRowText(listTemp, el)));
                                    InspectorSelectGameobject = GameObject.Find(GetRowText(listTemp, el));
                                    SetSelectRow(GameObject.Find(GetRowText(listTemp, el)));
                                }
                            }


                            if (current.type == EventType.Repaint)
                            {
                                textContent.text = GetRowText(listTemp, el);
                                // 交替显示不同背景色
                                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                                style.Draw(el.position, false, true, Engine_ListView[i].row == el.row, false);
                            }

                            EditorGUI.LabelField(el.position, el.row.ToString());

                            EditorGUI.LabelField(playNumRect, textContent);

                            listTemp[el.row].MoveModel = EditorGUI.Popup(moveModelRect, listTemp[el.row].MoveModel, AllModelsLogic.MoveModelList.ToArray());

                            listTemp[el.row].NameDisplay = EditorGUI.Popup(nameDisplayModelRect, listTemp[el.row].NameDisplay, AllModelsLogic.NameDisplayModelList.ToArray());

                            listTemp[el.row].GroupNum = EditorGUI.Popup(groupNameRect, listTemp[el.row].GroupNum, AllModelsLogic.GroupName.ToArray());

                            if (GUI.Button(upNameRect, "↑") && Engine_ListView[i].totalRows > 0 && el.row > 0)
                            {
                                var tmpName = listTemp[el.row - 1].Name;
                                listTemp[el.row - 1].Name = listTemp[el.row].Name;
                                listTemp[el.row].Name     = tmpName;

                                var tmpPopueInt2 = listTemp[el.row - 1].MoveModel;
                                listTemp[el.row - 1].MoveModel = listTemp[el.row].MoveModel;
                                listTemp[el.row].MoveModel     = tmpPopueInt2;

                                var tmpPopueInt3 = listTemp[el.row - 1].NameDisplay;
                                listTemp[el.row - 1].NameDisplay = listTemp[el.row].NameDisplay;
                                listTemp[el.row].NameDisplay     = tmpPopueInt3;

                                var tmpPopueInt5 = listTemp[el.row - 1].GroupNum;
                                listTemp[el.row - 1].GroupNum = listTemp[el.row].GroupNum;
                                listTemp[el.row].GroupNum     = tmpPopueInt5;

                                Engine_ListView[i].row = el.row - 1;
                            }

                            if (GUI.Button(downNameRect, "↓") && Engine_ListView[i].totalRows > 0)
                            {
                                var tmpName = listTemp[el.row + 1].Name;
                                listTemp[el.row + 1].Name = listTemp[el.row].Name;
                                listTemp[el.row].Name     = tmpName;

                                var tmpPopueInt2 = listTemp[el.row + 1].MoveModel;
                                listTemp[el.row + 1].MoveModel = listTemp[el.row].MoveModel;
                                listTemp[el.row].MoveModel     = tmpPopueInt2;

                                var tmpPopueInt3 = listTemp[el.row + 1].NameDisplay;
                                listTemp[el.row + 1].NameDisplay = listTemp[el.row].NameDisplay;
                                listTemp[el.row].NameDisplay     = tmpPopueInt3;

                                var tmpPopueInt5 = listTemp[el.row + 1].GroupNum;
                                listTemp[el.row + 1].GroupNum = listTemp[el.row].GroupNum;
                                listTemp[el.row].GroupNum     = tmpPopueInt5;

                                Engine_ListView[i].row = el.row + 1;
                            }
                        }

                        if (Engine_ListView[i].totalRows > 0 && Engine_ListView[i].selectionChanged)
                        {
                            // 拖动更新
                            if (Engine_ListView[i].draggedFrom != -1 && Engine_ListView[i].draggedTo != -1)
                            {
                                var tmpName = listTemp[Engine_ListView[i].draggedFrom].Name;
                                listTemp[Engine_ListView[i].draggedFrom].Name = listTemp[Engine_ListView[i].row].Name;
                                listTemp[Engine_ListView[i].row].Name         = tmpName;

                                var tmpPopueInt2 = listTemp[Engine_ListView[i].draggedFrom].MoveModel;
                                listTemp[Engine_ListView[i].draggedFrom].MoveModel = listTemp[Engine_ListView[i].row].MoveModel;
                                listTemp[Engine_ListView[i].row].MoveModel         = tmpPopueInt2;

                                var tmpPopueInt3 = listTemp[Engine_ListView[i].draggedFrom].NameDisplay;
                                listTemp[Engine_ListView[i].draggedFrom].NameDisplay = listTemp[Engine_ListView[i].row].NameDisplay;
                                listTemp[Engine_ListView[i].row].NameDisplay         = tmpPopueInt3;

                                var tmpPopueInt5 = listTemp[Engine_ListView[i].draggedFrom].GroupNum;
                                listTemp[Engine_ListView[i].draggedFrom].GroupNum = listTemp[Engine_ListView[i].row].GroupNum;
                                listTemp[Engine_ListView[i].row].GroupNum         = tmpPopueInt5;
                            }
                        }
                    }
                    EditorGUILayout.EndVertical();

                    //第一组永远存在,不能被删除
                    if ("Group0" != AllModelsLogic.GroupName[i] && GUILayout.Button("删除组"))
                    {
                        for (int j = 0; j < GlobalVar._AllModelsLogic.GetModelList().Count; j++)
                        {
                            if (i <= GlobalVar._AllModelsLogic.GetModelList()[j].GroupNum)
                            {
                                GlobalVar._AllModelsLogic.GetModelList()[j].GroupNum -= 1;
                            }
                        }
                        AllModelsLogic.GroupName.RemoveAt(i);
                        GroupFoldOutFlag.RemoveAt(i);
                        GroupCountChangeFlag = true;
                        IsDataInitFlag       = false;
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 7
0
    // UI: object list view
    private void _ObjectListViewEditor()
    {
        // Object List Section:
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Object Lists:", m_labelStyle);

        if (s_Styles == null)
        {
            s_Styles = new Styles();
        }
        m_ListView.totalRows = ObjectLists.Instance.objectList.Count;
        Event current = Event.current;

        GUIContent textContent = new GUIContent();

        foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, s_Styles.listBackgroundStyle))
        {
            if (current.type == EventType.MouseDown && current.button == 0 && el.position.Contains(current.mousePosition) && current.clickCount == 1)
            {
                Debug.Log(el.row);
                m_selected = ObjectLists.Instance.objectList[el.row];
                if (el.row != m_ListView.row)
                {
                    m_dirty = true;
                }
            }
            if (current.type == EventType.Repaint)
            {
                textContent.text = ObjectLists.Instance.objectList[el.row].name;

                GUIStyle style = (el.row % 2 != 0) ? s_Styles.listItemBackground2 : s_Styles.listItemBackground;
                style.Draw(el.position, false, false, m_ListView.row == el.row, false);
                s_Styles.listItem.Draw(el.position, textContent, false, false, m_ListView.row == el.row, m_Focus);
            }
        }

        // add object button
        if (GUILayout.Button("Add Object"))
        {
            TestObject item = new TestObject();
            item.name = "TestObject";
            ObjectLists.Instance.objectList.Add(item);
            m_dirty = true;
        }

        // delete object button
        GUI.color = Color.red;
        if (GUILayout.Button("Delete Object") && m_selected != null)
        {
            ObjectLists.Instance.objectList.Remove(m_selected);

            m_selected = null;

            m_ListView.row = -1;

            m_dirty = true;
        }
        GUI.color = m_orgColor;

        EditorGUILayout.EndVertical();
        // end List Section
    }