void InitializeGrid(Match3Grid grid) { var currentChilds = grid.transform.Cast <Transform>().ToList(); foreach (var child in currentChilds) { DestroyImmediate(child.gameObject); } for (var x = 0; x < m_GridSize; x++) { for (var y = 0; y < m_GridSize; y++) { var cell = Instantiate(grid.CellPrefab, new Vector3(x, 0, y), Quaternion.identity, grid.transform); cell.name = $"{x}_{y}"; var traitHolder = cell.GetComponent <ITraitBasedObjectData>(); traitHolder.Name = $"Cell{x}_{y}"; var cellData = traitHolder.GetTraitData <AI.Planner.Domains.Cell>(); if (cellData != null) { cellData.InitializeFieldValues(); #if PLANNER_DOMAIN_GENERATED cellData.SetValue(Cell.FieldType, (CellType)UnityEngine.Random.Range(1, Enum.GetNames(typeof(CellType)).Length)); #endif cellData.SetValue(Cell.FieldLeft, $"Cell{x - 1}_{y}"); cellData.SetValue(Cell.FieldRight, $"Cell{x + 1}_{y}"); cellData.SetValue(Cell.FieldTop, $"Cell{x}_{y + 1}"); cellData.SetValue(Cell.FieldBottom, $"Cell{x}_{y - 1}"); } else { Debug.LogError("Cell object doesn't have a Cell Trait"); continue; } var coordinateData = traitHolder.GetTraitData <Coordinate>(); if (coordinateData != null) { coordinateData.InitializeFieldValues(); coordinateData.SetValue(Coordinate.FieldX, (long)x); coordinateData.SetValue(Coordinate.FieldY, (long)y); } else { Debug.LogError("Cell object doesn't have a Coordinate Trait"); continue; } } } }
void InitializeGrid(Match3Grid grid) { var currentChilds = grid.transform.Cast <Transform>().ToList(); foreach (var child in currentChilds) { DestroyImmediate(child.gameObject); } for (var x = 0; x < m_GridSize; x++) { for (var y = 0; y < m_GridSize; y++) { var cell = Instantiate(grid.CellPrefab, new Vector3(x, 0, y), Quaternion.identity, grid.transform); cell.name = $"{x}_{y}"; } } for (var x = 0; x < m_GridSize; x++) { for (var y = 0; y < m_GridSize; y++) { var cell = GameObject.Find($"{x}_{y}"); var cellData = cell.GetComponent <Cell>(); if (cellData != null) { cellData.Type = (CellType)Random.Range(1, Enum.GetNames(typeof(CellType)).Length); cellData.Left = GameObject.Find($"{x - 1}_{y}"); cellData.Right = GameObject.Find($"{x + 1}_{y}"); cellData.Top = GameObject.Find($"{x}_{y + 1}"); cellData.Bottom = GameObject.Find($"{x}_{y - 1}"); } else { Debug.LogError("Cell object doesn't have a Cell Trait"); continue; } var coordinateData = cell.GetComponent <Coordinate>(); if (coordinateData != null) { coordinateData.X = x; coordinateData.Y = y; } else { Debug.LogError("Cell object doesn't have a Coordinate Trait"); continue; } } } }