当前位置: 首页>>代码示例>>C#>>正文


C# TileSet.GetUVForType方法代码示例

本文整理汇总了C#中TileSet.GetUVForType方法的典型用法代码示例。如果您正苦于以下问题:C# TileSet.GetUVForType方法的具体用法?C# TileSet.GetUVForType怎么用?C# TileSet.GetUVForType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileSet的用法示例。


在下文中一共展示了TileSet.GetUVForType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RPlate

    public GameObject RPlate(World world, TileSet tileSet, int i)
    {
        GameObject output = (GameObject)Instantiate(worldPrefab, Vector3.zero, Quaternion.identity);

        MeshFilter myFilter = output.GetComponent<MeshFilter>();
        MeshCollider myCollider = output.GetComponent<MeshCollider>();

        SerializableVector3 origin = world.origin;
        List<Vector3> vertices = new List<Vector3>();
        List<int> triangles = new List<int>();
        List<Vector3> normals = new List<Vector3>();
        List<Vector2> uvs = new List<Vector2>();

        //Switch between UV Modes
        if (hexagonal) //Hexagonal uvs
        {
          //Copypasta from worldrenderer
          float texHeight = tileSet.texture.height;
          float texWidth = tileSet.texture.width;
          //float root3 = Mathf.Sqrt(3);
          float uvTileWidth = tileSet.tileWidth / texWidth;
          float uvTileHeight = tileSet.tileWidth / texHeight;
          float side = uvTileWidth / 2;
          float radius = Mathf.Sqrt((3 * side * side) / 4);

          Vector2 uv0 = new Vector2(side, side),
              uv1 = new Vector2(side, side + side),
              uv2 = new Vector2(side + radius, side + side / 2),
              uv3 = new Vector2(side + radius, side / 2),
              uv4 = new Vector2(side, 0),
              uv5 = new Vector2(side - radius, side / 2),
              uv6 = new Vector2(side - radius, side + side / 2);
          //Generate quadrant
          foreach (HexTile ht in world.tiles)
          {
        if (ht.plate == i)
        {
          IntCoord uvCoord = tileSet.GetUVForType(ht.type);
          //Debug.Log("xCoord: "+ uvCoord.x + "  type: "+ ht.type);
          Vector2 uvOffset = new Vector2(uvCoord.x * uvTileWidth, uvCoord.y * uvTileHeight);

          // Origin point
          int originIndex = vertices.Count;
          vertices.Add(origin);
          uvs.Add(uv0 + uvOffset);
          normals.Add(ht.hexagon.center - origin);

          // Center of hexagon
          int centerIndex = vertices.Count;

          // Triangle 1
          vertices.Add(ht.hexagon.center);
          normals.Add((origin + ht.hexagon.center));
          uvs.Add(uv1 + uvOffset);

          vertices.Add(ht.hexagon.v1);
          normals.Add((origin + ht.hexagon.v1));
          uvs.Add(uv1 + uvOffset);

          vertices.Add(ht.hexagon.v2);
          normals.Add((origin + ht.hexagon.v2));
          uvs.Add(uv2 + uvOffset);

          triangles.Add(centerIndex);
          triangles.Add(vertices.Count - 2);
          triangles.Add(vertices.Count - 1);

          // T2
          vertices.Add(ht.hexagon.v3);
          normals.Add((origin + ht.hexagon.v3));
          uvs.Add(uv3 + uvOffset);

          triangles.Add(centerIndex);
          triangles.Add(vertices.Count - 2);
          triangles.Add(vertices.Count - 1);

          // T3
          vertices.Add(ht.hexagon.v4);
          normals.Add((origin + ht.hexagon.v4));
          uvs.Add(uv4 + uvOffset);

          triangles.Add(centerIndex);
          triangles.Add(vertices.Count - 2);
          triangles.Add(vertices.Count - 1);

          // T4
          vertices.Add(ht.hexagon.v5);
          normals.Add((origin + ht.hexagon.v5));
          uvs.Add(uv5 + uvOffset);

          triangles.Add(centerIndex);
          triangles.Add(vertices.Count - 2);
          triangles.Add(vertices.Count - 1);

          // T5
          vertices.Add(ht.hexagon.v6);
          normals.Add((origin + ht.hexagon.v6));
          uvs.Add(uv6 + uvOffset);

          triangles.Add(centerIndex);
//.........这里部分代码省略.........
开发者ID:beardhero,项目名称:HEX,代码行数:101,代码来源:WorldRenderer.cs


注:本文中的TileSet.GetUVForType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。