// Update is called once per frame
    void Update()
    {
        float objectRelativeAltitude = attachedObject.position.y - HexMapUI.currentUIMapAltitude;

        //normal
        Vector3 normal             = (attachedObject.position - centerPoint).normalized;
        Vector3 gridIntercectPoint = centerPoint + (normal * HexMapHelper.GetRadialOffsetFromLevel(HexMapUI.currentUIMapLevel));

        //Set the cylinder position to midway between object and grid
        heightCylinder.transform.position   = (attachedObject.position + gridIntercectPoint) / 2f;
        heightCylinder.transform.localScale = new Vector3(xzScale, xzScale, Vector3.Distance(attachedObject.position, gridIntercectPoint));
        heightCylinder.transform.rotation   = Quaternion.LookRotation(normal);

        //Set the little target sprite to grid height
        baseSprite.transform.position = gridIntercectPoint;
        baseSprite.transform.rotation = Quaternion.LookRotation(normal);
        baseSprite.GetComponent <SpriteRenderer>().color = HexMapUI.GetLevelColor(HexMapUI.currentUIMapLevel);
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (isDirty && tileFootprintObject.GetFootprint() != null)
        {
            List <TileWithLevel> footParts = tileFootprintObject.GetFootprint().GetAllTilesInFootprint();

            if (polygons.Count == 0)
            {
                Initialize(footParts.Count);
            }
            Color meshColor = Color.white;

            for (int footPartIndex = 0; footPartIndex < footParts.Count; footPartIndex++)
            {
                TileWithLevel footPart = footParts[footPartIndex];
                Tile          footTile = HexMapUI.GetHexasphereTile(footPart.position, footPart.level);
                if (footTile != null)
                {
                    Vector3[] vertices = new Vector3[7];
                    vertices[0] = transform.InverseTransformPoint(footTile.center * 2f * HexMapHelper.GetRadialOffsetFromLevel(footPart.level));
                    for (int i = 0; i < footTile.vertices.Length; i++)
                    {
                        vertices[i + 1] = transform.InverseTransformPoint(footTile.vertices[i] * 2f * HexMapHelper.GetRadialOffsetFromLevel(footPart.level));
                    }

                    meshColor = HexMapUI.GetLevelColor(footPart.level);

                    polygons[footPartIndex].SetVertices(vertices);
                    polygons[footPartIndex].SetTriangles(
                        footTile.vertices.Length == 6 ? trianglesHex : trianglesPenta,
                        0);
                    polygons[footPartIndex].SetNormals(normals);
                    polygons[footPartIndex].SetUVs(0, uvs);

                    combineInstances[footPartIndex].mesh = polygons[footPartIndex];
                }
            }

            combinedMesh.CombineMeshes(combineInstances, true, false);
            combinedMesh.RecalculateBounds();

            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            GetComponent <MeshRenderer>().material.color = meshColor;

            isDirty = false;
        }
    }