コード例 #1
0
    public void packetArrives(GameObject node, GameObject packet)
    {
        SelectNode   selectNode   = GameObject.FindGameObjectWithTag("GameController").GetComponent <SelectNode>();
        SelectPacket selectPacket = GameObject.FindGameObjectWithTag("GameController").GetComponent <SelectPacket>();

        bool             reselectNode   = false;
        bool             reselectPacket = false;
        ReferencedPacket packetToReset  = null;

        if (selectNode.getSelectedNode() == node)
        {
            reselectNode = true;
            if (selectPacket.getSelectedPacket())
            {
                packetToReset  = selectPacket.getReferencedPacket();
                reselectPacket = true;
            }
        }

        GameObject.FindGameObjectWithTag("PacketArrive").GetComponent <AudioSource>().Play();
        node.GetComponent <Packets>().addPacket(packet);    // add packet to the new node
        node.GetComponent <Packets>().checkPacketTargets(); // destroy packet if it has reached the target
        packet.GetComponent <Packet>().getPacketChild().SetActive(false);
        if (node.GetComponent <Packets>().getPacketCount() == 0)
        {
            node.GetComponentInChildren <Text>().text = "";
        }
        else
        {
            node.GetComponentInChildren <Text>().text = "" + node.GetComponent <Packets>().getPacketCount();//update packet count on arrival node
        }
        if (reselectNode)
        {
            //selectNode.selectNode(selectNode.getSelectedNode());// reselect currently selected node -- unneccesary now, so commented
            if (reselectPacket)
            {
                selectPacket.setSelectedPacket(packetToReset);
                selectPacket.resetDisplays(packetToReset);
            }
        }
        //if the arrived at node is selected it does not show the updated packet information without being reselected
    }