/* * This functions places an incoming socket and adjusts it's parameters to react correctly when being visited. * @param coords The coordinates to place the socket on the grid. * @param targetCoord The coordinates of the logic-element to which this sockets belongs to. * @param filler The filler-object that is used to fill spaces, in case the placement of the sockets causes a conflict with a multi-cell-element. */ private void PlaceIncomingSocket(Vector2Int coords, Vector2Int targetCoords, GameObject filler) { // Only place the socket, if the coords is adjacent to the logic-element. if (Placer.IsAdjacent(_mainGrid.grid, coords, targetCoords)) { // Get a reference to the newly placed socket. GameObject tempObj; tempObj = Placer.PlaceObject(_mainGrid.grid, selected.go, coords.x, coords.y, _filler.go); // If the placement was successfull, play a sound and adjust attributes of the socket and the logic-element. if (tempObj) { // Auditive feedback for the successfull placement. AudioManager.instance.PlaySound(clips[0]); // Set the target-logic-element coordinates to the saved coordinates. tempObj.GetComponent <SocketOfGridElement>().coordsToTarget = tempTargetCoord; // Set the target-logic-element to be the target of the socket. tempObj.GetComponent <SocketOfGridElement>().targetGo = _mainGrid.grid.GetObjFromCoordinate(tempTargetCoord); // Add this socket to the list of incoming sockets of the logic-element. MultiCellElement targetMCE = _mainGrid.grid.GetObjFromCoordinate(tempTargetCoord).GetComponent <MultiCellElement>(); // Nullchecking the element. Might not really be neccessary, if the inventory is correct, which it should. if (tempObj.GetComponentInChildren <TMP_Text>()) { // Set the text of the prefab to the corresponding variable it resembles. // The first incoming socket is always A, the second is B, the third is C and so on. tempObj.GetComponentInChildren <TMP_Text>().text = ((Charge)targetMCE.incomingSockets.Count + 1).ToString(); } targetMCE.AddToList(targetMCE.incomingSockets, coords); // Decrement the number of incoming sockets needed to be placed by the player. _incomingSocketsToPlace--; } } // Show a message, reminding the player that sockets need to be placed adjacent to the element. else { floatingText.GetComponent <Animation>().Play(); } }
/* * Similar to placing an incoming socket, but still different. * @param coords The coordinates to place the socket on the grid. * @param targetCoord The coordinates of the logic-element to which this sockets belongs to. * @param filler The filler-object that is used to fill spaces, in case the placement of the sockets causes a conflict with a multi-cell-element. */ private void PlaceOutgoingSocket(Vector2Int coords, Vector2Int targetCoords, GameObject filler) { // Also outgoing sockets can only be placed adjacent to logic-elements. if (Placer.IsAdjacent(_mainGrid.grid, coords, targetCoords)) { // Get a reference to the newly placed socket. GameObject tempObj; tempObj = Placer.PlaceObject(_mainGrid.grid, selected.go, coords.x, coords.y, _filler.go); // If the placement was successfull, play a sound and adjust attributes of the socket and the logic-element. if (tempObj) { AudioManager.instance.PlaySound(clips[0]); // Since outgoingsockets can't be visited, we only need to add the socket to the logic-elements list of outgoing sockets. // There is no need to define a target for the outgoing socket. MultiCellElement targetMCE = _mainGrid.grid.GetObjFromCoordinate(tempTargetCoord).GetComponent <MultiCellElement>(); if (tempObj.GetComponentInChildren <TMP_Text>()) { // Set the text of the prefab to the corresponding variable it resembles. // The first outgoing socket is always 0, the second is 1, the third is 2 and so on. tempObj.GetComponentInChildren <TMP_Text>().text = targetMCE.outgoingSockets.Count.ToString(); } targetMCE.AddToList(targetMCE.outgoingSockets, coords); targetMCE.outgoingSocketObjects.Add(tempObj.GetComponent <OutGoingSocket>()); // Decrement the number of incoming sockets needed to be placed by the player. _outgoingSocketsToPlace--; } } // Show a message, reminding the player that sockets need to be placed adjacent to the element. else { floatingText.GetComponent <Animation>().Play(); } }