2016-05-08 4 views
0

私はこのループを使用してピクセルを設定するために使用していますが、何らかの理由でそれがいくつかの時間しか働いていないと考えることはできません。時々それは完全にテクスチャを生み出しますが、それ以外のときは混乱したラインが混乱しています。何が間違っていますか?テクスチャのみカラーを使用してコンパイルする場合があります

void texRend() 
{ 
    GameObject parentGameObject = new GameObject("SpaceStation"); 

    int tileRow = 0; 
    int tileCol = 0; 

    GameObject floorQuad = GameObject.CreatePrimitive(PrimitiveType.Quad); 

    floorQuad.transform.localScale = new Vector3(stationWidth*1.28f,stationHeight*1.28f,1); 
    floorQuad.transform.parent = parentGameObject.transform; 
    floorQuad.transform.position = new Vector3(0.0f, 0.0f, 0.0f); 

    Color transparent = new Color(0,0,0,0); 

    Texture2D floorTex = new Texture2D(stationWidth*256, stationHeight*256, TextureFormat.ARGB32, false); 

    Color[] floorArray = new Color[stationWidth*256*stationHeight*256]; 

    int k = 0; 

    for(int row = 0; row < stationWidth*256; row++) 
    { 
     for(int col = 0; col < stationHeight*256; col++) 
     { 
      tileRow = Mathf.FloorToInt(row/256); 
      tileCol = Mathf.FloorToInt(col/256); 

      float prow = ((float)tileRow/(float)stationWidth)*scale; 
      float pcol = ((float)tileCol/(float)stationHeight)*scale; 

      if(roomType[tileRow, tileCol] != (int)room.None && roomType[tileRow, tileCol] != (int)room.Corridor) 
      { 
       int tileNumber = Mathf.Abs(Mathf.RoundToInt(Mathf.PerlinNoise(prow,pcol)*baseSprites.Length)%baseSprites.Length); 
       floorArray[k] = baseSprites[tileNumber].texture.GetPixel(row%256, col%256); 
      } 
      else if(roomType[tileRow, tileCol] == (int)room.Corridor) 
      { 
       if(connections[tileRow,tileCol] == (int)connect.NESW) 
       { 
        floorArray[k] = corridorFloorNESW.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.NS) 
       { 
        floorArray[k] = corridorFloorNS.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.EW) 
       { 
        floorArray[k] = corridorFloorEW.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.NE) 
       { 
        floorArray[k] = corridorFloorNE.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.NW) 
       { 
        floorArray[k] = corridorFloorNW.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.SE) 
       { 
        floorArray[k] = corridorFloorSE.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.SW) 
       { 
        floorArray[k] = corridorFloorSW.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.WNE) 
       { 
        floorArray[k] = corridorFloorWNE.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.NES) 
       { 
        floorArray[k] = corridorFloorNES.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.ESW) 
       { 
        floorArray[k] = corridorFloorESW.texture.GetPixel(row%256, col%256); 
       } 
       if(connections[tileRow,tileCol] == (int)connect.SWN) 
       { 
        floorArray[k] = corridorFloorSWN.texture.GetPixel(row%256, col%256); 
       } 
      } 

      k++; 
     } 

    } 

    floorTex.SetPixels(floorArray); 
    floorTex.Apply(); 
    //attach texture to quad 
    floorQuad.GetComponent<Renderer>().material.mainTexture = floorTex; 
    floorQuad.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Diffuse"); 

    byte[] bytes = floorTex.EncodeToPNG(); 
    File.WriteAllBytes(Application.dataPath + "/../floorTexture.png", bytes); 

} 

OKは、倍の負荷これを実行した後、テクスチャが正方形であるとき、それが唯一の正しいテクスチャを生成ようです。ダイナミックなオフセットが必要だと思います。

What it looks like when working Not working

答えて

0

は私が行うために必要なすべてのループの行とCOLの周りの変化であったし、それは完全に働いたが判明します!私は、テクスチャが間違っていることをかなり間違ってしまうことが予想されませんでした。

関連する問題