Exemple #1
0
    // Run when necessary to check inputs; an update function
    // on every single gate is wasteful!
    public void RunLogic()
    {
        // Make sure things are initialised
        if (Inputs == null)
        {
            Inputs      = new bool[2];
            Sources     = new Gates.SourceConnection[2];
            SourceWires = new LineRenderer[2];
            InputGates  = new GateBehaviour[2];
        }

        // Only do logic if it's working
        if (Working)
        {
            // Just assign the output to the result of Gates.GetOutput()
            Output = Gates.GetOutput(LogicGate, Inputs[0], Inputs[1]);
        }
        else
        {
            Output = false;
        }

        // Assign the next gate's output
        if (OutputGate != null)
        {
            // Check the OGCID; if it's 0, connect to the first input,
            // otherwise, connect to the second input
            if (OGCID == 0)
            {
                OutputGate.Inputs[0] = Output;
            }
            else
            {
                OutputGate.Inputs[1] = Output;
            }
        }

        // Assign the end's output
        if (EndConnection != null)
        {
            EndConnection.Powered = Output;
        }

        // Colour the wires
        ColourWires();

        // Log stuff

        /*Debug.Log("Running logic for gate '" + gameObject.name + "'...");
         * Debug.Log("Input gate 1 is '" + ((Input1Gate != null) ? Input1Gate.gameObject.name + "'" : "null'"));
         * Debug.Log("Input gate 2 is '" + ((Input2Gate != null) ? Input2Gate.gameObject.name + "'" : "null'"));
         * Debug.Log("Connected to gate '" + ((OutputGate == null) ? "null'" : OutputGate.gameObject.name + "'") + ", setting that gate's input #" + (OGCID + 1) + " to " + (Output ? "true" : "false"));*/
    }