Disassemble Match3 game for Unity, found the code, it works. I saw these lines

//структура описание точки struct Point { public int X, Y; } //список претендентов на уничтожение List<Point> Pretindent = new List<Point>(); //генератор координат которые нужно проверить List<Point> IndexList(Point coord) { //создаем список предпологаемых мест для поиска точки List<Point> P = new List<Point>(); //обьявляем переменную которая будет расчетным буфером для точки Point T; 

Full version of the code

 using UnityEngine; using System.Collections.Generic; public class LoadGame : MonoBehaviour { //эталонный блок для поля public GameObject Box; //размеры поля static int col = 8, row = 8; //карта из блоков GameObject[,] map = new GameObject[col, row]; //структура описание точки struct Point { public int X, Y; } //список претендентов на уничтожение List<Point> Pretindent = new List<Point>(); //генератор координат которые нужно проверить List<Point> IndexList(Point coord) { //создаем список предпологаемых мест для поиска точки List<Point> P = new List<Point>(); //обьявляем переменную которая будет расчетным буфером для точки Point T; //проверяем существует ли вобще точка в том раене где хотим проверять if ((coord.X - 1) >= 0) { //расчитываем координату по Х TX = coord.X - 1; //Расчитываем координату по Y TY = coord.Y; //Добавляем координату в массив P.Add(T); Debug.Log("ss" + T); }; if ((coord.X + 1) < col) { //расчитываем координату по Х TX = coord.X + 1; //Расчитываем координату по Y TY = coord.Y; //Добавляем координату в массив P.Add(T); Debug.Log("ss" + T); }; if ((coord.Y - 1) >= 0) { //расчитываем координату по Х TX = coord.X; //Расчитываем координату по Y TY = coord.Y - 1; //Добавляем координату в массив P.Add(T); Debug.Log("ss" + T); }; if ((coord.Y + 1) < row) { //расчитываем координату по Х TX = coord.X; //Расчитываем координату по Y TY = coord.Y + 1; //Добавляем координату в массив P.Add(T); Debug.Log("ss" + T); }; //возвращаем найденный список точек return P; } void CreateGamePole() { float Dx = 1.2f, Dy = 1.2f; Vector3 MyPoze = new Vector3(-7.6f, -4.35f, 0); for (int YY = 0; YY < row; YY++) { for (int XX = 0; XX < col; XX++) { map[XX, YY] = Instantiate(Box, MyPoze, Quaternion.identity) as GameObject; ; //получаем параметры блока MyPoze.x += Dx; BoxBehaviourScript CXCY = map[XX, YY].GetComponent<BoxBehaviourScript>(); CXCY.CX = XX; CXCY.CY = YY; CXCY.MyMainGame = this.gameObject; } //обнуляем позицию Х MyPoze.x = -7.6f; //задаем новые координаты для У MyPoze.y += Dy; } } // Use this for initialization void Start() { CreateGamePole(); } // Update is called once per frame void Update() { MoverDown(); swap(); } //функция будет получать номер блока на который нажали public void GetSelectIndex(int X, int Y) { BoxBehaviourScript CXCY = map[X, Y].GetComponent<BoxBehaviourScript>(); Pretindent.Clear(); Point P; PX = X; PY = Y; TestBlock(P, CXCY.index); //проверяем сколько блоков найдено рядом if (Pretindent.Count > 2) ClearBlockColor(); } void TestBlock(Point coord, int IDColor) { //проверяем нет ли уже этой точки в списке на вылет int Find = Pretindent.IndexOf(coord); //если не нашли значение значит равно -1 if (Find == -1) { //получим цвет проверяемого блока int IndexColor = map[coord.X, coord.Y].GetComponent<BoxBehaviourScript>().index; //если точка if (IndexColor == IDColor) { //добавляем претиндента в список Pretindent.Add(coord); //расчитываем координаты для поиска далее List<Point> Test = IndexList(coord); //запускаем цикл поиска по точкам foreach (Point T in Test) TestBlock(T, IDColor); } } } void ClearBlockColor() { //Закрасим белым цветом все найденные точки foreach (Point Clear in Pretindent) { //обнулим точки с правельным цветом map[Clear.X, Clear.Y].GetComponent<BoxBehaviourScript>().index = 0; } } //функция сброса блоков вниз void MoverDown() { for (int Y = 0; Y < row; Y++) { for (int X = 0; X < col; X++) { //проверяем пуст ли блок if (map[X, Y].GetComponent<BoxBehaviourScript>().index == 0) { int Dy = Y + 1; //проверяем может ли над нами быть кубик if (Dy < row) { map[X, Y].GetComponent<BoxBehaviourScript>().index = map[X, Dy].GetComponent<BoxBehaviourScript>().index; map[X, Dy].GetComponent<BoxBehaviourScript>().index = 0; } else { map[X, Y].GetComponent<BoxBehaviourScript>().RandomColor(); } } } } } 

The question is this - despite the excellent commenting of the code, the "structure description of a point" is completely incomprehensible to me. It seems like in Match3, GameObjects are searched and destroyed if nearby. What are the points

  struct point 

and why are they needed here? What is their advantage over simply searching GameObject and checking by coordinates?

  • Apparently optimization is faster likely than every time to search for a GameObject. - pavel
  • @pavel I apparently incorrectly formulated the question. Why do these points? What are they and how do they interact with GameObject? How can you find or destroy an object through them? - Dmitrii
  • not enough information. I would make a two-dimensional array with all game objects necessary and work with their coordinates. - pavel
  • @pavel Added the full version of the code - Dmitrii
  • Well, actually I was right. To index the array map - pavel

0