COLS









How do I use C O L S
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Board.cs Copy
40         public void Clear()
41         {
42             for (int row = 0; row < ROWS; row++)
43             {
44                 for (int col = 0; col < COLS; col++)
45                 {
46                     cells[row, col].Clear();
47                 }
48             }
49
50             lastChangedCell = null;
51         }
File name: Board.cs Copy
53         public bool IsDraw()
54         {
55             for (int row = 0; row < ROWS; row++)
56             {
57                 for (int col = 0; col < COLS; col++)
58                 {
59                     if (cells[row, col].Content == Seed.Empty)
60                     {
61                         return false;
62                     }
63                 }
64             }
65
66             return true;
67         }
File name: Board.cs Copy
128         private void CreateCells()
129         {
130             Transform container = (new GameObject("Cells")).transform;
131
132             container.transform.parent = transform;
133             container.transform.localPosition = new Vector3(-cellOffset, -cellOffset, 0f);
134
135             for (int row = 0; row < ROWS; row++)
136             {
137                 for (int col = 0; col < COLS; col++)
138                 {
139                     GameObject go = (GameObject)Instantiate(cellPrefab, Vector3.zero, Quaternion.identity);
140                     Cell cell = go.GetComponent();
141
142                     cell.transform.parent = container;
143                     cell.transform.localPosition = new Vector3(col * cellOffset, row * cellOffset, 0f);
144
145                     cell.Init(row, col, OnCellClick);
146
147                     cells[row, col] = cell;
148                 }
149             }
150         }
File name: Grid.cs Copy
34  public int Cols {
35   get {return cols;}
36  }
File name: Grid.cs Copy
44  public bool IsReady {
45   get{
46    for (int row = 0; row < rows; row++) {
47     for (int col = 0; col < cols; col++) {
48      Node node = grid[row,col];
49      if (!node.IsReady) return false;
50     }
51    }
52
53    return true;
54   }
55  }
File name: Grid.cs Copy
57  public int Size {
58   get {
59    return rows * cols;
60   }
61  }
File name: Grid.cs Copy
63  public Node GetNodeAt(int row, int col) {
64   if (row < 0 || row >= rows || col < 0 || col >= cols) return null;
65   return grid[row,col];
66  }
File name: Grid.cs Copy
68  public Node GetNodeAt(Vector3 pos) {
69   pos -= transform.position;
70
71   float percentRow = (pos.z / size.z) + 0.5f;
72   float percentCol = (pos.x / size.x) + 0.5f;
73   percentRow = Mathf.Clamp01(percentRow);
74   percentCol = Mathf.Clamp01(percentCol);
75   int row = Mathf.RoundToInt((rows-1) * percentRow);
76   int col = Mathf.RoundToInt((cols-1) * percentCol);
77
78   return grid[row,col];
79  }
File name: Grid.cs Copy
81  void Awake() {
82   grid = new Node[rows,cols];
83   tileSize = tilePrefab.GetComponent().bounds.size;
84   size = new Vector3(tileSize.x * cols, tileSize.y, tileSize.z * rows);
85   CreateGrid();
86  }
File name: Grid.cs Copy
88  void CreateGrid() {
89   Vector3 bottomLeft = new Vector3(
90     transform.position.x - size.x / 2 + tileSize.x / 2,
91     transform.position.y,
92     transform.position.z - size.z / 2 + tileSize.z / 2);
93   Vector3 startPosition = bottomLeft;
94
95   GameObject tile = tilePrefab;
96
97   for (int row = 0; row < rows; row++) {
98    for (int col = 0; col < cols; col++) {
99     startPosition.z = bottomLeft.z + tileSize.z * row;
100     startPosition.x = bottomLeft.x + tileSize.x * col;
101     GameObject go = Instantiate(tile, startPosition, tile.transform.rotation) as GameObject;
102     Node dn = go.AddComponent();
103     dn.row = row;
104     dn.col = col;
105     dn.rowChess = Converter.ToChessRow(row);
106     dn.colChess = Converter.ToChessCol(col);
107     grid[row,col] = dn;
108     go.transform.parent = transform;
109     go.transform.localScale = Vector3.zero;
110
111     dn.ScaleIn(Random.Range(0f,1f),Random.Range(1f,2f),tile.transform.localScale);
112     tile = SwapTilePrefab(tile);
113    }
114    tile = SwapTilePrefab(tile);
115   }
116
117   StartCoroutine(SpawnPieces());
118  }

COLS 139 lượt xem

Gõ tìm kiếm nhanh...