//CALCULATES output light(s) protected override void CalculateOutput() { LightBeam input = inputList.ElementAt(0); LightBeam output1; LightBeam output2; // 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; output1 = tempObj.GetComponent <LightBeam>(); tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject; output2 = tempObj.GetComponent <LightBeam>(); outputList.AddFirst(output1); outputList.AddLast(output2); } output1 = outputList.ElementAt(0); output2 = outputList.ElementAt(1); // COLOR if (input.GetColor() == cyan) { // Erstelle blauen und grünen Strahl output1.SetColor(blue); output2.SetColor(green); } else if (input.GetColor() == yellow) { // Erstelle roten und grünen Strahl output1.SetColor(green); output2.SetColor(red); } else if (input.GetColor() == magenta) { // Erstelle roten und blauen Strahl output1.SetColor(red); output2.SetColor(blue); } else { ChangeError(ErrorState.ERRORINPUT); } // DIRECTION output1.SetDirection(Quaternion.Euler(0, -60, 0) * input.GetRaycastHit().collider.transform.forward); output2.SetDirection(Quaternion.Euler(0, 60, 0) * input.GetRaycastHit().collider.transform.forward); // SET ACTIVE output1.Enable(); output2.Enable(); }
//CALCULATES output light(s) protected override void CalculateOutput() { LightBeam input = inputList.ElementAt(0); Debug.Log(inputList.ElementAt(0)); LightBeam output1; LightBeam output2; // 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; output1 = tempObj.GetComponent <LightBeam>(); tempObj = Instantiate(Resources.Load("LightBeam"), transform.position, transform.rotation, transform) as GameObject; output2 = tempObj.GetComponent <LightBeam>(); outputList.AddFirst(output1); outputList.AddLast(output2); } output1 = outputList.ElementAt(0); output2 = outputList.ElementAt(1); // color output1.SetColor(input.GetColor()); output2.SetColor(input.GetColor()); // direction // blocked side is forward (positive z axis) if (input.GetRaycastHit().collider.name == "LightColliderLeft") { output1.SetDirection(transform.right); output2.SetDirection(transform.forward * (-1)); } else if (input.GetRaycastHit().collider.name == "LightColliderRight") { output1.SetDirection(transform.right * (-1)); output2.SetDirection(transform.forward * (-1)); } else if (input.GetRaycastHit().collider.name == "LightColliderBack") { output1.SetDirection(transform.right); output2.SetDirection(transform.right * (-1)); } // set active output1.Enable(); output2.Enable(); }
//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(); } } }
//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(); }