Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        HexSphere hexSphere  = sphere.GetSphere();
        Icosphere gameSphere = hexSphere.GetHexMap();

        if (gameSphere == null)
        {
            return;
        }

        if (Input.GetButtonDown("Select"))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("Sphere")))
            {
                if (outlineHighlight != null)
                {
                    GameObject.Destroy(outlineHighlight);
                }

                GameObject obj = hit.collider.gameObject;

                HexIdentifier hex = obj.GetComponent <HexIdentifier>();

                if (hex != null)
                {
                    selected = hex.location;

                    float rad = gameSphere.Radius;

                    gameSphere.SetRadius(rad + 0.001f);

                    outlineHighlight = new GameObject();

                    outlineHighlight.transform.position += sphere.transform.position;
                    outlineHighlight.transform.Rotate(sphere.transform.eulerAngles);

                    outlineHighlight.name = "Outline Highlight";
                    MeshFilter   mf = outlineHighlight.AddComponent <MeshFilter>();
                    MeshRenderer mr = outlineHighlight.AddComponent <MeshRenderer>();
                    mr.material = new Material(Shader.Find("Transparent/Diffuse"));

                    HexSphere.RenderTile(mf.mesh, selected, gameSphere);

                    if (new List <SCoord>(gameSphere.GetNeighbors(selected)).Count == 5)
                    {
                        mr.material.SetTexture("_MainTex", pentHighlight);
                    }
                    else
                    {
                        mr.material.SetTexture("_MainTex", hexHighlight);
                    }

                    gameSphere.SetRadius(rad);
                }
            }
        }
    }
Esempio n. 2
0
    public HexSphere(int subdivisions, Vector3 center, float edgeLength)
    {
        tileMap = new Dictionary <SCoord, GameObject>();

        // Make and subdivide the icosphere
        hexSphere = new Icosphere(center, 1);
        for (int sub = 0; sub < subdivisions; sub++)
        {
            hexSphere = hexSphere.SubdivideSphere();
        }

        // Scale the spehres
        float sf = HexSphere.GetScaleFactor(hexSphere, edgeLength);

        hexSphere.SetRadius(sf);
    }