コード例 #1
0
    // Returns true if a connection is possible.
    public bool CanMakeConnection(ConnectionPoint src, ConnectionPoint dest)
    {
        if (src == null || dest == null)
        {
            return(false);
        }

        if (src.connectionType == ConnectionPoint.ConnectionType.Input || dest.connectionType == ConnectionPoint.ConnectionType.Output)
        {
            return(false);
        }

        if (src.connectionType == dest.connectionType)
        {
            return(false);
        }

        CircuitDevice dest_cd = dest.GetComponentInParent <CircuitDevice>();

        // If we're trying to connect to a port that already has something connected to it, fail
        if (circuitSimObject.gates[dest_cd.associatedGuid].inputs[dest.connectionIndex] != null)
        {
            return(false);
        }

        return(true);
    }
コード例 #2
0
    void PopulateWire(Guid netGuid)
    {
        // If we already have a wire system for this particular net...
        if (wires.ContainsKey(netGuid))
        {
            Debug.Log("Destroying old wire system");
            Destroy(wires[netGuid].gameObject);
            wires.Remove(netGuid);
        }

        Net net = circuitSimObject.nets.ContainsKey(netGuid) ? circuitSimObject.nets[netGuid] : null;

        if (net == null)
        {
            Debug.Log("Net does not exist. Removed wire, and returning");
            return;
        }


        // // If the circuit sim does not contain the source of the net,
        // // it was deleted.
        // if(circuitSimObject.gates.ContainsKey(src.guid) == false){
        //     Debug.Log("Detected destroyed gate, returning");
        //     return;
        // }

        // // Don't create a wire system if the circuit sim doesn't contain the net...
        // if(circuitSimObject.nets.ContainsKey(netGuid) == false){
        //     Debug.Log("Detected destroyed net, returning");
        //     return;
        // }

        WireSystem newWire = GameObject.Instantiate(wirePrefab, wireContainer.transform).GetComponent <WireSystem>();

        newWire.transform.position = Vector2.zero;

        // Physically connect the wire system to the physical
        // connection port on the source device
        newWire.start = physicalDevices[net.source.guid].outputs[net.source.outputs.IndexOf(net)];

        // Find all receiving devices and their connection points
        foreach (Primitive recipient in net.fanout)
        {
            // Null if point is not connected
            // if(recipient == null){ continue; }

            // Find which port this net is connected to
            int recipientPortIndex = recipient.inputs.IndexOf(net);

            CircuitDevice   recipientDevice          = physicalDevices[recipient.guid];
            ConnectionPoint recipientConnectionPoint = recipientDevice.inputs[recipientPortIndex];

            newWire.ends.Add(recipientConnectionPoint);
        }

        newWire.netGuid = netGuid;
        wires.Add(newWire.netGuid, newWire);
    }
コード例 #3
0
ファイル: DragHandler.cs プロジェクト: Zee2/DigitalPlayground
    public void Start()
    {
        parentRectTransform = transform.parent.transform as RectTransform;
        panelRectTransform  = transform as RectTransform;
        attachedDevice      = GetComponent <CircuitDevice>();

        clampedToLeft   = false;
        clampedToRight  = false;
        clampedToTop    = false;
        clampedToBottom = false;
    }
コード例 #4
0
    public void RemovePhysicalGate(CircuitDevice circuitDevice)
    {
        HashSet <Guid> netsToUpdate = circuitSimObject.RemovePrimitive(circuitDevice.associatedGuid);

        Debug.Log($"{netsToUpdate.Count} nets need updating");
        foreach (Guid netGuid in netsToUpdate)
        {
            PopulateWire(netGuid);
        }
        physicalDevices.Remove(circuitDevice.associatedGuid);
        Destroy(circuitDevice.gameObject);
    }
コード例 #5
0
 // Update the location of the circuit device.
 public void UpdateDeviceLocation(CircuitDevice circuitDevice)
 {
     circuitSimObject.gates[circuitDevice.associatedGuid].position = circuitDevice.transform.localPosition;
 }
コード例 #6
0
    public void AddPhysicalGate(CircuitDevice circuitDevice)
    {
        Primitive newSimGate;

        switch (circuitDevice.logicType)
        {
        case Utils.LogicType.NOT:
            newSimGate = new Not("replaceMe");
            break;

        case Utils.LogicType.NAND:
            newSimGate = new Nand("replaceMe");
            break;

        case Utils.LogicType.AND:
            newSimGate = new And("replaceMe");
            break;

        case Utils.LogicType.OR:
            newSimGate = new Or("replaceMe");
            break;

        case Utils.LogicType.NOR:
            newSimGate = new Nor("replaceMe");
            break;

        case Utils.LogicType.XOR:
            newSimGate = new Xor("replaceMe");
            break;

        case Utils.LogicType.XNOR:
            newSimGate = new Xnor("replaceMe");
            break;

        case Utils.LogicType.Lever:
            newSimGate = new Lever("replaceMe");
            (circuitDevice as LeverDevice).leverGate = newSimGate as Lever;
            break;

        case Utils.LogicType.Indicator:
            newSimGate = new Indicator("replaceMe");
            break;

        case Utils.LogicType.Clock:
            newSimGate = new Clock("replaceMe");
            break;

        case Utils.LogicType.ShiftRegister4:
            newSimGate = new ShiftRegister("replaceMe", 4);
            break;

        case Utils.LogicType.ShiftRegister8:
            newSimGate = new ShiftRegister("replaceMe", 8);
            break;

        case Utils.LogicType.DFF:
            newSimGate = new DFF("replaceMe");
            break;

        case Utils.LogicType.FA1:
            newSimGate = new Adder("replaceMe", 1);
            break;

        default:
            Debug.LogError("Unknown circuit device type, object name: " + circuitDevice.gameObject.name);
            return;
        }

        newSimGate.position          = circuitDevice.transform.localPosition;
        circuitDevice.associatedGuid = newSimGate.guid;

        circuitSimObject.Add(newSimGate);

        physicalDevices.Add(newSimGate.guid, circuitDevice);
    }
コード例 #7
0
    void PopulateSimGate(Primitive simGate)
    {
        GameObject prefabToUse;

        switch (simGate.logicType)
        {
        case Utils.LogicType.NOT:
            prefabToUse = notGate;
            break;

        case Utils.LogicType.AND:
            prefabToUse = andGate;
            break;

        case Utils.LogicType.NAND:
            prefabToUse = nandGate;
            break;

        case Utils.LogicType.OR:
            prefabToUse = orGate;
            break;

        case Utils.LogicType.NOR:
            prefabToUse = norGate;
            break;

        case Utils.LogicType.XOR:
            prefabToUse = xorGate;
            break;

        case Utils.LogicType.XNOR:
            prefabToUse = xnorGate;
            break;

        case Utils.LogicType.Lever:
            prefabToUse = leverGate;
            break;

        case Utils.LogicType.Indicator:
            prefabToUse = indicatorGate;
            break;

        case Utils.LogicType.Clock:
            prefabToUse = clockGate;
            break;

        case Utils.LogicType.ShiftRegister4:
            prefabToUse = shiftRegister4Gate;
            break;

        case Utils.LogicType.ShiftRegister8:
            prefabToUse = shiftRegister8Gate;
            break;

        case Utils.LogicType.DFF:
            prefabToUse = dffGate;
            break;

        case Utils.LogicType.FA1:
            prefabToUse = fa1Gate;
            break;

        default:
            prefabToUse = null;
            break;
        }

        if (prefabToUse == null)
        {
            Debug.Log("Unknown simGate: " + simGate.GetType());
            return;
        }

        CircuitDevice gateObject = GameObject.Instantiate(prefabToUse, gateContainer.transform).GetComponent <CircuitDevice>();

        gateObject.transform.localPosition = (Vector3)simGate.position;
        gateObject.transform.SetAsFirstSibling();
        gateObject.associatedGuid = simGate.guid;
        gateObject.logicType      = simGate.logicType;

        // If the new gate is a lever, tell it what the sim gate is,
        // so it can inform the logic sim of any new inputs.
        if (simGate.logicType == Utils.LogicType.Lever)
        {
            (gateObject as LeverDevice).leverGate = simGate as Lever;
        }

        physicalDevices.Add(simGate.guid, gateObject);
    }