Beispiel #1
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();
        }
Beispiel #2
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
    }