Exemple #1
0
 public static void CreateGrid(int gridX, int gridZ, GameObject hexHighlighter, GameObject highlightParent)
 {
     changed         = new List <HexHighlighter>();
     highlighterGrid = new HexHighlighter[gridX, gridZ];
     for (int x = 0; x < gridX; x++)
     {
         for (int z = 0; z < gridZ; z++)
         {
             GameObject newHighlighter;
             newHighlighter = Instantiate(hexHighlighter);
             Vector3 hexPos = TerrainGen.GetHexPosition(x, z);
             hexPos.y += TerrainGen.hexSize / 2;
             newHighlighter.transform.position = hexPos;
             HexHighlighter hexHighlighterScr = newHighlighter.GetComponent <HexHighlighter>();
             if (hexPos.y > 0)
             {
                 hexHighlighterScr.Set(HexHighlight.grid);
             }
             else
             {
                 hexHighlighterScr.Set(HexHighlight.none);
                 newHighlighter.SetActive(false);
             }
             highlighterGrid[x, z]           = hexHighlighterScr;
             newHighlighter.transform.parent = highlightParent.transform;
         }
     }
 }
 public void ShowHexes()
 {
     HexHighlighter.ResetGrid();
     foreach (Vector2Int gridPos in hexesInRange)
     {
         HexHighlighter.Set(gridPos, HexHighlight.positive);
     }
     foreach (Vector2Int gridPos in blockedHexesInRange)
     {
         HexHighlighter.Set(gridPos, HexHighlight.negative);
     }
 }
    /// <summary>
    /// Updates the highlight grid to show where a tower could hit taking its name as a string.
    /// </summary>
    /// <param name="tower"></param>
    void PreviewTowerRange(string tower)
    {
        float?towerVal     = Towers.instance.GetTowerValue(tower, "attack_range");
        int   range        = 0;
        float heightOffset = 0.05f;
        bool  arc          = false;

        if (towerVal.HasValue)
        {
            range = (int)towerVal.Value;
        }
        towerVal = Towers.instance.GetTowerValue(tower, "projectile_arc");
        if (towerVal.HasValue)
        {
            arc = true;
        }
        towerVal = Towers.instance.GetTowerValue(tower, "projectile_yoff");
        if (towerVal.HasValue)
        {
            heightOffset = towerVal.Value;
        }
        HexHighlighter.ResetGrid();
        Dictionary <string, List <Vector2Int> > hexes = TowerBase.GetHexesInRange(hexHook.transform.position, range, arc, heightOffset);

        if (hexes.ContainsKey("good") && hexes["good"] != null)
        {
            foreach (Vector2Int newPos in hexes["good"])
            {
                if (!MyMath.IsWithin(newPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(newPos.y, -1, TerrainGen.gridZ))
                {
                    continue;
                }
                if (newPos != TerrainGen.GetGridPosition2D(hexHook.transform.position))
                {
                    HexHighlighter.Set(newPos, HexHighlight.positive);
                }
            }
        }
        if (hexes.ContainsKey("bad") && hexes["bad"] != null)
        {
            foreach (Vector2Int newPos in hexes["bad"])
            {
                if (!MyMath.IsWithin(newPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(newPos.y, -1, TerrainGen.gridZ))
                {
                    continue;
                }
                HexHighlighter.Set(newPos, HexHighlight.negative);
            }
        }
    }
 public static void ShowEdgeHexes()
 {
     foreach (Vector2Int hex in edgeHexes)
     {
         if (GetHex(hex.x, hex.y).edge == EdgeType.outter)
         {
             HexHighlighter.Set(hex, HexHighlight.height_0);
         }
         else
         {
             HexHighlighter.Set(hex, HexHighlight.height_6);
         }
     }
 }
    public static void ShowOnGrid(PathType type)
    {
        if (!generated)
        {
            return;
        }
        PathNode node;
        Vector3  facingDir;

        for (int x = 0; x < TerrainGen.gridX; x++)
        {
            for (int z = 0; z < TerrainGen.gridZ; z++)
            {
                node = pathGrids[type][x, z];
                if (node != null && node.target != null)
                {
                    Vector3 nodePos   = TerrainGen.GetHexPosition(node.positionVec);
                    Vector3 targetPos = TerrainGen.GetHexPosition(node.targetVec);
                    nodePos.y   = 0;
                    targetPos.y = 0;
                    facingDir   = targetPos - nodePos;
                    if (facingDir.z > 0)
                    {
                        if (facingDir.x > 0)
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_1);
                        }
                        else
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_2);
                        }
                    }
                    else if (facingDir.z < 0)
                    {
                        if (facingDir.x > 0)
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_5);
                        }
                        else
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_4);
                        }
                    }
                    else if (facingDir.x > 0)
                    {
                        if (facingDir.z == 0)
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_0);
                        }
                    }
                    else if (facingDir.x < 0)
                    {
                        if (facingDir.z == 0)
                        {
                            HexHighlighter.Set(new Vector2Int(x, z), HexHighlight.arrow_3);
                        }
                    }
                }
            }
        }


        //
        HexHighlighter.showingType = GridType.path;
    }