Exemplo n.º 1
0
    /// <summary>
    /// 分发需加密的文件
    /// </summary>
    /// <param name="allPath"></param>
    /// <param name="ThreadCount"></param>
    /// <returns></returns>
    private static List <EncodeFileNode> DispatchEncodeFileNode(PackageNodeType packageType, List <string> ModifPath, Dictionary <string, AssetBundleManager.PackageNode> orginalTable, int ThreadCount)
    {
        if (null == ModifPath)
        {
            return(null);
        }
        if (ModifPath.Count <= 0)
        {
            return(null);
        }
        List <EncodeFileNode> reslut = new List <EncodeFileNode>();

        //根据每个线程处理的最少数目,来分配需要多少个线程,最多只有ThreadCount个线程
        int realyThreadCount = Mathf.Clamp(ModifPath.Count / MinThreadProcessCout, 1, ThreadCount);

        int clipCount = ModifPath.Count / realyThreadCount;
        //遇到有余数的,待会直接分配到最后一根线程
        int Remainder = ModifPath.Count - (realyThreadCount * clipCount);

        List <string>[] clipArray = new List <string> [realyThreadCount];

        List <string> keys = new List <string>();

        keys.AddRange(orginalTable.Keys);
        for (int i = 0; i < realyThreadCount; i++)
        {
            EncodeFileNode node = new EncodeFileNode();
            node.isDone = false;
            for (int j = i * clipCount; j < (i + 1) * clipCount; j++)
            {
                string key = ModifPath[j];
                node.ModifPath.Add(key);
                if (orginalTable.ContainsKey(key))
                {
                    node.resultTable.Add(key, orginalTable[key]);
                }
            }
            node.nodeType = packageType;
            reslut.Add(node);
        }

        //余下的分配给最后一根线程
        for (int j = 0; j < Remainder; j++)
        {
            string key = ModifPath[realyThreadCount * clipCount + j];
            reslut[realyThreadCount - 1].ModifPath.Add(key);
            if (orginalTable.ContainsKey(key))
            {
                reslut[realyThreadCount - 1].resultTable.Add(key, orginalTable[key]);
            }
        }

        foreach (EncodeFileNode node in reslut)
        {
            AssetBundleManager.PushWork(EncodeFileWorckFunc, node);
        }
        return(reslut);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 计算packageNode工作线程函数
    /// </summary>
    /// <param name="data"></param>
    private static void EncodeFileWorckFunc(System.Object data)
    {
        EncodeFileNode node = (EncodeFileNode)data;

        if (null == node)
        {
            return;
        }
        ProcessEncodeFileNode(node.nodeType, node.ModifPath, ref node.resultTable);
        node.isDone = true;
    }
Exemplo n.º 3
0
 private static bool IsEncodeFileFinish(EncodeFileNode nod)
 {
     return(null == nod || nod.isDone);
 }