Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino RGB support #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion Assets/TestHarness/TestHarness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ public class TestHarness : MonoBehaviour
private List<KMBombModule> Modules;
private List<KMNeedyModule> NeedyModules;

private bool Arduino = true;

void Awake()
{
Instance = this;
Expand Down Expand Up @@ -1122,6 +1124,7 @@ void Start()
GameSoundEffects[effect].AddRange(kmSoundOverride.AdditionalVariants.Where(x => x != null));
}
}
StartCoroutine(ArduinoController());
}

protected void PlaySoundHandler(string clipName, Transform t)
Expand Down Expand Up @@ -1311,6 +1314,7 @@ void Update()
if (Input.GetMouseButtonDown(1))
{
mouseDownTIme = 0;
currentModule=null;
}

if (Input.GetMouseButtonUp(1) && mouseDownTIme < 0.25f)
Expand Down Expand Up @@ -1588,6 +1592,8 @@ void OnGUI()
command = "";
}
}

Arduino = GUILayout.Toggle(Arduino, "Arduino RGB");
}

private Light _emergencyLight;
Expand Down Expand Up @@ -1661,5 +1667,33 @@ public void TurnLightsOff()
lightsOn = false;
UpdateAmbientIntensity();
}
}

private IEnumerator ArduinoController()
{
Camera.main.clearFlags = CameraClearFlags.SolidColor;
Camera.main.backgroundColor = Color.Lerp(new Color32(104,97,91, 255), Camera.main.backgroundColor, 0);
while(true)
{
if(Arduino)
{
if(currentModule!=null)
{
List<int> outputValue = new List<int>() { 104, 97, 91 };;
foreach (var component in currentModule.GetComponentsInChildren<Component>(true))
{
var type = component.GetType();
FieldInfo outputValueField = type.GetField("arduinoRGBValues", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
try { outputValue = (List<int>)outputValueField.GetValue(component); break; } catch { outputValue = new List<int>() { 104, 97, 91 }; }
}
if (outputValue != null && outputValue.Count >= 3) Camera.main.backgroundColor = Color.Lerp(new Color32((byte)(outputValue[0]%256), (byte)(outputValue[1]%256), (byte)(outputValue[2]%256), 255), Camera.main.backgroundColor, 0);
}
else
{
Camera.main.backgroundColor = Color.Lerp(new Color32(104,97,91, 255), Camera.main.backgroundColor, 0);
}
}
else{Camera.main.backgroundColor = Color.Lerp(new Color32(104,97,91, 255), Camera.main.backgroundColor, 0);}
yield return null;
}
}
}