Example #1
0
 /// <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);
     }
 }
Example #2
0
 /// <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);
 }
Example #3
0
 /// <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");
     }
 }
Example #4
0
 /// <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");
     }
 }
Example #5
0
    /// <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);
        }
    }
Example #6
0
    /// <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);
    }
Example #7
0
    /// <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);
    }
Example #8
0
    /// <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);
    }
Example #9
0
    /// <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);
    }
Example #10
0
    /// <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);
    }
Example #11
0
    /// <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();
    }
Example #12
0
 /// <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);
 }
Example #13
0
    /// <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);
    }
Example #14
0
    /// <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();
    }