Пример #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);
                }
            }
        }
    }
Пример #2
0
        // Update is called once per frame
        void Update()
        {
            if (sphere == null)
            {
                return;
            }

            foreach (MeshRenderer ren in previousSet)
            {
                ren.enabled = false;
            }

            //Debug.DrawRay(viewCamera.transform.position, viewCamera.transform.forward.normalized * 20, Color.red);
            RaycastHit hit;

            if (Physics.Raycast(viewCamera.transform.position, viewCamera.transform.forward, out hit, Mathf.Infinity, LayerMask.GetMask("Sphere")))
            {
                hit.collider.gameObject.GetComponent <MeshRenderer>().enabled = true;
                HashSet <MeshRenderer> currentObjects = new HashSet <MeshRenderer>();

                HashSet <SCoord>    foundCoordinates = new HashSet <SCoord>();
                LinkedList <SCoord> coordinates      = new LinkedList <SCoord>();
                LinkedList <int>    distances        = new LinkedList <int>();
                coordinates.AddLast(hit.collider.gameObject.GetComponent <HexIdentifier>().location);
                distances.AddLast(0);

                while (coordinates.Count > 0)
                {
                    SCoord coord    = coordinates.First.Value;
                    int    distance = distances.First.Value;
                    coordinates.RemoveFirst();
                    distances.RemoveFirst();

                    if (foundCoordinates.Contains(coord))
                    {
                        continue;
                    }
                    foundCoordinates.Add(coord);
                    if (distance > hexRadius)
                    {
                        continue;
                    }

                    currentObjects.Add(sphere.GetTile(coord).GetComponent <MeshRenderer>());

                    foreach (SCoord adj in sphere.GetHexMap().GetNeighbors(coord))
                    {
                        coordinates.AddLast(adj);
                        distances.AddLast(distance + 1);
                    }
                }

                foreach (MeshRenderer ren in currentObjects)
                {
                    ren.enabled = true;
                }
                previousSet = currentObjects;
            }
            else
            {
                previousSet = new HashSet <MeshRenderer>();
            }
        }