Exemplo 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);
                }
            }
        }
    }
Exemplo n.º 2
0
    public void RenderSphere(Transform parentObject, Material outlineHex, Material outlinePent)
    {
        int sphereLayer = LayerMask.NameToLayer("Sphere");;

        foreach (SCoord tile in hexSphere.Coordinates)
        {
            // Setup new game object with generated mesh
            GameObject    newTile = new GameObject();
            MeshFilter    mf      = newTile.AddComponent <MeshFilter>();
            MeshRenderer  mr      = newTile.AddComponent <MeshRenderer>();
            MeshCollider  mc      = newTile.AddComponent <MeshCollider>();
            HexIdentifier hider   = newTile.AddComponent <HexIdentifier>();
            //GameObjectUtility.SetStaticEditorFlags(newTile,
            //StaticEditorFlags.OccludeeStatic | StaticEditorFlags.OccluderStatic);

            // Set the standard material shader
            mr.material = new Material(Shader.Find("Diffuse"));

            // Make the mesh and render the tile
            RenderTile(mf.mesh, tile, hexSphere);

            // Move the tile to its new position and rotation
            newTile.transform.position += parentObject.transform.position;
            newTile.transform.Rotate(parentObject.transform.eulerAngles);

            // set hierarchy relationship
            newTile.transform.SetParent(parentObject);

            // Set Name of the tile
            newTile.name = "Lat " + Mathf.Round(tile.GetTheta() * Mathf.Rad2Deg * 100) / 100 +
                           " Lon " + Mathf.Round(tile.GetPhi() * Mathf.Rad2Deg * 100) / 100;

            tileMap[tile] = newTile;

            hider.center   = hexSphere.GetPoint(tile);
            hider.location = tile;

            CameraHider.AddObject(hider);

            newTile.layer = sphereLayer;

            if (hexSphere.GetDegree(tile) == 5)
            {
                mr.material = outlinePent;
            }
            else if (hexSphere.GetDegree(tile) == 6)
            {
                mr.material = outlineHex;
            }

            mc.sharedMesh = mf.mesh;
        }
    }
Exemplo n.º 3
0
 public static void AddObject(HexIdentifier obj)
 {
     objects.Add(obj);
     //obj.GetComponent<MeshRenderer>().enabled = false;
 }