/// <summary> /// Ensures that the object is properly initialized. /// </summary> private void EnsureInit() { if (!this) { return; } if (adjacencyMap == null) { adjacencyMap = new AdjacencyMap(); } if (!filter) { filter = GetComponent <MeshFilter>(); } PlacedTileObject placedTileObject = GetComponent <PlacedTileObject>(); if (placedTileObject == null) { genericType = TileObjectGenericType.None; specificType = TileObjectSpecificType.None; } else { genericType = placedTileObject.GetGenericType(); specificType = placedTileObject.GetSpecificType(); } }
public override string GetName(InteractionEvent interactionEvent) { PlacedTileObject tileObject = (interactionEvent.Target as IGameObjectProvider)?.GameObject?.GetComponentInParent <PlacedTileObject>(); if (tileObject != null && tileObject.GetGenericType() == TileObjectGenericType.Wall) { return("Deconstruct"); } return("Construct"); }
/// <summary> /// Update a single direction. /// </summary> /// <param name="dir"></param> /// <param name="placedObject"></param> /// <returns></returns> private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject) { // For some reason called before OnAwake() EnsureInit(); UpdateBlockedFromEditor(); bool isConnected = false; if (placedObject) { isConnected = (placedObject && placedObject.HasAdjacencyConnector()); // If cross connect is allowed, we only allow it to connect when the object type matches the connector type if (CrossConnectAllowed) { isConnected &= (placedObject.GetGenericType() == genericType && genericType != ""); } else { isConnected &= (placedObject.GetGenericType() == genericType || genericType == null); } // Check for specific isConnected &= (placedObject.GetSpecificType() == specificType || specificType == ""); isConnected &= (AdjacencyBitmap.Adjacent(blockedConnections, dir) == 0); } bool isUpdated = adjacents.UpdateDirection(dir, isConnected, true); SyncAdjacentConnections(adjacents.Connections, adjacents.Connections); // Cross connect will override adjacents for other layers, so return isConnected instead. if (CrossConnectAllowed) { return(isConnected); } else { return(isUpdated); } }
/// <summary> /// Update a single direction. /// </summary> /// <param name="dir"></param> /// <param name="placedObject"></param> /// <returns></returns> private bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject) { // For some reason called before OnAwake() EnsureInit(); UpdateBlockedFromEditor(); bool isConnected = false; if (placedObject) { isConnected = (placedObject && placedObject.HasAdjacencyConnector()); // If cross connect is allowed, we only allow it to connect when the object type matches the connector type if (CrossConnectAllowed) { isConnected &= placedObject.GetGenericType() == genericType && genericType != TileObjectGenericType.None; } else { isConnected &= placedObject.GetGenericType() == genericType || genericType == TileObjectGenericType.None; } // Check for specific isConnected &= placedObject.GetSpecificType() == specificType || specificType == TileObjectSpecificType.None; isConnected &= ((blockedConnections >> (int)dir) & 0x1) == 0; } bool isUpdated = adjacencyMap.SetConnection(dir, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected)); byte connections = adjacencyMap.SerializeToByte(); SyncAdjacentConnections(connections, connections); // Cross connect will override adjacents for other layers, so return isConnected instead. return(CrossConnectAllowed ? isConnected : isUpdated); }
protected override void StartDelayed(InteractionEvent interactionEvent) { var targetBehaviour = (IGameObjectProvider)interactionEvent.Target; TileManager tileManager = TileManager.Instance; PlacedTileObject targetPlacedObject = targetBehaviour.GameObject.GetComponentInParent <PlacedTileObject>(); // var tile = targetPlacedObject.Tile; // Deconstruct if (targetPlacedObject != null && targetPlacedObject.GetGenericType() == TileObjectGenericType.Wall) { tileManager.ClearTileObject(TileLayer.Turf, targetPlacedObject.transform.position); } else // Construct { tileManager.SetTileObject(WallToConstruct, targetPlacedObject.transform.position, Direction.South); } }
/** * Adjusts the connections value based on the given new tile. * Returns whether value changed. */ private bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject) { SetPerpendicularBlocked(true); bool isConnected = (placedObject && placedObject.HasAdjacencyConnector() && placedObject.GetGenericType() == TileObjectGenericType.Wall); return(adjacencyMap.SetConnection(direction, new AdjacencyData(TileObjectGenericType.None, TileObjectSpecificType.None, isConnected))); }
/** * Adjusts the connections value based on the given new tile. * Returns whether value changed. */ private bool UpdateSingleConnection(Direction direction, PlacedTileObject placedObject) { SetPerpendicularBlocked(true); bool isConnected = (placedObject && placedObject.HasAdjacencyConnector() && placedObject.GetGenericType() == "wall"); return(adjacents.UpdateDirection(direction, isConnected, true)); }