예제 #1
0
    /// <summary>
    /// 绘制文件目录GUI
    /// </summary>
    /// <param name="control">文件信息</param>
    /// <param name="direType">显示文件夹或全部目录</param>
    /// <param name="selectCallback">选择一个文件回调</param>
    /// <param name="isShowChoose">是否打开勾选文件</param>
    /// <param name="chooseCallBack">勾选文件回调</param>
    public static void DrawFileDirectory(TreeModelController <FileData> control, ShowFileDirectoryType direType = ShowFileDirectoryType.ShowAllFile, string[] showEndsWith = null, CallBack <FileData> selectCallback = null, bool isShowChoose = false, CallBack <FileData> chooseCallBack = null)
    {
        GUI.enabled = true;
        EditorGUIUtility.SetIconSize(Vector2.one * 16);
        control.TreeForeachNode((data) =>
        {
            if (direType == ShowFileDirectoryType.OnlyDirectory)
            {
                if (data.isDirectory)
                {
                    DrawGUIData(control, data, direType, selectCallback, isShowChoose, chooseCallBack);
                    if (!data.isSelected)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (data.isDirectory && !data.isSelected)
                {
                    DrawGUIData(control, data, direType, selectCallback, isShowChoose, chooseCallBack);
                    return(false);
                }
                if (showEndsWith != null)
                {
                    if (!data.isDirectory)
                    {
                        if (OtherUtils.ArrayContains(showEndsWith, Path.GetExtension(data.relativeRootPath)))
                        {
                            DrawGUIData(control, data, direType, selectCallback, isShowChoose, chooseCallBack);
                        }
                        return(true);
                    }
                }

                DrawGUIData(control, data, direType, selectCallback, isShowChoose, chooseCallBack);
            }
            return(true);
        });
    }
예제 #2
0
    static void DrawGUIData(TreeModelController <FileData> control, FileData data, ShowFileDirectoryType direType = ShowFileDirectoryType.ShowAllFile, CallBack <FileData> selectCallback = null, bool isShowChoose = false, CallBack <FileData> chooseCallBack = null)
    {
        GUIStyle style = "Label";

        style.richText = true;
        Rect rt = GUILayoutUtility.GetRect(data.content, style);

        if (data == selectData)
        {
            EditorGUI.DrawRect(rt, Color.gray);
        }
        rt.x += (24 * data.Deep);

        if (data.isDirectory)
        {
            Rect rt1 = new Rect(rt.x - 12, rt.y, 20, rt.height);
            if (direType == ShowFileDirectoryType.OnlyDirectory)
            {
                if (HaveChildDirectory(control, data))
                {
                    data.isSelected = EditorGUI.Foldout(rt1, data.isSelected, "");
                }
            }
            else
            {
                data.isSelected = EditorGUI.Foldout(rt1, data.isSelected, "");
            }
        }
        if (isShowChoose)
        {
            // rt.x += 20;
            Rect rt1 = new Rect(rt.x - 13, rt.y, 20, rt.height);
            if (data.isDirectory)
            {
                if (direType == ShowFileDirectoryType.OnlyDirectory)
                {
                    if (HaveChildDirectory(control, data))
                    {
                        rt1.x -= 13;
                    }
                }
                else
                {
                    rt1.x -= 13;
                }
            }
            bool oldChoose = data.isChoose;
            data.isChoose = EditorGUI.ToggleLeft(rt1, "", data.isChoose);
            if (data.isChoose != oldChoose)
            {
                if (chooseCallBack != null)
                {
                    chooseCallBack(data);
                }
            }
        }
        if (GUI.Button(rt, data.content, style))
        {
            //  data.isSelected = !data.isSelected;
            selectData = data;
            if (selectCallback != null)
            {
                selectCallback(data);
            }
        }
    }