public ObjectTemplate Clone() { return(new ObjectTemplate( Objects.Select(original => { var clone = new ScriptObject() { X = original.X, Y = original.Y, Z = original.Z, Rotation = original.Rotation, RoadOptions = original.RoadOptions, Type = original.Type }; foreach (var property in original.Properties) { clone.Properties.Add(property.Key, new Property() { Name = property.Value.Name, Type = property.Value.Type, Value = property.Value.Value }); } return clone; }).ToArray(), BlockedTiles.Select(t => new Point(t.X, t.Y)).ToArray()) { Tiles = Tiles, Map = Map }); }
private void CalculatePositions() { if (Objects.Any()) { Point origin = CalculateOrigin(); foreach (var obj in Objects) { obj.X -= origin.X; obj.Y -= origin.Y; } } BlockedTiles = BlockedTiles.Select(t => t - origin).ToArray(); }
public void StartMe() { BlockedTiles bt; // Blocked tiles GameObject[] blockers; // Tile blockers GameObject[] doors; // List of doors List<GameObject> allBlockedTiles; // List of all blocked tiles Tile t; // Generated tile SetPublicVariables(); debugging = false; camController = GetComponentInChildren<CameraController>(); playerScript = gameObject.GetComponent<Player>(); /* * IMPORTANT: if you make a tag type that you want to add to blockedTiles, use AddRange() * like I have here. */ blockers = GameObject.FindGameObjectsWithTag("Blocker"); doors = GameObject.FindGameObjectsWithTag("Door"); allBlockedTiles = new List<GameObject>(); allBlockedTiles.AddRange(blockers); allBlockedTiles.AddRange(doors); allBlockedTiles.ForEach(delegate(GameObject blocker) { bt = blocker.GetComponent<BlockedTiles>(); /* Not all blockers will have a BlockedTiles script (e.g. doors) */ if (bt == null) bt = new BlockedTiles(); for (int i = -bt.Down; i <= bt.Up; i++) { t = new Tile( Tile.TilePosition(blocker.transform.position.x), Tile.TilePosition(blocker.transform.position.z) + i ); blockedTiles.Add(t); } for (int i = -bt.Left; i <= bt.Right; i++) { t = new Tile( Tile.TilePosition(blocker.transform.position.x) + i, Tile.TilePosition(blocker.transform.position.z) ); blockedTiles.Add(t); } }); GameObject o; Vector3 v ; /* Checks if blockedTiles is correct */ if (debugging) { foreach (Tile tile in blockedTiles) { Debug.Log(tile.X + " " + tile.Z); o = GameObject.CreatePrimitive(PrimitiveType.Cube); v = Tile.TileMiddle(tile); o.transform.position = v; } } }