Exemple #1
0
    public void Update()
    {
        if (Input.GetMouseButton(0))
        {
            RaycastHit hit;
            if (!Physics.Raycast(_mainCamera.ScreenPointToRay(Input.mousePosition), out hit))
            {
                return;
            }

            MeshCollider meshCollider = hit.collider as MeshCollider;
            if (meshCollider == null || meshCollider.sharedMesh == null)
            {
                return;
            }

            Mesh      mesh      = meshCollider.sharedMesh;
            int[]     triangles = mesh.triangles;
            Color32[] colors32  = mesh.colors32;

            // search for the Polygon object representing the clicked triangle among
            // the land polygons of the planet.
            Polygon hitPoly = PolySet.FindPolyInPolyset(hit.triangleIndex, _planet);

            // if the Polygon object is not a land polygon
            if (hitPoly == null || hitPoly.m_territory == Territory.RedClan)
            {
                return;
            }

            // Change the color of the clicked triangle
            ColorTriangle(triangles, hit.triangleIndex, ref colors32, Clan.RedClan);

            // Make sure we update the color and territory properties of the hit polygon
            hitPoly.UpdateClan(Clan.RedClan);

            // See if a zone has been circled
            LookForCircledZonesInNeighbors(hitPoly, triangles, ref colors32);

            mesh.colors32 = colors32;
        }
    }