void loadCellData(string s) { if (string.IsNullOrEmpty(s)) { return; } string[] data = s.Split('$'); if (data.Length < 2) { return; } CellData cell = GetCellById(int.Parse(data[0])); int heightDataCount = (data.Length - 1) / 2; for (int i = 0; i < heightDataCount; i++) { float h = float.Parse(data[i * 2 + 1]); float sz = float.Parse(data[i * 2 + 2]); cell.AddHeight(h, sz); } if (((data.Length - 1) % 2) == 1) { bool canMove = true; if (bool.TryParse(data[data.Length - 1], out canMove)) { if (canMove) { cell.AddUnit(UnitType.OBJECTS); } else { cell.AddUnit(UnitType.OBSTACLE); } } else { cell.Unit = (UnitType)System.Enum.Parse(typeof(UnitType), data[data.Length - 1]); } } else { cell.AddUnit(UnitType.OBJECTS); } }
/// <summary> /// Set the cell if a person can move. /// </summary> /// <param name="xIndex"></param> /// <param name="zIndex"></param> /// <param name="movable"></param> /// <returns></returns> public bool SetCellMovable(int xIndex, int zIndex, bool movable) { CellData cell = MapDataCollection[xIndex, zIndex]; if (cell != null && cell.IsCanMove() != movable) { if (movable) { cell.RemoveUnit(UnitType.OBSTACLE); } else { cell.AddUnit(UnitType.OBSTACLE); } return(true); } return(false); }