/// <summary> /// Gets the crossing costs for a given hexagonal side /// </summary> /// <returns>The side cross cost.</returns> public float GetSideCrossCost(CELL_SIDE side) { if (crossCost == null) { return(0); } return(crossCost[(int)side]); }
/// <summary> /// Assigns a crossing cost for a given hexagonal side /// </summary> /// <param name="side">Side.</param> /// <param name="cost">Cost.</param> public void SetSideCrossCost(CELL_SIDE side, int cost) { if (_crossCost == null) { _crossCost = new int[6]; } _crossCost[(int)side] = cost; }
/// <summary> /// Assigns a crossing cost for a given hexagonal side /// </summary> /// <param name="side">Side.</param> /// <param name="cost">Cost.</param> public void SetSideCrossCost(CELL_SIDE side, float cost) { if (crossCost == null) { crossCost = new float[6]; } crossCost[(int)side] = cost; }
/// <summary> /// Returns true if side is blocking LOS /// </summary> public bool GetSideBlocksLOS(CELL_SIDE side) { if (_blocksLOS == null) { return(false); } return(_blocksLOS[(int)side]); }
/// <summary> /// Assigns a crossing cost for a given hexagonal side /// </summary> /// <param name="side">Side.</param> public void SetSideBlocksLOS(CELL_SIDE side, bool blocks) { if (_blocksLOS == null) { _blocksLOS = new bool[8]; } _blocksLOS[(int)side] = blocks; }
/// <summary> /// Gets the extra cost for crossing a given cell side /// </summary> public int PathFindingCellGetSideCost(int cellIndex, CELL_SIDE side) { if (_cellsCosts == null || cellIndex < 0 || cellIndex >= _cellsCosts.Length) { return(-1); } return(_cellsCosts [cellIndex].crossCost [(int)side]); }
/// <summary> /// Sets the cost for crossing a given cell side. Note that the cost is only assigned in one direction (from this cell to the outside). /// </summary> public void PathFindingCellSetSideCost(int cellIndex, CELL_SIDE side, int cost) { if (_cellsCosts == null || cellIndex < 0 || cellIndex >= _cellsCosts.Length) { return; } _cellsCosts [cellIndex].SetSideCrossCost(side, cost); }
/// <summary> /// Draws a line over a cell side. /// </summary> /// <returns>The line.</returns> /// <param name="cellIndex">Cell index.</param> /// <param name="side">Side.</param> /// <param name="color">Color.</param> /// <param name="width">Width.</param> public GameObject DrawLine(int cellIndex, CELL_SIDE side, Color color, float width) { GameObject line = new GameObject("Line"); LineRenderer lr = line.AddComponent <LineRenderer>(); if (cellLineMat == null) { cellLineMat = Resources.Load <Material>("Materials/CellLine") as Material; } Material mat = Instantiate(cellLineMat) as Material; mat.MarkForDisposal(); mat.color = color; lr.sharedMaterial = mat; lr.useWorldSpace = true; lr.positionCount = 2; lr.startWidth = width; lr.endWidth = width; int v1, v2; switch (side) { case CELL_SIDE.BottomLeft: v1 = 0; v2 = 1; break; case CELL_SIDE.Bottom: v1 = 1; v2 = 2; break; case CELL_SIDE.BottomRight: v1 = 2; v2 = 3; break; case CELL_SIDE.TopRight: v1 = 3; v2 = 4; break; case CELL_SIDE.Top: v1 = 4; v2 = 5; break; default: // BottomLeft v1 = 5; v2 = 0; break; } Vector3 offset = transform.forward * 0.05f; lr.SetPosition(0, CellGetVertexPosition(cellIndex, v1) - offset); lr.SetPosition(1, CellGetVertexPosition(cellIndex, v2) - offset); return(line); }
/// <summary> /// Adds a line to the 2D map over a Cell edge with options (returns the line gameobject). /// </summary> /// <param name="points">Sequence of points for the line</param> /// <param name="side">the side of the hexagonal cell</param> /// <param name="color">line color</param> /// <param name="lineWidth">line width</param> public LineMarkerAnimator AddLine(int cellIndex, CELL_SIDE side, Color color, float lineWidth) { LineMarkerAnimator lma = AddLine(cellIndex, side, markerLineMat, lineWidth); if (lma != null) { lma.color = color; } return(lma); }
/// <summary> /// Gets the additional cost of crossing any hexagon side. /// </summary> /// <param name="cellIndex">Cell index.</param> /// <param name="side">Side of the hexagon.</param>/// /// <param name="additionalCost">Additional cost.</param> public int CellGetSideCrossCost(int cellIndex, CELL_SIDE side, int additionalCost) { if (cellIndex < 0 || cellIndex >= cells.Count) { return(0); } if (cells[cellIndex].crossCost != null) { return(cells[cellIndex].crossCost[(int)side]); } else { return(0); } }
/// <summary> /// Adds a line to the 2D map over a Cell edge with options (returns the line gameobject). /// </summary> /// <param name="points">Sequence of points for the line</param> /// <param name="side">the side of the hexagonal cell</param> /// <param name="material">line material</param> /// <param name="lineWidth">line width</param> public LineMarkerAnimator AddLine(int cellIndex, CELL_SIDE side, Material material, float lineWidth) { if (cells == null || cellIndex < 0 || cellIndex >= cells.Length) { return(null); } Vector2[] points = new Vector2[2]; Cell cell = cells[cellIndex]; switch (side) { case CELL_SIDE.TopLeft: points[0] = cell.points[0]; points[1] = cell.points[1]; break; case CELL_SIDE.Top: points[0] = cell.points[1]; points[1] = cell.points[2]; break; case CELL_SIDE.TopRight: points[0] = cell.points[2]; points[1] = cell.points[3]; break; case CELL_SIDE.BottomRight: points[0] = cell.points[3]; points[1] = cell.points[4]; break; case CELL_SIDE.Bottom: points[0] = cell.points[4]; points[1] = cell.points[5]; break; case CELL_SIDE.BottomLeft: points[0] = cell.points[5]; points[1] = cell.points[0]; break; } LineMarkerAnimator lma = AddLine(points, material, 0, lineWidth); lma.numPoints = 2; return(lma); }
/// <summary> /// Sets the additional cost of crossing an hexagon side. /// </summary> /// <param name="cellIndex">Cell index.</param> /// <param name="side">Side of the hexagon.</param> /// <param name="additionalCost">Additional cost.</param> /// <param name="symmetrical">Applies crossing cost to both directions of the given side.</param> public void CellSetSideCrossCost(int cellIndex, CELL_SIDE side, int additionalCost, bool symmetrical = true) { if (cellIndex < 0 || cellIndex >= cells.Count) { return; } Cell cell = cells[cellIndex]; cell.SetSideCrossCost(side, additionalCost); int r = cell.row; int c = cell.column; int or = r, oc = c; CELL_SIDE os = side; if (symmetrical) { switch (side) { case CELL_SIDE.Bottom: or--; os = CELL_SIDE.Top; break; case CELL_SIDE.Top: or++; os = CELL_SIDE.Bottom; break; case CELL_SIDE.BottomRight: if (oc % 2 != 0) { or--; } oc++; os = CELL_SIDE.TopLeft; break; case CELL_SIDE.TopRight: if (oc % 2 == 0) { or++; } oc++; os = CELL_SIDE.BottomLeft; break; case CELL_SIDE.TopLeft: if (oc % 2 == 0) { or++; } oc--; os = CELL_SIDE.BottomRight; break; case CELL_SIDE.BottomLeft: if (oc % 2 != 0) { or--; } oc--; os = CELL_SIDE.TopRight; break; } int oindex = CellGetIndex(or, oc); if (oindex >= 0) { cells[oindex].SetSideCrossCost(os, additionalCost); } } }