示例#1
0
    void BuildPort(Region r)
    {
        Vector2Int loc = r.GetPortPosition();
        Vector2    rot = Vector2.zero;
        int        n   = 0;

        if (MapMetrics.InsideMap(loc.y, loc.x) && regions[regionIndex[loc.y, loc.x]].iswater)
        {
            n++; rot += new Vector2(1, 1);
        }
        if (MapMetrics.InsideMap(loc.y, loc.x - 1) && regions[regionIndex[loc.y, loc.x - 1]].iswater)
        {
            n++; rot += new Vector2(-1, 1);
        }
        if (MapMetrics.InsideMap(loc.y - 1, loc.x) && regions[regionIndex[loc.y - 1, loc.x]].iswater)
        {
            n++; rot += new Vector2(1, -1);
        }
        if (MapMetrics.InsideMap(loc.y - 1, loc.x - 1) && regions[regionIndex[loc.y - 1, loc.x - 1]].iswater)
        {
            n++; rot += new Vector2(-1, -1);
        }
        // rot /= n;
        Port port = Instantiate(PrefabHandler.GetPort(r.owner.fraction), Ports);

        port.transform.position = MapMetrics.PerturbedCorner(loc);
        port.transform.rotation = Quaternion.Euler(0, Vector2.SignedAngle(rot, new Vector2(0, -1)), 0);
        port.CornerPosition     = loc + rot.normalized * 0.5f;
        port.Region             = r;
        r.Port = port;
        port.gameObject.SetActive(false);
    }
示例#2
0
    public void TriangulateMap(int x0, int y0)
    {
        List <int>     triangles = new List <int>();
        List <Vector2> uvs = new List <Vector2>(), uvs1 = new List <Vector2>();
        List <Vector3> vertices = new List <Vector3>();

        for (int i = y0; i < y0 + tile + 1; i++)
        {
            for (int j = x0; j < x0 + tile + 1; j++)
            {
                uvs.Add(new Vector2(1f * j / MapMetrics.SizeM, 1f * i / MapMetrics.SizeN));
                Vector3 v = MapMetrics.PerturbedCorner(new Vector2Int(j, i));
                Navigation.field[i + y0, j + x0] = new Vector2(v.x, v.z);
                vertices.Add(new Vector3(v.x, v.y, v.z));
                uvs1.Add(new Vector2(v.x, v.z));
            }
        }
        for (int i = 0; i < tile; i++)
        {
            for (int j = 0; j < tile; j++)
            {
                int a = i * (tile + 1) + j;
                int b = a + tile + 1;
                triangles.Add(a);
                triangles.Add(b);
                triangles.Add(b + 1);

                triangles.Add(b + 1);
                triangles.Add(a + 1);
                triangles.Add(a);
            }
        }
        mapMesh.SetVertices(vertices);
        mapMesh.SetUVs(0, uvs);
        mapMesh.SetUVs(1, uvs1);
        mapMesh.SetTriangles(triangles, 0);
        ListPool <Vector3> .Add(vertices);

        ListPool <int> .Add(triangles);

        ListPool <Vector2> .Add(uvs);

        ListPool <Vector2> .Add(uvs1);

        mapMesh.RecalculateNormals();
        mapMesh.RecalculateBounds();
        GetComponent <MeshCollider>().sharedMesh = mapMesh;
    }