/// <summary> /// // Adds a list of cube HexagonCells to the given container key /// </summary> /// <param name="cubes"></param> /// <param name="key"></param> public void AddCubesToContainer(List <Vector3> cubes, BoxTypeFeature key) { foreach (Vector3 cube in cubes) { AddHexagonCellToContainer(GetHexagonCellFromContainer(cube, _tileFeature), key); } }
/// <summary> /// // Hides and Clears all HexagonCells for a given container key /// </summary> /// <param name="key"></param> public void HideAndClearhexContainer(BoxTypeFeature key) { foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key)) { HexagonCell.Hide(); } ClearHexagonCellsFromContainer(key); }
/// <summary> /// // Shows all HexagonCells for a given container key /// </summary> /// <param name="key"></param> /// <param name="bCollider"></param> public void ShowHexagonCellsInContainer(BoxTypeFeature key, bool bCollider = true) { foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key)) { HexagonCell.Show(); AddHexagonCellToContainer(HexagonCell, "visible"); } }
/// <summary> /// // Hides all HexagonCells for a given container key /// </summary> /// <param name="key"></param> public void HideHexagonCellsInContainer(BoxTypeFeature key) { foreach (HexagonCell HexagonCell in GetHexagonCellsFromContainer(key)) { HexagonCell.Hide(); RemoveHexagonCellFromContainer(HexagonCell, "visible"); } }
/// <summary> /// // Removes a given HexagonCell from the given container key /// </summary> /// <param name="HexagonCell"></param> /// <param name="key"></param> public void RemoveHexagonCellFromContainer(HexagonCell HexagonCell, BoxTypeFeature key) { Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); if (hexContainer.ContainsKey(HexagonCell.cube)) { hexContainer.Remove(HexagonCell.cube); } }
/// <summary> /// // Adds a given HexagonCell to the given container key /// </summary> /// <param name="HexagonCell"></param> /// <param name="key"></param> /// <returns></returns> public bool AddHexagonCellToContainer(HexagonCell HexagonCell, BoxTypeFeature key) { Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); if (!hexContainer.ContainsKey(HexagonCell.cube)) { hexContainer.Add(HexagonCell.cube, HexagonCell); return(true); } return(false); }
/// <summary> /// // Returns a list of cube HexagonCells given a container key /// </summary> /// <param name="key"></param> /// <returns></returns> public List <Vector3> GetCubesFromContainer(BoxTypeFeature key) { List <Vector3> cubes = new List <Vector3>(); Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); foreach (Vector3 cube in hexContainer.Keys) { cubes.Add(cube); } return(cubes); }
/// <summary> /// // Returns a list of HexagonCells given a container key /// </summary> /// <param name="key"></param> /// <returns></returns> public List <HexagonCell> GetHexagonCellsFromContainer(BoxTypeFeature key) { List <HexagonCell> HexagonCells = new List <HexagonCell>(); Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); foreach (KeyValuePair <Vector3, HexagonCell> entry in hexContainer) { HexagonCells.Add(entry.Value); } return(HexagonCells); }
/// <summary> /// // Returns a HexagonCell container given a container key /// </summary> /// <param name="key"></param> /// <returns></returns> private Dictionary <Vector3, HexagonCell> GethexContainer(BoxTypeFeature key) { Dictionary <Vector3, HexagonCell> hexContainer; if (!_hexContainers.TryGetValue(key, out hexContainer)) { _hexContainers.Add(key, new Dictionary <Vector3, HexagonCell>()); _hexContainers.TryGetValue(key, out hexContainer); } return(hexContainer); }
/// <summary> /// // Returns a HexagonCell given a cube HexagonCell and a container key /// </summary> /// <param name="cube"></param> /// <param name="key"></param> /// <returns></returns> public HexagonCell GetHexagonCellFromContainer(Vector3 cube, BoxTypeFeature key) { HexagonCell HexagonCell = null; Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); if (cube == Vector3.zero) { hexContainer.TryGetValue(Vector3.zero, out HexagonCell); } else { hexContainer.TryGetValue(cube, out HexagonCell); } return(HexagonCell); }
/// <summary> /// // Removes all HexagonCells from given container key /// </summary> /// <param name="key"></param> public void RemoveAllHexagonCellsInContainer(BoxTypeFeature key) { Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); hexContainer.Clear(); }
/// <summary> /// // Adds a given cube HexagonCell to the given container key /// </summary> /// <param name="cube"></param> /// <param name="key"></param> public void AddCubeToContainer(Vector3 cube, BoxTypeFeature key) { AddHexagonCellToContainer(GetHexagonCellFromContainer(cube, _tileFeature), key); }
/// <summary> /// // Returns an ordered list of cube HexagonCells following the A* path results between two given cube HexagonCells /// </summary> /// <param name="origin"></param> /// <param name="target"></param> /// <param name="container"></param> /// <returns></returns> public List <Vector3> GetPathBetweenTwoCubes(Vector3 origin, Vector3 target, BoxTypeFeature container = _tileFeature) { if (origin == target) { return(new List <Vector3>()); } List <Vector3> openSet = new List <Vector3>(); List <Vector3> closedSet = new List <Vector3>(); openSet.Add(origin); Dictionary <Vector3, Vector3> cameFrom = new Dictionary <Vector3, Vector3>(); cameFrom.Add(origin, Vector3.zero); Vector3 current = Vector3.zero; HexagonCell HexagonCell = null; HexagonCell currentHexagonCell = null; HexagonCell neighborHexagonCell = null; float newCost = 0.0f; while (openSet.Count > 0) { current = openSet[0]; currentHexagonCell = GetHexagonCellFromContainer(current, container); for (int i = 1; i < openSet.Count; i++) { HexagonCell = GetHexagonCellFromContainer(openSet[i], container); if (HexagonCell.fCost < currentHexagonCell.fCost || HexagonCell.fCost == currentHexagonCell.fCost && HexagonCell.hCost < currentHexagonCell.hCost) { current = openSet[i]; currentHexagonCell = GetHexagonCellFromContainer(current, container); } } openSet.Remove(current); closedSet.Add(current); if (current == target) { break; } List <Vector3> neighbors = new List <Vector3>(); neighbors = GetReachableCubes(current); foreach (Vector3 neighbor in neighbors) { HexagonCell = GetHexagonCellFromContainer(neighbor, container); if (HexagonCell == null || closedSet.Contains(neighbor)) { continue; } newCost = currentHexagonCell.gCost + GetDistanceBetweenTwoCubes(current, neighbor); neighborHexagonCell = GetHexagonCellFromContainer(neighbor, container); if (newCost < neighborHexagonCell.gCost || !openSet.Contains(neighbor)) { neighborHexagonCell.gCost = newCost; neighborHexagonCell.hCost = GetDistanceBetweenTwoCubes(current, neighbor); cameFrom.Add(neighbor, current); if (!openSet.Contains(neighbor)) { openSet.Add(neighbor); } } } } List <Vector3> path = new List <Vector3>(); current = target; path.Add(target); while (current != origin) { cameFrom.TryGetValue(current, out current); path.Add(current); } path.Reverse(); return(path); }
/// <summary> /// // Clears all HexagonCells from a given container key /// </summary> /// <param name="key"></param> public void ClearHexagonCellsFromContainer(BoxTypeFeature key) { Dictionary <Vector3, HexagonCell> hexContainer = GethexContainer(key); hexContainer.Clear(); }