コード例 #1
0
        public List <UnitBase> GetUnitListInLine(IntVector2 startPos, short angle, short lineWidth, short lineLength, CampType effectCamp, List <UnitBase> filler = null)
        {
            List <UnitBase> ret = null;

            if (null == filler)
            {
                ret = mConditionFindRet;
                ret.Clear();
            }
            else
            {
                ret = filler;
            }

            //求出未旋转时的矩形的四个边的坐标
            IntVector2 rectangleLeftBottomPos  = startPos - new IntVector2(lineWidth, 0);
            IntVector2 rectangleRightBottomPos = startPos + new IntVector2(lineWidth, 0);
            IntVector2 rectangleLeftTopPos     = rectangleLeftBottomPos + new IntVector2(0, lineLength);
            IntVector2 rectangleRightTopPos    = rectangleRightBottomPos + new IntVector2(0, lineLength);

            //对四个边进行旋转
            rectangleLeftBottomPos  = IntVector2.Rotate(rectangleLeftBottomPos, angle);
            rectangleLeftTopPos     = IntVector2.Rotate(rectangleLeftTopPos, angle);
            rectangleRightBottomPos = IntVector2.Rotate(rectangleRightBottomPos, angle);
            rectangleRightTopPos    = IntVector2.Rotate(rectangleRightTopPos, angle);

            IntVector2 minPos = IntVector2.MinVector(rectangleLeftBottomPos, rectangleLeftTopPos, rectangleRightBottomPos, rectangleRightTopPos);
            IntVector2 maxPos = IntVector2.MaxVector(rectangleLeftBottomPos, rectangleLeftTopPos, rectangleRightBottomPos, rectangleRightTopPos);

            int searchIndexMinX = PosToSafeXLattlceIndex(minPos.x);
            int searchIndexMaxX = PosToSafeXLattlceIndex(maxPos.x);
            int searchIndexMinY = PosToSafeYLattlceIndex(minPos.y);
            int searchIndexMaxY = PosToSafeYLattlceIndex(maxPos.y);

            Matrix3x3 transMa3x3 = Matrix3x3.Create(angle, startPos);

            for (int i = searchIndexMinX; i <= searchIndexMaxX; i++)
            {
                for (int j = searchIndexMinY; j <= searchIndexMaxY; ++j)
                {
                    List <UnitBase> lattleUnitList = mLattileUnitList[i, j];
                    if (null == lattleUnitList)
                    {
                        continue;
                    }
                    for (int k = 0; k < lattleUnitList.Count; ++k)
                    {
                        UnitBase unitBase = lattleUnitList[k];
                        if (unitBase.Data.camp != effectCamp)
                        {
                            continue;
                        }
                        IntVector2 posInSquare = transMa3x3 * unitBase.Position;
                        if (MathUtils.IsPosInSquare(lineWidth, lineLength, posInSquare))
                        {
                            ret.Add(unitBase);
                        }
                    }
                }
            }
            return(ret);
        }