private GameObject BuildOrga() { CellType[,] CellMatrix = BuildCellMatrix(MAX_SIZE); PopulateCellMatrix(ref CellMatrix); GameObject Organism = Instantiate(OrganismPrefab); Vector2 mid = BaseU.GetMatrixMid(CellMatrix).ToVector2(); for (int i = 0; i < CellMatrix.GetLength(0); i++) { for (int j = 0; j < CellMatrix.GetLength(1); j++) { CellType type = CellMatrix[i, j]; CreateCell(mid, type, i, j, Organism); } } return(Organism); }
private void PopulateCellMatrix(ref CellType[,] CellMatrix) { List <Gene> Genes = DNA.GetGenes(); Point pos = BaseU.GetMatrixMid(CellMatrix); foreach (Gene gene in Genes) { CellType type = gene.GetCellType(); PhysicsU.Directions dir = gene.GetDirection(); Vector2 dirVec = PhysicsU.Dir2Vec(dir); pos.x += (int)dirVec.x; pos.y += (int)dirVec.y; pos.x = MathU.MinMax(pos.x, 0, CellMatrix.GetLength(0) - 1); pos.y = MathU.MinMax(pos.y, 0, CellMatrix.GetLength(1) - 1); CellMatrix[pos.x, pos.y] = type; } }