// Use this for initialization
 public override void Init()
 {
     //Vector3 direction = (FinalTarget.transform.position - Character.transform.position).normalized;
     //Character.transform.up = direction;
     m_startingPoint = Character.transform.parent.gameObject.GetComponent<GridHex>();
     Character.transform.SetParent(FinalTarget.transform);
 }
Пример #2
0
    private static List<List<GridHex>> recurseHexPath(GridHex _startHex, GridHex _endHex, int _moverSize, List<List<GridHex>> _paths)
    {
        // The current hex is the last hex on the last path in the list.
        List<GridHex> currentPath = _paths[_paths.Count-1];
        GridHex currentHex = currentPath[currentPath.Count-1];

        if (currentHex == _endHex)
        {
            // Path finished (successfully)
            List<GridHex> newPath = new List<GridHex>(currentPath);
            newPath.Remove(currentHex);
            _paths.Add(newPath);
            //Debug.Log("FOUND SUCCESSFULL PATH OF LENGTH " + currentPath.Count +
                      //". Saving and branching to new path starting from " + newPath[newPath.Count-1].name + ".");
            return _paths;
        }

        for (int i = 0; i < currentHex.AdjacentHexes.Length; i++)
        {
            currentPath = _paths[_paths.Count-1];
            GridHex nextHex = currentHex.AdjacentHexes[i];
            if (nextHex != null)
            {
                if (nextHex.IsNavigable &&
                    nextHex.AvailableSpace >= _moverSize &&
                    !currentPath.Contains(nextHex))
                {
                    //Debug.Log("Moving to next valid hex: " + nextHex.name);
                    _paths[_paths.Count-1].Add(nextHex);
                    _paths = recurseHexPath(_startHex, _endHex, _moverSize, _paths);
                }
                else
                {
                    //Debug.Log("Found invalid hex " + "(" + nextHex.name  + ".)" + "Moving back to " + currentHex.name);
                    string path = "";
                    for (int j = 0; j < currentPath.Count; j++)
                    {
                        path += "-> " + currentPath[j].name;
                    }
                    //Debug.Log("Current path: " + path);
                }
            }
            else
            {
                //Debug.Log("No hex in this direction.");
            }
        }

        // Exhausted all options for this hex.
        //Debug.Log("Exhausted all options for " + currentHex.gameObject.name + ". Removing from current path.");
        _paths[_paths.Count-1].Remove(currentHex);
        if (_paths[_paths.Count-1].Count == 0)
            _paths.Remove(_paths[_paths.Count-1]);
        return _paths;
    }
Пример #3
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GridHex grid = (GridHex)target;

        int size = grid.numberOfTiles;

        if (GUILayout.Button("Create Grid"))
        {
            grid.ResetGrid();
            grid.CreateGrid(size);
        }
    }
Пример #4
0
    public static List<GridHex> PathToHex(GridHex _startHex, GridHex _endHex, int _moverSize = 2)
    {
        List<List<GridHex>> availablePaths = new List<List<GridHex>>();
        List<GridHex> startingPath = new List<GridHex>();
        startingPath.Add(_startHex);
        availablePaths.Add(startingPath);

        availablePaths = recurseHexPath(_startHex, _endHex, _moverSize, availablePaths);

        //Debug.Log("Number of paths discovered: " + availablePaths.Count);

        // Find shortest path
        int shortestLength = 0;
        int shortestPathIndex = 0;
        for (int i = 0; i < availablePaths.Count; i++)
        {
            string path = "";
            for (int j = 0; j < availablePaths[i].Count; j++)
            {
                path += "-> " + availablePaths[i][j].name;
            }

            //Debug.Log("Path " + i + ": Length " + availablePaths[i].Count + ": " + path);
            if ((shortestLength == 0 || shortestLength > availablePaths[i].Count) && availablePaths[i].Count != 0)
            {
                shortestLength = availablePaths[i].Count;
                shortestPathIndex = i;
            }
        }

        string npath = "";
        for (int j = 0; j < availablePaths[shortestPathIndex].Count; j++)
        {
            npath += "-> " + availablePaths[shortestPathIndex][j].name;
        }
        //Debug.Log("Shortest path has length " + availablePaths[shortestPathIndex].Count + " (" + npath + ")");
        return availablePaths[shortestPathIndex];
    }
Пример #5
0
 public void SetSelectedHex(GridHex _newHex)
 {
     m_SelectedHex = _newHex;
 }
Пример #6
0
 public void OnUniversalNPCTargetClicked(GridHex _hexTarget)
 {
     UniversalNPCTarget = _hexTarget;
 }
Пример #7
0
    public void Place(GridHex _fromHex, int _adjIndex, float _spacing)
    {
        // Determine position offset
        //Debug.Log("Determining new hex placement.");
        Vector3 fromHexPosition = _fromHex.transform.position;
        float placeTheta = 30f + (_adjIndex*60f);
        //Debug.Log("Place Theta: " + placeTheta);
        float placeThetaR = placeTheta * Mathf.PI / 180f;
        Vector3 positionOffset = new Vector3(Mathf.Cos(placeThetaR)*_spacing, 0.0f, Mathf.Sin(placeThetaR)*_spacing);
        transform.position = fromHexPosition + positionOffset;

        // Establish mutual adjacency
        //Debug.Log("Adj index: " + _adjIndex);
        //_fromHex.AdjacentHexes[_adjIndex] = this;

        /*
        int oppositeAdjIndex = _adjIndex + 3;
        if (oppositeAdjIndex > 5) oppositeAdjIndex -= 6;
        Debug.Log(AdjacentHexes.Length);
        Debug.Log("Opposite adj index: " + oppositeAdjIndex);
        AdjacentHexes[oppositeAdjIndex] = _fromHex;
        */

        //FindAdjacentHexes(_spacing);
    }