Exemple #1
0
    /// <summary>
    /// 添加进grid
    /// </summary>
    void AddItemInGrid(int id, bool tail = true)
    {
        //添加到最后一个
        GameObject newGO = ResourcesMgr.Instance().PopPool(PrefabDefine.RECORD);

        newGO.transform.SetParent(contentTrans);
        newGO.transform.localScale = Vector3.one;
        if (tail)
        {
            //Debug.Log("添加到尾部:" + id);
            newGO.transform.localPosition = curPool[curPool.Count - 1].transform.localPosition - new Vector3(0, cellSize.y, 0);
            curHead++;
            curPool.Add(newGO);
        }
        else
        {
            //Debug.Log("添加到头部:" + id);
            newGO.transform.localPosition = curPool[0].transform.localPosition + new Vector3(0, cellSize.y, 0);
            curTail--;
            curPool.Insert(0, newGO);
        }
        newGO.name = "record_" + id;
        newGO.transform.Find("Text").GetComponent <Text>().text = Recyle.Instance().pathList[id];
        beginPos = contentTrans.localPosition;
    }
Exemple #2
0
 public static Recyle Instance()
 {
     if (instance == null)
     {
         instance = new Recyle();
     }
     return(instance);
 }
Exemple #3
0
    /// <summary>
    /// 拖动过程中刷新UI
    /// </summary>
    void RefreshUI()
    {
        int needCount = Recyle.Instance().pathList.Count;

        //判断向上还是向下
        if (curPos.y > beginPos.y)
        {
            //Debug.Log("向下");
            if (curTail >= needCount - 1)
            {
                return;
            }
            int count = curPool.Count;
            int idx   = 0;
            for (int i = 0; i < count; i++)
            {
                if (curPos.y + curPool[idx].transform.localPosition.y >= 0)
                {
                    GameObject go = curPool[idx];
                    curPool.RemoveAt(idx);
                    ResourcesMgr.Instance().PushPool(PrefabDefine.RECORD, go);
                    AddItemInGrid(++curTail);
                }
                else
                {
                    return;
                }
            }
        }
        else if (curPos.y < beginPos.y)
        {
            //Debug.Log("向上");
            if (curHead <= 0)
            {
                return;
            }
            int   count  = curPool.Count;
            int   idx    = count - 1;
            float height = view.GetComponent <RectTransform>().sizeDelta.y;
            for (int i = count - 1; i >= 0; i--)
            {
                if (curPos.y + height + curPool[idx].transform.localPosition.y < cellSize.y)
                {
                    GameObject go = curPool[idx];
                    curPool.RemoveAt(idx);
                    ResourcesMgr.Instance().PushPool(PrefabDefine.RECORD, go);
                    AddItemInGrid(--curHead, false);
                }
                else
                {
                    return;
                }
            }
        }
    }
Exemple #4
0
    private void InitUI()
    {
        float viewHeight = view.GetComponent <RectTransform>().sizeDelta.y;

        cellSize = contentTrans.GetComponent <GridLayoutGroup>().cellSize;
        float cellHeight = cellSize.y;
        //view能容纳个数
        float count = viewHeight / cellHeight;
        //根据需要加载个数
        int needCount = Recyle.Instance().pathList.Count;

        //根据需要加载个数初始化contentsize
        contentTrans.GetComponent <RectTransform>().sizeDelta = new Vector2(0, needCount * cellHeight);
        if (count - (int)count > 0)
        {
            count = (int)count + 1;
        }
        //实际需要
        int realCount = 0;

        if (needCount >= (int)count)
        {
            realCount = (int)count;
        }
        else
        {
            realCount = needCount;
        }

        for (int i = 0; i < realCount; i++)
        {
            GameObject go = ResourcesMgr.Instance().PopPool(PrefabDefine.RECORD);
            go.name = "record_" + i;
            go.transform.SetParent(contentTrans);
            go.transform.localScale = Vector3.one;
            go.transform.Find("Text").GetComponent <Text>().text = Recyle.Instance().pathList[i];

            Button btn = go.GetComponent <Button>();
            btn.onClick.AddListener(delegate()
            {
                OnClickRecord(go);
            });
        }
        curHead = 0;
        curTail = (int)count - 1;
    }
Exemple #5
0
    private void OnClickClear()
    {
        Recyle.Instance().ClearPath();

        Clear();
    }
Exemple #6
0
    //[MenuItem("Tools/遍历文件")]
    private void LogPath()
    {
        RefreshOutPut();
        GetPath();
        if (string.IsNullOrEmpty(PATH))
        {
            debugText.text = "路径不能为空";
            return;
        }

        //遍历文件存入list
        List <string> data = new List <string>();
        Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >();

        if (type == SearchType.single)
        {
            GetDirs(PATH, ref data);
        }
        else if (type == SearchType.all)
        {
            GetDirs(PATH, ref data);
        }
        Helper.ListStringSort(ref data);

        //处理前缀
        string first = data.Count == 0 ? "" : data[0].PadLeft(NAME_MIN, '0');
        string pre   = string.IsNullOrEmpty(inputText.text) ? "" : inputText.text;

        if (pre.Length < PRE_MIN)
        {
            pre = pre.PadRight(PRE_MIN, ' ');
        }
        pre += KUANG[0];

        //写入string
        StreamWriter sw;
        string       path = Application.dataPath + "/Output" + "/" + "output.txt";

        if (!File.Exists(path))
        {
            sw = File.CreateText(path);//创建一个用于写入 UTF-8 编码的文本
        }
        else
        {
            File.Delete(path);
            sw = File.CreateText(path);
        }
        int    row    = 1;
        string number = first;
        //以行为单位写入text
        string rowString = pre + first;

        for (int i = 1; i < data.Count; i++)
        {
            //处理名字
            string name = data[i];
            if (name.Length < NAME_MIN)
            {
                name = name.PadLeft(NAME_MIN, '0');
            }
            //处理隔行
            row += 1;
            if (row <= ROW_COUNT)
            {
                number    = number + "," + name;
                rowString = rowString + "," + name;
                //若最后且不满一行
                if (i == data.Count - 1)
                {
                    sw.WriteLine(rowString + KUANG[1]);
                }
            }
            else
            {
                sw.WriteLine(rowString);
                number    = number + ",\n" + name.PadLeft(Helper.GetNumberSpace(pre), ' ');
                row      -= ROW_COUNT;
                rowString = name.PadLeft(8, ' ');
            }
        }
        sw.Close();
        sw.Dispose();//文件流释放
        Debug.Log(pre + number + KUANG[1]);
        num             = pre + number + KUANG[1];
        outputText.text = outputText.text + num;

        SetDebug(data);
        //更新历史记录并刷新
        Recyle.Instance().PushPool(PATH);
        recordView.Refresh();
    }