Beispiel #1
0
    private void GetOneTreeItemData(TreeItem treeItem, List <TreeItemData> buffer)
    {
        if (treeItem.BeFolder)
        {
            TreeFolder _treeFolder = treeItem as TreeFolder;
            //buffer.PutBool (_treeFolder.BeFolder);//是否是folder
            //buffer.PutString (_treeFolder.Name);//节点名称
            List <TreeItem> _ItemList = _treeFolder.ItemList;
            //buffer.PutInt (_ItemList.Count);//直接子节点数

            for (int i = 0; i < _ItemList.Count; i++)
            {
                TreeItem item = _ItemList [i];
                GetOneTreeItemData(item, buffer);
            }
        }
        else
        {
            TreeItemData tempData = new TreeItemData();
            tempData.TreeItemID   = treeItem.TreeItemID;
            tempData.TreeItemName = treeItem.Name;
            buffer.Add(tempData);

            //buffer.PutBool (treeItem.BeFolder);//是否是folder
            //buffer.PutString (treeItem.Name);//节点名称
            //buffer.PutString(treeItem.TreeItemID);//数据索引ID
        }
    }
Beispiel #2
0
    public void CreateMenu(TreeFolder menuListFolder)
    {
        if (null != FolderRightMenu)
        {
            return;
        }
        Dictionary <string, Listener> dic = new Dictionary <string, Listener> ();

        dic.Add("创建文件夹", menuListFolder.AddFolder);
        if (!BeRootFolder)
        {
            dic.Add("删除文件夹", menuListFolder.DelFolder);
        }
        else
        {
            Listener callback = () => {
                GEditorDataMgr.GenerateGameData(Name);
            };

            dic.Add("导出" + Name + "数据", callback);
        }
        dic.Add("创建文件", menuListFolder.AddItem);
        dic.Add("重命名", menuListFolder.ReName);
        dic.Add("黏贴", menuListFolder.Paste);
        FolderRightMenu = Menu.Generate(dic, "FolderMenu");
        FolderRightMenu.ItemDic["黏贴"].interactable = false;//默认禁用黏贴
    }
Beispiel #3
0
    /// <summary>
    /// 使用数据创建Tree
    /// </summary>
    public void CreateByData(string treeName, RectTransform parentTrm, RectTransform treeRootTrm, float offx, float offy, byte[] data)
    {
        Name = treeName;
        IoBuffer ib = new IoBuffer();

        ib.PutBytes(data);

        bool   bFolder  = ib.GetBool();     //这里第一个节点一定是根节点,但是还是按正常数据读下
        string name     = ib.GetString();
        int    listSize = ib.GetInt();

        //VLog.I("TreeContainer","CreateByData","bFolder:"+bFolder+" name:"+name+" listSize:"+listSize);

        //这里需要创建
        TreeRootTrm = treeRootTrm;
        RootFolder  = TreeFolder.CreateRootFolder(treeName, parentTrm, this, offx, offy);


        for (int i = 0; i < listSize; i++)
        {
            //CreateOneItem(ib);
            bFolder = ib.GetBool();

            if (bFolder)
            {
                RootFolder.AddFolderByData(ib);
            }
            else
            {
                RootFolder.AddItemByData(ib);
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// 使用外部数据填充增加folder
    /// </summary>
    /// <param name="ib">Ib.</param>
    public void AddFolderByData(IoBuffer ib)
    {
        bool   bFolder  = false;
        string name     = ib.GetString();
        int    listSize = ib.GetInt();

        if (!BeFolderOpen)
        {
            OpenFolder();
        }
        TreeFolder curTreeFolder = TreeFolder.CreateSubFolder(name, this, MyTreeContainer);


        for (int i = 0; i < listSize; i++)
        {
            //CreateOneItem(ib);
            bFolder = ib.GetBool();

            if (bFolder)
            {
                curTreeFolder.AddFolderByData(ib);
            }
            else
            {
                curTreeFolder.AddItemByData(ib);
            }
        }
    }
Beispiel #5
0
 /// <summary>
 /// 创建可折叠菜单列表
 /// </summary>
 /// <param name="name">Name.</param>
 /// <param name="parentTrm">Parent trm.</param>
 /// <param name="offx">Offx.</param>
 /// <param name="offy">Offy.</param>
 public void Create(string treeName, RectTransform parentTrm, RectTransform treeRootTrm, float offx, float offy)
 {
     Name        = treeName;
     TreeRootTrm = treeRootTrm;
     RootFolder  = TreeFolder.CreateRootFolder(treeName, parentTrm, this, offx, offy);
     //读取menu文件夹文件结构
     //设置位置
 }
Beispiel #6
0
    /// <summary>
    /// 创建根文件夹
    /// </summary>
    /// <returns>The root.</returns>
    /// <param name="name">Name.</param>
    /// <param name="parentTrm">Parent trm.</param>
    /// <param name="offx">Offx.</param>
    /// <param name="offy">Offy.</param>
    public static TreeFolder CreateRootFolder(string rootFolderName, RectTransform parentTrm, TreeContainer menuList, float offx, float offy)
    {
        TreeFolder folder = TreeFolder.Create(rootFolderName, parentTrm, menuList);

        folder.ParentFolder = null;
        folder.BeRootFolder = true;
        //设置PosX,PosY
        folder._RectTransform.anchoredPosition = new Vector2(offx - UIEnum.FolderBtnW, offy);
        //根目录去掉+-号显示
        folder.FolderBtn.gameObject.SetActive(false);
        //创建菜单
        folder.CreateMenu(folder);
        return(folder);
    }
Beispiel #7
0
 /// <summary>
 /// 新增文件夹
 /// </summary>
 public void AddFolder()
 {
     InputTextDialog.Open(
         delegate(byte[] bts)
     {
         //创建文件夹
         IoBuffer ib = new IoBuffer();
         ib.PutBytes(bts);
         string inputFieldText = ib.GetString();
         if (!BeFolderOpen)
         {
             OpenFolder();                                 //没打开的先打开再创建,否则位置错乱
         }
         TreeFolder.CreateSubFolder(inputFieldText, this, MyTreeContainer);
     }
         );
 }
Beispiel #8
0
    /// <summary>
    /// 新建,黏贴插入操作
    /// </summary>
    /// <param name="index">Index.</param>
    /// <param name="itemName">Item name.</param>
    /// <param name="parentFolder">Parent folder.</param>
    /// <param name="menuList">Menu list.</param>
    private TreeItem InsertItem(int index, string itemName, TreeFolder parentFolder, TreeContainer menuList)
    {
        //实例化文件夹
        GameObject go = GameObject.Instantiate(Resources.Load("Prefabs/TreeItem")) as GameObject;

        go.name = itemName;
        TreeItem item = go.GetComponent <TreeItem>();

        item.MyTreeContainer = menuList;
        item.BeFolder        = false;
        item.Name            = itemName;
        go.transform.SetParent(parentFolder.SubRootRectTransform as Transform);
        item._RectTransform           = go.GetComponent <RectTransform>();
        item._RectTransform.pivot     = new Vector2(0, 1);
        item._RectTransform.anchorMax = new Vector2(0, 1);
        item._RectTransform.anchorMin = new Vector2(0, 1);

        item.ItemNameText.text     = itemName;
        item.ItemNameText.fontSize = UIEnum.FontSize;
        var   textRt = item.ItemNameText.gameObject.GetComponent <RectTransform>();
        float w      = Tools.GetStringW(item.ItemNameText.text, UIEnum.FontSize);

        textRt.sizeDelta = new Vector2(w, UIEnum.ItmeH);

        //重新设置下Folder的边框宽度
        float w1 = UIEnum.ItemImageW + w;

        item._RectTransform.sizeDelta = new Vector2(w1, UIEnum.ItemH);

        item.ParentFolder = parentFolder;

        //这里这句还是要注意点,文件夹和item混合插入应该会出问题,不过目前没这种需求
        float h = (index + 1) * UIEnum.ItemH;

        item._RectTransform.anchoredPosition = new Vector2(UIEnum.FolderBtnW * 2 + 4, -h);
        item.CreateMenu(item);

        parentFolder.ItemList.Insert(index, item);
        parentFolder.RefreshItemNum();
        //新建文件夹后通知上级进行重新排序,比如rootFolder下有10个subFolder,在第二个subFolder下新建,那么后面所有subFolder都要重排
        //这里注意下ui坐标系是左下是0,0所以负值是向下移动
        parentFolder.ParentYOrder(-UIEnum.ItemH, index);

        return(item);
    }
Beispiel #9
0
    /// <summary>
    /// 计算子Item相对与父folder的相对高度H
    ///
    /// TODO 使用情景需要补充说明
    ///
    /// 传入folder在父folder中的序号index
    /// 返回从父folder到这个序号index之间实际的h
    /// 需要计算内部每个文件夹是否打开,总共暂用了多少位置
    /// </summary>
    /// <returns>The H from current h.</returns>
    /// <param name="index">item在文件夹中的index</param>
    public float GetFrontH(int subItemIndexInParentFolder)
    {
        float h = 0;

        for (int i = 0; i < subItemIndexInParentFolder; i++)
        {
            bool bFolder = ItemList [i].BeFolder;
            if (bFolder)
            {
                TreeFolder folder = ItemList [i] as TreeFolder;
                h += folder.CurFolderH;
            }
            else
            {
                h += UIEnum.ItemH;
            }
        }
        return(h);
    }
Beispiel #10
0
    public static TreeFolder Create(string folderName, RectTransform parentRectTrm, TreeContainer menuList)
    {
        //实例化文件夹
        GameObject go = GameObject.Instantiate(Resources.Load("Prefabs/TreeFolder")) as GameObject;

        go.name = folderName;
        TreeFolder folder = go.GetComponent <TreeFolder>();

        folder.MyTreeContainer = menuList;
        folder.BeFolder        = true;
        folder.Name            = folderName;
        go.transform.SetParent(parentRectTrm as Transform);
        folder._RectTransform           = go.GetComponent <RectTransform>();
        folder._RectTransform.pivot     = new Vector2(0, 1);
        folder._RectTransform.anchorMax = new Vector2(0, 1);
        folder._RectTransform.anchorMin = new Vector2(0, 1);

        //设置下文件夹文字及大小
        StringBuilder sb = new StringBuilder();

        sb.Append(folderName);
        sb.Append('(');
        sb.Append(folder.SubItemNums);
        sb.Append(')');
        folder.ItemNameText.text     = sb.ToString();
        folder.ItemNameText.fontSize = UIEnum.FontSize;
        var   textRt = folder.ItemNameText.gameObject.GetComponent <RectTransform>();
        float w      = Tools.GetStringW(folder.ItemNameText.text, UIEnum.FontSize);

        textRt.sizeDelta = new Vector2(w, UIEnum.ItmeH);

        //重新设置下Folder的边框宽度
        float w1 = UIEnum.FolderBtnW + UIEnum.FolderImageW + w;

        folder._RectTransform.sizeDelta = new Vector2(w1, UIEnum.FolderH);

        //设置+-打开关闭文件夹button事件
        folder.FolderBtn.onClick.AddListener(folder.OnButtonClick);



        return(folder);
    }
Beispiel #11
0
    /// <summary>
    /// 创建子文件夹
    /// 不需要加入xy偏移量,因为这个偏移量是固定的
    /// </summary>
    /// <param name="name">Name.</param>
    /// <param name="parentTrm">Parent trm.</param>
    public static TreeFolder CreateSubFolder(string folderName, TreeFolder parentFolder, TreeContainer menuList)
    {
        //添加文件夹时,如果父文件夹没有打开,先打开再添加
        if (!parentFolder.BeFolderOpen)
        {
            parentFolder.BeFolderOpen = true;
        }

        var folder = TreeFolder.Create(folderName, parentFolder.SubRootRectTransform, menuList);

        folder.ParentFolder = parentFolder;
        folder.BeRootFolder = false;

        //这里计算的是相对父folder的位置
        //float h = (parentFolder.SubItemNums + 1) * MenuListFolder.FolderH;
        float h = parentFolder.CurFolderH;

        folder._RectTransform.anchoredPosition = new Vector2(UIEnum.FolderBtnW, -h);
        folder.CreateMenu(folder);
        parentFolder.ItemList.Add(folder);

        //新建文件夹后通知上级进行重新排序,比如rootFolder下有10个subFolder,在第二个subFolder下新建,那么后面所有subFolder都要重排
        //这里注意下ui坐标系是左下是0,0所以负值是向下移动
        parentFolder.ParentYOrder(-UIEnum.FolderH, folder.IndexInParentFolder);


        //刷新下MenuList的边框宽,用于刷新MenuList滚动区域,item距离Menulist左边距离+两个图标间隔+4(文字和图标间隔)+w1(文字长度)
        if (!folder.BeRootFolder)
        {
            var   textRt = folder.ItemNameText.gameObject.GetComponent <RectTransform>();
            float w      = Tools.GetStringW(folder.ItemNameText.text, UIEnum.FontSize);
            float w1     = UIEnum.FolderBtnW + UIEnum.FolderImageW + w;
            float _w     = folder.CurItemLeftOffset + UIEnum.ItemImageW * 2 + 4 + w1;
            menuList.SetTreeW(_w);
            menuList.RefreshTreeArea();
        }

        return(folder);
    }
Beispiel #12
0
    /// <summary>
    /// 处理1个tree的导出
    ///
    /// </summary>
    /// <param name="treeItem">Tree item.</param>
    /// <param name="ioBuffer">Io buffer.</param>
    private static void ProcessOneTreeItem(TreeItem treeItem)
    {
        if (treeItem.BeFolder)
        {
            TreeFolder _treeFolder = treeItem as TreeFolder;
            ioBuffer4TreeCfgExport.PutBool(_treeFolder.BeFolder);       //是否是folder
            ioBuffer4TreeCfgExport.PutString(_treeFolder.Name);         //节点名称
            List <TreeItem> _ItemList = _treeFolder.ItemList;
            ioBuffer4TreeCfgExport.PutInt(_ItemList.Count);             //直接子节点数

            for (int i = 0; i < _ItemList.Count; i++)
            {
                TreeItem item = _ItemList [i];
                ProcessOneTreeItem(item);
            }
        }
        else
        {
            ioBuffer4TreeCfgExport.PutBool(treeItem.BeFolder);           //是否是folder
            ioBuffer4TreeCfgExport.PutString(treeItem.Name);             //节点名称
            ioBuffer4TreeCfgExport.PutString(treeItem.TreeItemID);       //数据索引ID
        }
    }
Beispiel #13
0
    /// <summary>
    /// 这个方法只有从folder右键创建item时调用
    /// 其他地方用InsertItem
    /// </summary>
    /// <param name="itemName">Item name.</param>
    /// <param name="parentFolder">Parent folder.</param>
    /// <param name="menuList">Menu list.</param>
    public static TreeItem Create(string itemName, TreeFolder parentFolder, TreeContainer treeContainer)
    {
        //添加文件夹时,如果父文件夹没有打开,先打开再添加
        if (!parentFolder.BeFolderOpen)
        {
            parentFolder.BeFolderOpen = true;
        }

        //实例化文件夹
        GameObject go = GameObject.Instantiate(Resources.Load("Prefabs/TreeItem")) as GameObject;

        go.name = itemName;
        TreeItem item = go.GetComponent <TreeItem>();

        item.MyTreeContainer = treeContainer;
        item.BeFolder        = false;
        item.Name            = itemName;
        go.transform.SetParent(parentFolder.SubRootRectTransform as Transform);
        item._RectTransform           = go.GetComponent <RectTransform>();
        item._RectTransform.pivot     = new Vector2(0, 1);
        item._RectTransform.anchorMax = new Vector2(0, 1);
        item._RectTransform.anchorMin = new Vector2(0, 1);

        item.ItemNameText.text     = itemName;
        item.ItemNameText.fontSize = UIEnum.FontSize;
        var   textRt = item.ItemNameText.gameObject.GetComponent <RectTransform>();
        float w      = Tools.GetStringW(item.ItemNameText.text, UIEnum.FontSize);

        textRt.sizeDelta = new Vector2(w, UIEnum.ItmeH);

        //重新设置下Folder的边框宽度
        float w1 = UIEnum.ItemImageW + w;

        item._RectTransform.sizeDelta = new Vector2(w1, UIEnum.ItemH);

        item.ParentFolder = parentFolder;

        //float h = (parentFolder.SubItemNums + 1) * UIEnum.ItemH;
        float h = parentFolder.CurFolderH;

        //float h = parentFolder.CurFolderH;
        item._RectTransform.anchoredPosition = new Vector2(UIEnum.FolderBtnW * 2 + 4, -h);
        item.CreateMenu(item);

        parentFolder.ItemList.Add(item);
        parentFolder.RefreshItemNum();


        //新建文件夹后通知上级进行重新排序,比如rootFolder下有10个subFolder,在第二个subFolder下新建,那么后面所有subFolder都要重排
        //这里注意下ui坐标系是左下是0,0所以负值是向下移动
        parentFolder.ParentYOrder(-UIEnum.ItemH, item.IndexInParentFolder);


        //刷新下MenuList的边框宽,用于刷新MenuList滚动区域,item距离Menulist左边距离+一个图标间隔+4(文字和图标间隔)+w1(文字长度)
        float _w = item.CurItemLeftOffset + UIEnum.ItemImageW + 4 + w1;

        treeContainer.SetTreeW(_w);
        treeContainer.RefreshTreeArea();

        return(item);
    }