Example #1
0
    public void CreateConnectionBetweenMachinesOn(GameObject firstFloor,
                                                  GameObject lastFloor,
                                                  GameObject wirePreFab,
                                                  int connection_id)
    {
        GameObject firstMachine = firstFloor.GetComponent <Floor>().objectHolded;
        GameObject lastMachine  = lastFloor.GetComponent <Floor>().objectHolded;

        if (firstMachine.GetComponent <Machine>().CanHaveMoreConnections() &&
            lastMachine.GetComponent <Machine>().CanHaveMoreConnections())
        {
            GameObject connectionGo = Instantiate(wirePreFab);
            Connection connection   = connectionGo.GetComponent <Connection>();

            connection.connectionsPoints[0] = firstMachine;
            connection.connectionsPoints[1] = lastMachine;
            connection.UpdatePointsOnLine();

            firstMachine.GetComponent <Machine>().connections.Add(connectionGo);
            lastMachine.GetComponent <Machine>().connections.Add(connectionGo);

            connection.id = connection_id;

            connectionGo.name = connection.wireType + connection.id.ToString();

            connectionGo.transform.SetParent(connectionsHolder.transform);
        }
        else
        {
            popTextController.CreatePopText("connections limit", firstMachine.transform);
        }
    }
    public void TryTransferBitsBetweenMachines(Machine to, Machine from)
    {
        string     transferError             = null;
        Transform  currentMachineSaying      = null;
        Connection connectionBetweenMachines = ConnectionBetween(to.gameObject, from.gameObject);

        if (connectionBetweenMachines != null)
        {
            if (from.CanSendBits())
            {
                if (to.CanReceiveAliedBits())
                {
                    TransferBitsBetweenMachines(connectionBetweenMachines, to, from);
                }
                else
                {
                    transferError        = "cheio.";
                    currentMachineSaying = to.transform;
                }
            }
            else
            {
                transferError        = "bits insuficientes.";
                currentMachineSaying = from.transform;
            }
        }
        else
        {
            transferError        = "não conectadas.";
            currentMachineSaying = from.transform;
        }

        if (transferError != null)
        {
            popTextController.CreatePopText(transferError, currentMachineSaying);
        }
    }