示例#1
0
    /// <summary>
    /// 找到离目标最近的移动点
    /// </summary>
    public Vector2Int GetMovingTargetPos(BattleUnit unit, Vector2Int targetPos)
    {
        standingGrid  = mapGrids[unit.Position.x][unit.Position.y];
        targetGrid    = standingGrid;
        walkableRange = CircleTargets(unit.Steps);
        int  distance = 0;
        int  temp;
        int  index = 0;
        bool isStraight;
        bool tempStraight;

        distance = MathCalculator.GetBattleGridDistance(targetPos, walkableRange[0].Position, out isStraight);
        Debug.Log("Total range = " + walkableRange.Count + "," + walkableRange[0].Position + "," + distance + "," + isStraight);

        for (int i = 1; i < walkableRange.Count; i++)
        {
            Debug.Log(walkableRange[i].Position + "," + walkableRange[i].Walkable);
            if (!walkableRange[i].Walkable)
            {
                continue;
            }
            temp = MathCalculator.GetBattleGridDistance(targetPos, walkableRange[i].Position, out tempStraight);
            Debug.Log(walkableRange[i].Position + "," + distance + "," + isStraight);
            if (temp < distance || (!isStraight && tempStraight))
            {
                distance   = temp;
                isStraight = tempStraight;
                index      = i;
            }
        }
        return(walkableRange[index].Position);
    }