Ejemplo n.º 1
0
    /*
     * On logic-elements, it can be useful to see it's truthtable.
     * This method is called by various input-behaviours and displays the truthtable of the clicked or selected logic-element.
     * @param   mceObject   The MultiCellElement of which to show the truthtable. If this is null, show the truthtable of the element in the inventory.
     */
    public void FillSelectionResultTable(MultiCellElement mceObject = null)
    {
        // If no object was given, get the MultiCellElement-Component of the element in the inventory.
        if (mceObject == null)
        {
            mceObject = selected.go.GetComponent <MultiCellElement>();
        }

        // Fill the selectionpanel with the truthtable of the determined MCE (MultiCellElement) if it is presentable.
        if (mceObject && mceObject.isPresentable)
        {
            UITableFiller.FillTable(selectionPanel.go, mceObject.resultList, mceObject.outComingSocketCount, mceObject.incomingSocketCount, mceObject.resultList, width: 300, height: 205);
            selectionPanel.go.SetActive(true);
        }
    }
Ejemplo n.º 2
0
    private void Start()
    {
        prefabs = Resources.LoadAll("Prefabs\\Schaltnetze", typeof(GameObject));
        foreach (GameObject temp in prefabs)
        {
            MultiCellElement tempObj = temp.GetComponent <MultiCellElement>();

            if (tempObj && !tempObj.Locked)
            {
                GameObject tempButton = Instantiate(_button, _contentGo.transform);
                tempButton.GetComponent <Button>().onClick.AddListener(delegate { InputHandler.instance.SelectNewElement(temp); });
                tempButton.GetComponent <Button>().onClick.AddListener(delegate { InputHandler.instance.FillSelectionResultTable(); });
                TMP_Text text = tempButton.GetComponentInChildren <TMP_Text>();
                text.text = temp.name;
            }
        }
    }
Ejemplo n.º 3
0
    /*
     * 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();
        }
    }
Ejemplo n.º 4
0
    /*
     * 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();
        }
    }