Exemple #1
0
    void CheckFusion()
    {
        if (!judge)
        {
            return;
        }
        bool[] fused = new bool[grabbedPieceList.Count];
        for (int i = 0; i < grabbedPieceList.Count; i++)
        {
            if (fused[i])
            {
                continue;
            }

            var   p1      = grabbedPieceList[i];
            int   closest = -1;
            float minDist = fusionDistance;
            // find closest fusable piece
            for (int j = i + 1; j < grabbedPieceList.Count; j++)
            {
                if (fused[j])
                {
                    continue;
                }
                var p2 = grabbedPieceList[j];
                if ((judge.CanRepairFruit(p1.gameObject, p2.gameObject)))
                {
                    float dist = Dist(p1, p2);
                    if (dist < minDist)
                    {
                        closest = j;
                        minDist = dist;
                    }
                }
            }
            if (closest != -1)
            {
                fused[i]       = true;
                fused[closest] = true;
                judge.RepairFruit(grabbedPieceList[i].gameObject, grabbedPieceList[closest].gameObject);
            }
        }
        for (int i = fused.Length - 1; i >= 0; i--)
        {
            if (fused[i])
            {
                grabbedPieceList.RemoveAt(i);
            }
        }
    }