Beispiel #1
0
    public void UpdateInBaseTiles()
    {
        foreach (var tile in HexMapManager.GetInstance().tiles.Values)
        {
            HexTile platform = tile.GetComponent <HexTile>();
            platform.inBase = false;
        }

        float   range          = 3.5f;
        float   verticalHeight = HexMapManager.GetInstance().HEIGHT_CAP;
        Vector3 capsuleOffset  = new Vector3(0, verticalHeight + range, 0);

        Collider[] colliders = Physics.OverlapCapsule(this.transform.position + capsuleOffset, this.transform.position - capsuleOffset, range);
        foreach (var collider in colliders)
        {
            HexTile platform = collider.GetComponent <HexTile>();
            if (platform != null)
            {
                platform.inBase = true;
            }
        }

        foreach (var tile in HexMapManager.GetInstance().tiles.Values)
        {
            HexTile platform = tile.GetComponent <HexTile>();
            platform.UpdateBorder();
        }
    }
Beispiel #2
0
    void UpdateScreenFocus()
    {
        // if(PlatformManager.GetInstance().selectedPlatform)
        // {
        //     focalPoint = PlatformManager.GetInstance().selectedPlatform.transform.position;
        // }

        zoomProgress = Mathf.Clamp(zoomProgress + Input.mouseScrollDelta.y / 100, 0, 1);

        float   avgTileHeight        = (HexMapManager.GetInstance().HEIGHT_CAP + HexMapManager.GetInstance().HEIGHT_FLOOR) / 2;
        float   height               = Mathf.Lerp(minHeight, maxHeight, zoomProgress);
        float   angle                = Mathf.Lerp(minAngle, maxAngle, zoomProgress);
        float   angleInRadians       = (90 - angle) * Mathf.PI / 180;
        float   deltaAngle           = angle - Camera.main.transform.rotation.eulerAngles.x;
        float   oppositeOverAdjacent = Mathf.Tan(angleInRadians);
        float   horOffset            = oppositeOverAdjacent * height;
        Vector3 cameraOffset         = new Vector3(-horOffset, 0, 0);
        Vector3 targetPosition       = focalPoint + new Vector3(horOffset, height + avgTileHeight, 0);
        Vector3 delta                = targetPosition - Camera.main.transform.position;

        float speed = 8;

        if (_isManualPanning)
        {
            Camera.main.transform.position += delta;
            Camera.main.transform.rotation  = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.x + deltaAngle, Camera.main.transform.rotation.eulerAngles.y, Camera.main.transform.rotation.eulerAngles.z);
        }
        else
        {
            Camera.main.transform.position += delta * Time.deltaTime * speed;
            Camera.main.transform.rotation  = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.x + deltaAngle * Time.deltaTime * speed, Camera.main.transform.rotation.eulerAngles.y, Camera.main.transform.rotation.eulerAngles.z);
        }
    }
    public bool CanBuild(BuildingMetaData buildingMetaData, Vector2Int coord)
    {
        GameObject tileGameObject = HexMapManager.GetInstance().TileAtCoordinate(coord);
        HexTile    tile           = tileGameObject.GetComponent <HexTile>();

        if (tile == null || buildingMetaData == null || !tile.inBase)
        {
            return(false);
        }

        return(buildingMetaData.CanBuildOn(tile.id));
    }
Beispiel #4
0
    public void MoveTo(Vector2Int targetCoord)
    {
        _movementProgress = 0;
        Vector3 targetPos            = Hexagon.PositionForCoordinate(targetCoord);
        float   height               = HexMapManager.GetInstance().HeightMap(targetCoord) / 2 + this.transform.localScale.y;
        float   radialOffsetDistance = 0.6f;
        // float randomAngle = Random.Range(0,359);
        // Debug.Log(randomAngle);
        // Vector3 randomOffset = Quaternion.Euler(0, randomAngle, 0) * new Vector3(1,0,0) * radialOffsetDistance;

        Vector3 offCenterOffset = -Vector3.Scale((targetPos - this.transform.position).normalized, new Vector3(1, 0, 1)).normalized *radialOffsetDistance;

        target = new Vector3(targetPos.x, height, targetPos.z) + offCenterOffset;
    }
Beispiel #5
0
    public void UpdateBorder()
    {
        Mesh border = new Mesh();

        this.transform.GetChild(0).GetComponent <MeshFilter>().mesh = border;
        if (!inBase)
        {
            return;
        }


        float width = Hexagon.HEXAGON_FLAT_WIDTH;

        Vector3[] vertices  = new Vector3[24];
        int[]     triangles = new int[36];

        for (int i = 0; i < 6; i++)
        {
            Vector2Int neighbourCoord          = Hexagon.NeighbourAtIndex(this.coordinate, i);
            GameObject neighbourTileGameObject = HexMapManager.GetInstance().TileAtCoordinate(neighbourCoord);
            if (neighbourTileGameObject != null && neighbourTileGameObject.GetComponent <HexTile>().inBase)
            {
                continue;
            }
            Vector3[] outer = Hexagon.FlatEdgeVertexPositions(width, i * 60 + 60);
            // Vector3[] inner = Hexagon.FlatEdgeVertexPositions(width-0.4f, i*60 + 60);
            Vector3[] inner = Hexagon.WideFlatEdgeVertexPositions(width, width - 0.4f, i * 60 + 60);

            outer.CopyTo(vertices, i * 4);
            inner.CopyTo(vertices, i * 4 + 2);

            triangles[i * 6]     = i * 4;
            triangles[i * 6 + 1] = i * 4 + 1;
            triangles[i * 6 + 2] = i * 4 + 3;
            triangles[i * 6 + 3] = i * 4 + 0;
            triangles[i * 6 + 4] = i * 4 + 3;
            triangles[i * 6 + 5] = i * 4 + 2;
        }

        border.vertices  = vertices;
        border.triangles = triangles;
        border.RecalculateNormals();
    }
Beispiel #6
0
    public void Purchase(BuildingMetaData item, Vector2Int coord)
    {
        if (HexMapManager.GetInstance().TileAtCoordinate(coord) == null)
        {
            Debug.LogError("Tried to purchase but no target platform");
            return;
        }

        if (!Player.GetInstance().CanAfford(item.costs))
        {
            return;
        }

        // GameObject platform = BuildingsManager.GetInstance().Build(item, coord);
        Builder.GetInstance().Build(item, coord);

        // if(platform != null) {
        //     Player.GetInstance().TransactCosts(item.costs);
        // }
    }
    private GameObject BuildBuilding(BuildingMetaData metaData, Vector2Int coordinate)
    {
        GameObject tile = HexMapManager.GetInstance().TileAtCoordinate(coordinate);

        bool isUpgrade = false;

        Building oldBuilding = BuildingAtCoordinate(coordinate);

        if (oldBuilding != null)
        {
            //check upgrade
            if (oldBuilding.metaData.id == metaData.id)
            {
                //is upgrade
                isUpgrade = true;
            }
            else
            {
                Debug.LogError("Cannot build: already have building here");
                return(null);
            }
        }

        GameObject buildingObject    = GameObject.Instantiate(metaData.prefab, tile.transform.position, tile.transform.rotation);
        Building   buildingComponent = buildingObject.GetComponent <Building>();

        buildingComponent.Initialize(metaData, coordinate);

        if (isUpgrade)
        {
            buildingComponent.UpgradeHandoverFrom(oldBuilding);
            buildings.Remove(coordinate);
            GameObject.Destroy(oldBuilding.gameObject);
        }

        buildings.Add(coordinate, buildingComponent);
        RecalculateResources();

        InfoDetail.GetInstance().LoadData(buildingComponent);
        return(buildingObject);
    }
Beispiel #8
0
 HexMapManager()
 {
     _singleton = this;
 }
Beispiel #9
0
 // Use this for initialization
 void Start()
 {
     oldPosition = this.transform.position;
     HexMap      = GameObject.Find("Managers").GetComponent <HexMapManager>();
     mouseMan    = GameObject.Find("Managers").GetComponent <MouseManager>();
 }