Esempio n. 1
0
    //泡泡吸附泡泡
    public void Absorb(Bubble bubble, Slot slot)
    {
        Vector2 pos = SlotContain.InverseTransformPoint(bubble.mTran.position);
        float DistanceMin = 1000;
        Vector2 location = slot.Location;
        bool even = slot.Row % 2 == 0;
        Slot targetSlot = null;

        //搜索邻近槽位
        for (int i = 0, len = Directs.Length; i < len; i++)
        {
            Direct dir = Directs[i];
            Slot temp = FindSideBubble(location, dir, even);
            if (temp != null && temp.Bubble == null)
            {
                float dis = Vector2.Distance(pos, temp.Position);
                //距离最短
                if (dis < DistanceMin)
                {
                    DistanceMin = dis;
                    targetSlot = temp;
                }
            }
        }

        //泡泡嵌入槽内
        bubble.mTran.parent = SlotContain;
        bubble.AbsorbAction(targetSlot);
        //震动传播
        SpreadShake(bubble, targetSlot);
    }
Esempio n. 2
0
    //泡泡吸附顶部
    public void AbsorbTop(Bubble bubble)
    {
        Vector2 pos = SlotContain.InverseTransformPoint(bubble.mTran.position);
        float DistanceMin = 1000;
        Slot targetSlot = null;

        //搜索顶部泡泡
        Slot[] tops = Tables[0];
        for (int i = 0, len = tops.Length; i < len; i++)
        {
            Slot slot = tops[i];
            if (slot.Bubble == null)
            {
                float dis = Vector2.Distance(pos, slot.Position);
                if (dis < DistanceMin)
                {
                    DistanceMin = dis;
                    targetSlot = slot;
                }
            }
        }

        //泡泡嵌入槽内
        bubble.mTran.parent = SlotContain;
        bubble.AbsorbAction(targetSlot);
        //震动传播
        SpreadShake(bubble, targetSlot);
    }