Пример #1
0
    public void PropagateOutput()
    {
        BaseLevelController _levelController = FindObjectOfType <BaseLevelController>();

        if (_levelController == null)
        {
            Debug.Log("didn't find LevelController");
        }
        else
        {
            string[] wire_list = _levelController.GetWireList();
            // Debug.Log("in propagate outputs for " + this.name);
            bool first_clock = true;
            for (int i = 0; i < wire_list.Length; i += 4)
            {
                if (wire_list[i] == this.name)
                {
                    // Debug.Log(" matched source name:  " + wire_list[i] + ", dest = " + wire_list[i+2]) ;
                    // On the first clock being driven, lock the FFs' inputs for the coming edge.
                    if (wire_list[i + 3] == "ck" && first_clock)
                    {
                        FF[] ffs = FindObjectsOfType <FF>();
                        foreach (FF myff in ffs)
                        {
                            myff.LockDInput();
                        }
                        first_clock = false;
                    }
                    GameObject _destination = GameObject.Find(wire_list[i + 2]);
                    if (_destination)
                    {
                        _destination.SendMessage("InputChanged_" + wire_list[i + 3],
                                                 _out);
                    }
                }
                else
                {
                    // Debug.Log("not matched name:  " + wire_list[i]);
                }
            }
        }
    }
Пример #2
0
    public bool IsInputAvailable(string input_name)
    {
        BaseLevelController lc = FindObjectOfType <BaseLevelController>();

        string[] wire_list = lc.GetWireList();
        if (wire_list.Length < 4)
        {
            return(true);
        }
        // Debug.Log("in IsInputAvailable, name = " + this.name);
        for (int i = 0; i < wire_list.Length; i += 4)
        {
            // Debug.Log("in IsInputAvailable, wl[2] = " + wire_list[2] + ", wl[3] =" + wire_list[3]);
            if (wire_list[i + 2] == this.name && wire_list[i + 3] == input_name)
            {
                return(false);
            }
        }
        return(true);
    }
Пример #3
0
    public void OnMouseEnter()
    {
        GameMode mygamemode = FindObjectOfType <GameMode>();

        if (mygamemode.IsInRouteMode() && _output_gate && _output_gate != this)
        {
            // Debug.Log("In OnMouseEnter, this = " + name);
            string[]            myinputs    = GateInputs().Split(' ');
            string              found_input = "BadInput";
            BaseLevelController lc          = FindObjectOfType <BaseLevelController>();
            lc.GetWireList();
            foreach (string myinput in myinputs)
            {
                if (IsInputAvailable(myinput))
                {
                    // Debug.Log("In OnMouse Enter Found available input " + this.name + "/" + myinput);
                    found_input = myinput;
                    break;
                }
            }
            if (found_input == "BadInput")
            {
                Debug.Log("Non inputs available on " + this);
                return;
            }
            // BaseLevelController lc = FindObjectOfType<BaseLevelController>();
            string wire_element = _output_gate.name + " out " + this.name + " " + found_input;
            lc.AddToWireList(wire_element);
            Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            newPosition.z = 0;
            LineRenderer mylr         = _output_gate.GetComponent <LineRenderer>();
            int          numPositions = mylr.positionCount;
            Vector3[]    positions    = new Vector3[numPositions + 1];
            mylr.GetPositions(positions);
            positions[numPositions - 1] = transform.position;
            positions[numPositions]     = transform.position;
            mylr.positionCount         += 1;
            mylr.SetPositions(positions);
            // Debug.Log("In OnMouseEnter, added this to wire list: " + wire_element);
        }
    }