Exemplo n.º 1
0
 void UpdateGrid(Vector3 gridPos = new Vector3())
 {
     if (TerrainGen.mapGenState == MapGen.done)
     {
         if (gridPos != Vector3.zero)
         {
             PathKeeper.pathKeeper.RecalcArea(PathType.normal, TerrainGen.GetGridPosition(hexHook.transform.position), 5, true);
         }
         TowerBase.UpdateTowerHexes();
     }
 }
Exemplo n.º 2
0
    private void OnGUI()
    {
        if (debugCostText)
        {
            Ray        ray = MouseHook.mousehook.GetCamera().ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Physics.Raycast(ray, out hit);
            if (hit.collider != null)
            {
                Vector3Int hookPos = TerrainGen.GetGridPosition(hit.point);
                Vector2Int tilePos = Vector2Int.zero;
                tilePos.x = hookPos.x;
                tilePos.y = hookPos.z;
                List <Vector2Int> showHexes = TerrainGen.GetHexOffSetInRange(tilePos, 5);
                Vector2Int        drawPos;
                string            val;
                foreach (Vector2Int hex in showHexes)
                {
                    Handles.color = Color.red;
                    drawPos       = hex + tilePos;
                    PathNode node = pathGrids[PathType.normal][drawPos.x, drawPos.y];
                    val = "" + node.cost.Value;
                    Handles.Label(TerrainGen.GetHexPosition(drawPos.x, drawPos.y), "" + val);
                    Vector3 drawEnd = TerrainGen.GetHexPosition(node.from);

                    if (node.from != Vector2Int.zero)
                    {
                        Vector3    angle  = -MyMath.GetDirectionRatio(TerrainGen.GetHexPosition(drawPos), drawEnd);
                        Quaternion lookat = Quaternion.LookRotation(angle, Vector3.up);
                        Handles.ArrowHandleCap(0, TerrainGen.GetHexPosition(drawPos), lookat, TerrainGen.hexSize, EventType.Repaint);
                    }
                    drawEnd = TerrainGen.GetHexPosition(node.target);
                    if (node.target != Vector2Int.zero)
                    {
                        Handles.color = Color.blue;
                        Vector3    angle     = -MyMath.GetDirectionRatio(TerrainGen.GetHexPosition(drawPos), drawEnd);
                        Quaternion lookat    = Quaternion.LookRotation(angle, Vector3.up);
                        Vector3    drawStart = TerrainGen.GetHexPosition(drawPos);
                        drawStart.y += 0.01f;
                        Handles.ArrowHandleCap(1, drawStart, lookat, TerrainGen.hexSize, EventType.Repaint);
                    }
                }
            }
        }
    }
Exemplo n.º 3
0
    public static Dictionary <string, List <Vector2Int> > GetHexesInRange(Vector3 position, int range, bool arc = false, float offSet = 0.05f)
    {
        Dictionary <string, List <Vector2Int> > hexesInRange;

        hexesInRange = new Dictionary <string, List <Vector2Int> >();

        List <Vector2Int> hexInRange   = new List <Vector2Int>();
        List <Vector2Int> goodHexes    = new List <Vector2Int>();
        List <Vector2Int> blockedHexes = new List <Vector2Int>();
        Vector3Int        hexPos       = TerrainGen.GetGridPosition(position);
        Vector2Int        gridPos      = new Vector2Int(hexPos.x, hexPos.z);

        hexInRange = TerrainGen.GetHexInRange(gridPos, range);
        Vector3 towerPos = position;

        towerPos.y += offSet;

        foreach (Vector2Int newPos in hexInRange)
        {
            if (!MyMath.IsWithin(hexPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(hexPos.y, -1, TerrainGen.gridZ))
            {
                continue;
            }
            RaycastHit[] hits;
            bool         good = false;
            BuildingBase building;
            Vector3      castPos = TerrainGen.GetHexPosition(newPos.x, newPos.y);
            if (position.y > TerrainGen.GetHexHeight(newPos))
            {
                castPos.y += 0.25f;
            }
            else
            {
                castPos.y += 0.05f;
            }
            if (!arc)
            {
                //Physics.RayC
                float   lineLenght = Vector3.Distance(towerPos, castPos);
                Vector3 faceDir    = MyMath.GetDirectionRatio(towerPos, castPos);
                hits = Physics.RaycastAll(towerPos, -faceDir, lineLenght);
                good = true;
                foreach (RaycastHit hit in hits)
                {
                    building = hit.transform.GetComponentInParent <BuildingBase>();
                    if (building != null)
                    {
                        if (!building.Ethereal)
                        {
                            good = false;
                        }
                    }
                    else
                    {
                        good = false;
                    }
                }
                if (good)
                {
                    goodHexes.Add(newPos);
                }
                else
                {
                    blockedHexes.Add(newPos);
                }
            }
            else
            {
                goodHexes.Add(newPos);
            }
        }
        hexesInRange.Add("good", goodHexes);
        hexesInRange.Add("bad", blockedHexes);

        return(hexesInRange);
    }
Exemplo n.º 4
0
    void MoveCamera()
    {
        if (Input.GetAxisRaw("Horizontal") > 0 || (Input.mousePosition.x > Screen.width - scrollBorder && Input.mousePosition.x < Screen.width + overBorder))
        {
            camHandle.transform.Translate(new Vector3(panSpeed, 0, 0), Space.Self);
        }
        else if (Input.GetAxisRaw("Horizontal") < 0 || (Input.mousePosition.x < scrollBorder && Input.mousePosition.x + overBorder > 0))
        {
            camHandle.transform.Translate(new Vector3(-panSpeed, 0, 0), Space.Self);
        }
        if (Input.GetAxisRaw("Vertical") > 0 || (Input.mousePosition.y > Screen.height - scrollBorder && Input.mousePosition.y < Screen.height + overBorder))
        {
            Quaternion saveRotation  = camHandle.transform.rotation;
            Quaternion rotation      = camHandle.transform.rotation;
            Vector3    eulerRotation = rotation.eulerAngles;
            eulerRotation.x = 0;
            if (eulerRotation.z != 0)
            {
                eulerRotation.y += eulerRotation.z;
                eulerRotation.z  = 0;
            }
            rotation.eulerAngles = eulerRotation;

            camHandle.rotation = rotation;
            camHandle.transform.Translate(new Vector3(0, 0, panSpeed), Space.Self);
            camHandle.rotation = saveRotation;
        }
        else if (Input.GetAxisRaw("Vertical") < 0 || (Input.mousePosition.y < scrollBorder && Input.mousePosition.y + overBorder > 0))
        {
            Quaternion saveRotation  = camHandle.transform.rotation;
            Quaternion rotation      = camHandle.transform.rotation;
            Vector3    eulerRotation = rotation.eulerAngles;
            eulerRotation.x = 0;
            if (eulerRotation.z != 0)
            {
                eulerRotation.y += eulerRotation.z;
                eulerRotation.z  = 0;
            }
            rotation.eulerAngles = eulerRotation;

            camHandle.rotation = rotation;
            camHandle.transform.Translate(new Vector3(0, 0, -panSpeed), Space.Self);
            camHandle.rotation = saveRotation;
        }
        Vector3 pos   = camHandle.position;
        float   lastY = pos.y;

        pos.y = TerrainGen.GetHexHeight(TerrainGen.GetGridPosition(pos));
        if (pos.y == -1)
        {
            pos.y = lastY;
        }
        camHandle.transform.position = pos;



        if (mouseCheck[2] != 0)
        {
            if (mouseCheck[2] > 0)
            {
                gameCam.transform.Translate(new Vector3(0, 0, panSpeed), Space.Self);
            }
            else
            {
                gameCam.transform.Translate(new Vector3(0, 0, -panSpeed), Space.Self);
            }
            //

            Vector3 camPos = gameCam.transform.localPosition;
            camPos.z = Mathf.Clamp(camPos.z, -40, -2.5f);
            camPos.y = Mathf.Clamp(camPos.y, 5f, 20);
            gameCam.transform.localPosition = camPos;
        }

        Vector3 menuPos = GetScreenPosition(hexHook.transform.position);

        menuPos.x += 60;
        triMenu.PlaceMenu(menuPos);
        Vector2 detailPos = GetScreenPosition(hexHook.transform.position);

        detailPos.x -= 120;
        triMenu.hexDetails.SetPosition(detailPos);
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (mapGenState == MapGen.terrain)
        {
            Texture2D featureMap;
            foreach (NoiseMap noiseMap in noiseMaps)
            {
                noiseMap.offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000));
                CalcNoise(noiseMap);
            }
            featureMap = shapeGenerator.GenerateClipMap();
            shapeGenerator.GenerateLake(featureMap, 3);
            shapeGenerator.GenerateForests(featureMap, 7);
            noiseTex = new Texture2D(gridX, gridZ);
            CombineTextures(noiseTex, noiseMaps);
            ClipTexture(noiseTex, featureMap, Color.white);
            GenHexGrid(gridX, gridY, gridZ);
            CombineMeshes(20, 20);
            navMesh.BuildNavMesh();
            FillDoodads(featureMap);
            CalcEdgeHexes(25);
            SpreadOutterEdges(5);
            Vector3 camPos = GetHexPosition((int)(gridX / 2), (int)(gridZ / 2));
            camPos.y = 5f;
            camHandle.transform.position = camPos;
            mapGenState = MapGen.terrainCon;
            HexHighlighter.CreateGrid(gridX, gridZ, highlightFab, highlighters);
            ShowEdgeHexes();
            if (debug)
            {
                Vector3 goalPos = Vector3.zero;
                while (goalPos == Vector3.zero)
                {
                    Vector2Int gridPos = Vector2Int.zero;
                    gridPos.x = Random.Range(0, gridX - 1);
                    gridPos.y = Random.Range(0, gridZ - 1);
                    if (GetHex(gridPos.x, gridPos.y) != null)
                    {
                        goalPos = GetHexPosition(gridPos);
                    }
                }
                GameObject debugGoal = new GameObject();
                debugGoal.transform.position = goalPos;
                MobLister.MakeModGrid(gridX, gridZ);
                pathKeeper.GeneratePath(PathType.normal, TerrainGen.GetGridPosition(debugGoal.transform.position));
                PathKeeper.goal  = debugGoal.transform.position;
                mapGenState      = MapGen.done;
                terrainGenerated = true;
                MobSpawner.GetSpawners()[0].MakeReady(debugGoal);
            }

            //
            //
        }
        else if (mapGenState == MapGen.pathing)
        {
            MobLister.MakeModGrid(gridX, gridZ);
            pathKeeper.GeneratePath(PathType.normal, TerrainGen.GetGridPosition(goal.transform.position));
            mapGenState      = MapGen.done;
            terrainGenerated = true;
            MobSpawner.GetSpawners()[0].MakeReady(goal);
        }
    }