OnCellClick









How do I use On Cell Click
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Board.cs Copy
34         public void SetCell(Seed seed, int row, int col)
35         {
36             SetPlayer(seed);
37             OnCellClick(cells[row, col]);
38         }
File name: Board.cs Copy
114         private void OnCellClick(Cell cell)
115         {
116             if (currentPlayer != Seed.Empty && cell.IsEmpty)
117             {
118                 cell.Set(currentPlayer);
119                 lastChangedCell = cell;
120
121                 if (onBoardChange != null)
122                 {
123                     onBoardChange(currentPlayer, cell.Row, cell.Col);
124                 }
125             }
126         }
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: Cell.cs Copy
22         public void Init(int row, int col, Action onCellClickAction)
23         {
24             Row = row;
25             Col = col;
26
27             name = string.Format("Cell [{0}, {1}]", row, col);
28
29             onCellClick = onCellClickAction;
30
31             Clear();
32         }
File name: Cell.cs Copy
65         public void OnPointerClick(PointerEventData eventData)
66         {
67             if (onCellClick != null)
68             {
69                 onCellClick(this);
70             }
71         }

OnCellClick 121 lượt xem

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