コード例 #1
0
ファイル: TetrisPiece.cs プロジェクト: clifordunique/TetriX3D
 public void Reset(TemplatePiece template)
 {
     color    = template.color;
     bulkSize = (int)Mathf.Sqrt(template.shape.Length);
     for (int y = 0; y < bulkSize; y++)
     {
         for (int x = 0; x < bulkSize; x++)
         {
             shape[x, y] = template.shape[x, y];
         }
     }
 }
コード例 #2
0
 private void InitializeTemplatePiecesFromPrefabs()
 {
     templatePieces = new TemplatePiece[templatePrefabs.Length];
     for (int i = 0; i < templatePieces.Length; i++)
     {
         var template = templatePrefabs[i];
         int bulkSz   = template.childCount;
         templatePieces[i].shape = new bool[bulkSz, bulkSz];
         for (int y = 0; y < bulkSz; y++)
         {
             for (int x = 0; x < bulkSz; x++)
             {
                 Transform cell = template.GetChild(x).GetChild(y);
                 if (cell.localScale.x > .95f) //smaller cells represent empty space within the bulk
                 {
                     templatePieces[i].shape[x, y] = true;
                     templatePieces[i].color       = cell.GetComponent <MeshRenderer>().sharedMaterial.color;
                 }
             }
         }
     }
 }
コード例 #3
0
    private void DisplayNextPiece(TemplatePiece nextPiece)
    {
        for (int y = 0; y < maxBulkSize; y++)
        {
            for (int x = 0; x < maxBulkSize; x++)
            {
                slots[x, y].enabled = false;
            }
        }

        int N = (int)Mathf.Sqrt(nextPiece.shape.Length);

        for (int y = 0; y < N; y++)
        {
            for (int x = 0; x < N; x++)
            {
                if (nextPiece.shape[x, y])
                {
                    slots[x, y].enabled        = true;
                    slots[x, y].material.color = nextPiece.color;
                }
            }
        }
    }