Esempio n. 1
0
    public void ClearPath()
    {
        if (currentPathExists)
        {
            HexCell current = currentPathEnd;
            while (current != currentPathStart)
            {
                current.DisableHighlight();
                current = current.PathFrom;
            }
            current.DisableHighlight();
            currentPathExists = false;

            //Remove This - For Cell Labels
            //Also remove ShowUI()
            for (int i = 0; i < cells.Length; i++)
            {
                cells[i].Distance = int.MaxValue;
            }
        }
        else if (currentPathStart)
        {
            currentPathStart.DisableHighlight();
            currentPathEnd.DisableHighlight();
        }
        currentPathStart = currentPathEnd = null;
    }
 public void Unselect()
 {
     if (selectedCell != null)
     {
         selectedCell.DisableHighlight();
         selectedCell = null;
     }
     selectedUnitGO = null;
     if (infoUserCanvas != null)
     {
         infoUserCanvas.CloseUnitPanel();
     }
 }
Esempio n. 3
0
    internal void Unselect()
    {
        if (selectedCell != null)
        {
            selectedCell.DisableHighlight();
            selectedCell = null;
        }

        if (inMapResourcePanel != null)
        {
            inMapResourcePanel.gameObject.SetActive(false);
        }
    }
Esempio n. 4
0
    // ekki nota[ i bili mun lagfaera seinna og nota thetta
    public void ClearHiglighted(List <HexCell> highlighted)
    {
        if (highlighted != null)
        {
            for (int i = 0; i < highlighted.Count; i++)
            {
                HexCell current = highlighted [i];
                current.SetLabel(null);
                current.DisableHighlight();
                current.DisableHighlight();
            }

            //tilesInRange = null;
        }
    }
Esempio n. 5
0
    void HandleInput()
    {
        Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(inputRay, out hit))
        {
            EditCell(hexGrid.GetCell(hit.point));
            HexCell currentCell = hexGrid.GetCell(hit.point);
            if (Input.GetKey(KeyCode.LeftShift) && searchToCell != currentCell)
            {
                if (searchFromCell)
                {
                    searchFromCell.DisableHighlight();
                }
                searchFromCell = currentCell;
                searchFromCell.EnableHighlight(Color.blue);
                if (searchToCell)
                {
                    hexGrid.FindPath(searchFromCell, searchToCell);
                }
            }
            if (searchFromCell && searchFromCell != currentCell)
            {
                searchToCell = currentCell;
                hexGrid.FindPath(searchFromCell, searchToCell);
            }
        }
    }
Esempio n. 6
0
 public void DehighlightCell(HexCell cell)
 {
     if (cell)
     {
         cell.DisableHighlight();
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 隐藏搜索出来的路径
 /// </summary>
 /// <param name="speed"></param>
 public void ClearPath()
 {
     if (currentPathExists)
     {
         HexCell current = currentPathTo;
         while (current != currentPathFrom)
         {
             current.SetLabel(null);
             current.DisableHighlight();
             current = current.PathFrom;
         }
         current.DisableHighlight();
         currentPathExists = false;
     }
     currentPathFrom = currentPathTo = null;
 }
Esempio n. 8
0
 /// <summary>
 /// Clears the path.
 /// </summary>
 public void ClearPath()
 {
     if (currentPathExists)
     {
         HexCell current = currentPathTo;
         while (current != currentPathFrom)
         {
             current.SetLabel(null);
             //TODO: bretua i infinity
             current.turnsToReach = 1000;
             current.DisableHighlight();
             current = current.PathFrom;
         }
         current.DisableHighlight();
         currentPathExists = false;
     }
     currentPathFrom = currentPathTo = null;
 }
Esempio n. 9
0
 internal void Unselect()
 {
     if (selectedCell != null)
     {
         selectedCell.DisableHighlight();
         selectedCell = null;
     }
     if (cityInfoPanel != null)
     {
         cityInfoPanel.gameObject.SetActive(false);
     }
 }
Esempio n. 10
0
    void CreateCell(int x, int z, int i)
    {
        Vector3 position;

        position.x = (x + z * 0.5f - z / 2) * (HexMetrics.innerRadius * 2f);
        position.y = 0f;
        position.z = z * (HexMetrics.outerRadius * 1.5f);

        HexCell cell = cells[i] = Instantiate <HexCell>(cellPrefab);

        cell.transform.localPosition = position;
        cell.coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
        //		cell.Color = defaultColor;
        cell.Index      = i;
        cell.ShaderData = cellShaderData;

        if (x > 0)
        {
            cell.SetNeighbor(HexDirection.W, cells[i - 1]);
        }

        if (z > 0)
        {
            if ((z & 1) == 0)
            {
                cell.SetNeighbor(HexDirection.SE, cells[i - cellCountX]);
                if (x > 0)
                {
                    cell.SetNeighbor(HexDirection.SW, cells[i - cellCountX - 1]);
                }
            }
            else
            {
                cell.SetNeighbor(HexDirection.SW, cells[i - cellCountX]);
                if (x < cellCountX - 1)
                {
                    cell.SetNeighbor(HexDirection.SE, cells[i - cellCountX + 1]);
                }
            }
        }

        Text label = Instantiate <Text>(cellLabelPrefab);

        label.rectTransform.anchoredPosition =
            new Vector2(position.x, position.z);
        //label.text = cell.coordinates.ToStringOnSeparateLines();
        cell.uiRect = label.rectTransform;
        cell.DisableHighlight();
        cell.Elevation = 0;
        AddCellToChunk(x, z, cell);
    }
Esempio n. 11
0
    //TODO: sameina þetta og næsta fall, eins og er tilesInRange ekki public
    public void ClearTilesInRange()
    {
        if (tilesInRange != null)
        {
            for (int i = 0; i < tilesInRange.Count; i++)
            {
                HexCell current = tilesInRange [i];
                current.SetLabel(null);
                current.DisableHighlight();
            }

            tilesInRange = null;
        }
    }
Esempio n. 12
0
 public void ClearPath()
 {
     if (currentPathExists)
     {
         HexCell current = currentPathTo;
         while (current != currentPathFrom)
         {
             if (reachableCells.Contains(current))
             {
                 current.EnableHighlight(Color.green);
             }
             else
             {
                 current.DisableHighlight();
             }
             current.SetLabel(null);
             current = current.PathFrom;
         }
         current.DisableHighlight();
         currentPathExists = false;
     }
     currentPathFrom = currentPathTo = null;
 }
Esempio n. 13
0
    //TODO: sameina þetta og næsta fall, eins og er tilesInRange ekki public
    public void ClearAttackableTiles()
    {
        if (unitsInRange != null)
        {
            for (int i = 0; i < unitsInRange.Count; i++)
            {
                HexCell current = unitsInRange [i];
                current.SetLabel(null);
                current.attackable = false;
                current.DisableHighlight();
            }

            unitsInRange = null;
        }
    }
Esempio n. 14
0
    public void GetHexGridInfo()
    {
        currentHexCell     = hexGrid.GetCell(currentHexCoordinates);
        terrain            = currentHexCell.TerrainTypeIndex.ToString();
        elevation          = currentHexCell.Elevation.ToString();
        IsUnderwater       = currentHexCell.IsUnderwater;
        HasRiver           = currentHexCell.HasRiver;
        HasRiverBeginOrEnd = currentHexCell.HasRiverBeginOrEnd;
        HasRoads           = currentHexCell.HasRoads;
        IsSpecial          = currentHexCell.IsSpecial;
        Walled             = currentHexCell.Walled;
        IsVisible          = currentHexCell.IsVisible;
        IsExplored         = currentHexCell.IsExplored;
        Explorable         = currentHexCell.Explorable;

        urbanLevel = currentHexCell.UrbanLevel;

        currentHexCell.EnableHighlight(Color.yellow);
        currentHexCell.PortalIndex = 1;
        //currentHexCell.Walled = true;
        // currentHexCell.SpaceCrackIndex = 1;
        //currentHexCell.SpecialIndex = 1;
        // Debug.Log(currentHexCell.SpaceCrackIndex);
        //currentHexCell.SpaceCrackIndex
        //currentHexCell.UrbanLevel = 1;
        if (preSelectCell.GetValue(0) != null && (HexCell)preSelectCell.GetValue(0) != currentHexCell)
        {
            preSelectCell.SetValue(currentHexCell, 1);
            HexCell cell = (HexCell)preSelectCell.GetValue(0);
            cell.DisableHighlight();
            preSelectCell.SetValue(null, 0);
        }
        else if (preSelectCell.GetValue(1) != null && (HexCell)preSelectCell.GetValue(1) != currentHexCell)
        {
            preSelectCell.SetValue(currentHexCell, 0);
            HexCell cell = (HexCell)preSelectCell.GetValue(1);
            cell.DisableHighlight();
            preSelectCell.SetValue(null, 1);
        }
        else if (preSelectCell.GetValue(0) == null && preSelectCell.GetValue(1) == null)
        {
            preSelectCell.SetValue(currentHexCell, 0);
        }
        cellInfoDisplay.text = "Cell Position:" + currentHexCoordinates.ToString() + "\n" + "Terrain:" + terrain + "\n" + "Elevation:" + elevation + "\n" + "Is Underwater:" + IsUnderwater +
                               "\n" + "Has River:" + HasRiver + "\n" + "Has River B OR E:" + HasRiverBeginOrEnd + "\n" + "Has Roads:" + HasRoads +
                               "\n" + "Is Special:" + IsSpecial + "\n" + "Is Visible:" + IsVisible + "\n" + "Is Explored:" + IsExplored + "\n" + "Explorable:" + Explorable;
    }
Esempio n. 15
0
    IEnumerator TravelPath()
    {
        Grid.DecreaseVisibility(currentTravelLocation ? currentTravelLocation : pathToTravel[0], this);
        pathToTravel[0].DisableHighlight();
        for (int i = 1; i < pathToTravel.Count; i++)
        {
            currentTravelLocation = pathToTravel[i];
            HexCell A = currentTravelLocation;
            HexCell B = pathToTravel[i - 1];
            Direction = A.GetHexDirection(B);

            spentPoints += GetMoveCost(A, B, Direction);

            Vector3 a = pathToTravel[i - 1].Position;
            Vector3 b = currentTravelLocation.Position;

            float t = Time.deltaTime * travelSpeed;
            Grid.IncreaseVisibility(pathToTravel[i], this);
            if (infoScreen)
            {
                // if the infocreen is not null, we still have the unit selected after travel.
                B.EnableHighlight(GameManager.instance.selectedCellColor);
                infoScreen.UpdateValues();
            }
            for (; t < 1f; t += Time.deltaTime * travelSpeed)
            {
                transform.localPosition = Vector3.Lerp(a, b, t);
                yield return(null);
            }
            Grid.DecreaseVisibility(pathToTravel[i], this);
            B.DisableHighlight();
            t -= 1f;
        }
        if (infoScreen)
        {
            // if the infocreen is not null, we still have the unit selected after travel.
            location.EnableHighlight(GameManager.instance.selectedCellColor);
            infoScreen.UpdateValues();
        }
        currentTravelLocation   = null;
        transform.localPosition = location.Position;
        Grid.IncreaseVisibility(location, this);
        hasMoved     = true;
        currentState = HexUnitState.Idle;
    }
Esempio n. 16
0
    bool UpdateCurrentCell()
    {
        HexCell cell =
            grid.GetCell(Camera.main.ScreenPointToRay(Input.mousePosition));

        if (cell != currentCell)
        {
            if (currentCell)
            {
                currentCell.DisableHighlight();
            }
            currentCell = cell;
            if (currentCell)
            {
                currentCell.EnableHighlight(Color.blue);
            }
            return(true);
        }
        return(false);
    }
Esempio n. 17
0
 void ClearStartingCells()
 {
     if (currentCell)
     {
         currentCell.DisableHighlight();
         currentCell = null;
     }
     if (startCell)
     {
         startCell.DisableHighlight();
         startCell = null;
     }
     if (endCell)
     {
         endCell.DisableHighlight();
         endCell = null;
     }
     if (previousCell)
     {
         previousCell.DisableHighlight();
     }
 }