Exemplo n.º 1
0
    void RenderLayoutList()
    {
        EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true));

        Rect treeRect = EditorGUILayout.BeginVertical(LayoutEditorGUIStyle.panelBox, GUILayout.ExpandHeight(true));

        if (layoutTree != null)
        {
            layoutTree.Draw(treeRect, this);
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginHorizontal();

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("导入"))
        {
            if (m_layout_mng.CurEditLayout == null)
            {
                EditorUtility.DisplayDialog("", "请先打开一个layout文件!", "确定");
                return;
            }

            string layout = LayoutTool.OpenLayoutDialog();

            if (!string.IsNullOrEmpty(layout))
            {
                m_layout_mng.ImportLayout(layout);
                m_layout_mng.SetLayoutVisible(m_layout_mng.LayoutCount - 1, true);
                ResetLayoutTree();

                RequestRepaint();
            }
        }
        if (GUILayout.Button("移除"))
        {
            List <TreeNode> selList = layoutTree.GetSelectedNodes();

            bool hasEdit = false;
            foreach (TreeNode node in selList)
            {
                if (node.ToggleList["编辑"])
                {
                    hasEdit = true;
                    break;
                }
            }

            if (!hasEdit && EditorUtility.DisplayDialog("移除layout", "确认要移除选中的layout?", "确认", "取消"))
            {
                foreach (TreeNode node in selList)
                {
                    layoutTree.RemoveRootNode(node);
                    m_layout_mng.RemoveLayout((int)node.DataKey);
                }

                ResetLayoutTree();
                RequestRepaint();
            }
        }
        GUILayout.FlexibleSpace();

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
Exemplo n.º 2
0
    void RenderToolBar()
    {
        Layout cur_layout = m_layout_mng.CurEditLayout;

        GUILayout.Label("版本号:" + ConfigTool.Instance.version);
        if (cur_layout == null)
        {
            GUILayout.Label("请打开layout文件来编辑。");
        }
        else
        {
            GUILayout.Label(cur_layout.FileName + (cur_layout.Dirty ? " *" : ""));
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("打开"))
        {
            int res = 0;
            if (cur_layout != null && m_layout_mng.CurEditLayout.Dirty)
            {
                res = EditorUtility.DisplayDialogComplex("", "当前编辑的layout已被修改,是否保存?", "是", "否", "取消");
                switch (res)
                {
                // 是
                case 0:
                    if (cur_layout != null)
                    {
                        cur_layout.Save();
                    }

                    break;

                // 否
                case 1:
                    break;

                // 取消
                case 2:
                    break;

                default:
                    break;
                }
            }
            if (res != 2)
            {
                string layout = LayoutTool.OpenLayoutDialog();

                if (!string.IsNullOrEmpty(layout))
                {
                    ClearUndos();

                    m_layout_mng.Clear();

                    /*
                     * if (res == 1)
                     *  m_layout_mng.CurEditLayout.Reload();*/

                    //m_layout_mng.RemoveLayout(1);
                    m_layout_mng.ImportLayout(layout);
                    m_layout_mng.SetCurEditLayout(m_layout_mng.LayoutCount - 1);
                    m_layout_mng.SetLayoutVisible(m_layout_mng.LayoutCount - 1, true);
                    ResetLayoutTree();
                    ResetUITree();

                    RequestRepaint();
                }
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.Dirty);
        if (GUILayout.Button("保存"))
        {
            if (cur_layout != null && m_view.CheckResolutionBeforeSave())
            {
                cur_layout.Save();
            }
            //Debug.Log("counter:" + cmdCounter.Cur + "  cur:" + cmdCur);
        }
        GUI.enabled = true;
        if (GUILayout.Button("设置背景图"))
        {
            string file = LayoutTool.OpenBackImage();

            if (!string.IsNullOrEmpty(file))
            {
                m_view.BackTexture = file;
            }
        }
        if (GUILayout.Button("清除背景图"))
        {
            m_view.BackTexture = "";
        }
        GUILayout.Label("背景颜色");
        m_view.BackColor  = EditorGUILayout.ColorField(m_view.BackColor);
        m_view.ShowBorder = GUILayout.Toggle(m_view.ShowBorder, "显示边框");
        GUI.enabled       = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignLeft));
        if (GUILayout.Button("左对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignLeft);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignVCenter));
        if (GUILayout.Button("纵向居中对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignVCenter);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignRight));
        if (GUILayout.Button("右对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignRight);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignTop));
        if (GUILayout.Button("顶对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignTop);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignHCenter));
        if (GUILayout.Button("横向居中对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignHCenter);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_AlignBottom));
        if (GUILayout.Button("底对齐"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_AlignBottom);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameSize));
        if (GUILayout.Button("使大小相同"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_SameSize);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameXSpace));
        if (GUILayout.Button("使x间距相同"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_SameXSpace);
            }
        }
        GUI.enabled = (cur_layout != null && cur_layout.ValidFormat(Layout.FormatType.FT_SameYSpace));
        if (GUILayout.Button("使y间距相同"))
        {
            if (cur_layout != null)
            {
                cur_layout.Format(Layout.FormatType.FT_SameYSpace);
            }
        }
        GUI.enabled = (cur_layout != null && !m_view.NormalCamera);
        if (GUILayout.Button("重置相机"))
        {
            m_view.ResetCamera();
        }
        GUI.enabled = (cur_layout != null);
        if (GUILayout.Button("调整分辨率"))
        {
            ResDialog dlg = EditorWindow.GetWindow <ResDialog>(false, "选择分辨率", true);
            dlg.mainview = m_view;
        }
        m_view.ShowBoxCollider = GUILayout.Toggle(m_view.ShowBoxCollider, "显示碰撞盒边框");

        GUI.enabled = true;
        if (GUILayout.Button("使用文档"))
        {
            Help.BrowseURL(ConfigTool.Instance.help_url);
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
    }