示例#1
0
    // Start is called before the first frame update
    void Start()
    {
        hexSphere = new HexSphere(subdivisions, transform.position, edgeLength);

        hexSphere.RenderSphere(transform, hexagonOutline, pentagonOutline);
        CameraHider.sphere = hexSphere;
    }
示例#2
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);
                }
            }
        }
    }
示例#3
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);
    }