public void MarkGridCell(CellPoint point, SCellValue.ECellContainValues value) { if(Grid == null) Grid = DeserializeGridData(GridAssetData); InitComponents(); int i = point.x; int j = point.y; Color result = EmptyColor; switch(value) { case SCellValue.ECellContainValues.Empty: result = EmptyColor; break; case SCellValue.ECellContainValues.Obstracle: result = ObstracleColor; break; case SCellValue.ECellContainValues.Enemy: result = EnemyColor; break; case SCellValue.ECellContainValues.Player: result = PlayerColor; break; } Grid[i,j].CellContainValue= value; Color[] cl = GridMesh.colors; for(int q=0; q<Grid[i,j].ConerListVertexIndexes.Length; q++) { cl[Grid[i,j].ConerListVertexIndexes[q]] = result; } GridMesh.colors = cl; filter.mesh = GridMesh; }
public LevelGridComponent.SCellValue[,] DeserializeGridData(TextAsset asset) { XmlDocument doc = new XmlDocument(); doc.LoadXml(asset.text); XmlSerializer serializer = new XmlSerializer(typeof(GridDataSerilizetion)); XmlReader reader = new XmlNodeReader(doc.ChildNodes[1]); GridDataSerilizetion sr = (GridDataSerilizetion)serializer.Deserialize(reader); LevelGridComponent.SCellValue[,] resutl = new SCellValue[sr.Height,sr.Widht]; int q=0; foreach(var a in sr.Cells) { SCellValue tmp = new SCellValue(); tmp.CellContainValue = a.CellContainValue; tmp.ConerListVertexIndexes = (int[]) a.ConerListVertexIndexes.Clone(); resutl[a.X,a.Y]=tmp; } return resutl; }
public void MarkGridCell(Vector3 position, SCellValue.ECellContainValues value) { if(Grid == null) Grid = DeserializeGridData(GridAssetData); InitComponents(); Vector3 meshPosition = position-transform.position; int i = Mathf.FloorToInt(meshPosition.x/GridWorldStep); int j = Mathf.FloorToInt(meshPosition.z/GridWorldStep); Color result = EmptyColor; switch(value) { case SCellValue.ECellContainValues.Empty: result = EmptyColor; break; case SCellValue.ECellContainValues.Obstracle: result = ObstracleColor; break; case SCellValue.ECellContainValues.Enemy: result = EnemyColor; break; case SCellValue.ECellContainValues.Player: result = PlayerColor; break; } Grid[i,j].CellContainValue= value; Color[] cl = GridMesh.colors; for(int q=0; q<Grid[i,j].ConerListVertexIndexes.Length; q++) { cl[Grid[i,j].ConerListVertexIndexes[q]] = result; } GridMesh.colors = cl; filter.mesh = GridMesh; }