Beispiel #1
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        // iterate over all inputs
        for (int i = 0; i < inputList.Count; i++)
        {
            LightBeam input = inputList.ElementAt(i);

            // if there are too little beams in the output list, create one more
            if (outputList.Count == 0 || outputList.Count < i + 1)
            {
                GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
                outputList.AddLast(tempObj.GetComponent <LightBeam>());
            }

            // hit point
            outputList.ElementAt(i).transform.position = new Vector3(input.GetRaycastHit().point.x, 0, input.GetRaycastHit().point.z);

            // color
            outputList.ElementAt(i).SetColor(input.GetColor());

            // direction
            Vector3 mirrorAxis   = Vector3.Dot(transform.right, input.GetDirection()) / Mathf.Sqrt(transform.right.magnitude) * transform.right;
            Vector3 mirrorNormal = Vector3.Dot(transform.forward, input.GetDirection()) / Mathf.Sqrt(transform.forward.magnitude) * transform.forward;

            outputList.ElementAt(i).SetDirection(mirrorAxis - mirrorNormal);

            // set active
            outputList.ElementAt(i).Enable();
        }

        if (outputList.Count >= inputList.Count)
        {
            for (int i = inputList.Count; i < outputList.Count; i++)
            {
                outputList.ElementAt(i).Disable();
            }
        }
    }
Beispiel #2
0
    //CALCULATES output light(s)
    protected override void CalculateOutput()
    {
        LightBeam input1 = inputList.ElementAt(0);
        LightBeam input2 = inputList.ElementAt(1);
        LightBeam output;

        // if output light beams don't yet exist, instantiate them
        if (outputList.Count == 0)
        {
            GameObject tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject;
            output = tempObj.GetComponent <LightBeam>();

            outputList.AddFirst(output);
        }

        output = outputList.ElementAt(0);

        // COLOR
        if (input1.GetColor() == red && input2.GetColor() == green ||
            input2.GetColor() == red && input1.GetColor() == green)
        {
            output.SetColor(yellow);
        }
        else if (input1.GetColor() == red && input2.GetColor() == blue ||
                 input2.GetColor() == red && input1.GetColor() == blue)
        {
            output.SetColor(magenta);
        }
        else if (input1.GetColor() == green && input2.GetColor() == blue ||
                 input2.GetColor() == green && input1.GetColor() == blue)
        {
            output.SetColor(cyan);
        }
        else
        {
            ChangeError(ErrorState.ERRORINPUT);
        }

        // DIRECTION
        output.SetDirection(Vector3.Normalize(input1.GetDirection() + input2.GetDirection()));

        // SET ACTIVE
        output.Enable();
    }