private void SetEffectOnAll(EffectInput input) { if (!this._mConnectionManager.Connected) { Debug.LogError("Chroma client is not yet connected!"); return; } ChromaApi apiChromaInstance = this._mConnectionManager.ApiChromaInstance; ChromaExample01.LogResult("PutChromaLink:", apiChromaInstance.PutChromaLink(input)); ChromaExample01.LogResult("PutHeadset:", apiChromaInstance.PutHeadset(input)); ChromaExample01.LogResult("PutKeyboard:", apiChromaInstance.PutKeyboard(input)); ChromaExample01.LogResult("PutKeypad:", apiChromaInstance.PutKeypad(input)); ChromaExample01.LogResult("PutMouse:", apiChromaInstance.PutMouse(input)); ChromaExample01.LogResult("PutMousepad:", apiChromaInstance.PutMousepad(input)); }
/// <summary> /// Set effect on all devices using PUT /// </summary> /// <param name="input"></param> void SetEffectOnAll(EffectInput input) { if (!_mConnectionManager.Connected) { Debug.LogError("Chroma client is not yet connected!"); return; } ChromaApi chromaApi = _mConnectionManager.ApiChromaInstance; LogResult("PutChromaLink:", chromaApi.PutChromaLink(input)); LogResult("PutHeadset:", chromaApi.PutHeadset(input)); LogResult("PutKeyboard:", chromaApi.PutKeyboard(input)); LogResult("PutKeypad:", chromaApi.PutKeypad(input)); LogResult("PutMouse:", chromaApi.PutMouse(input)); LogResult("PutMousepad:", chromaApi.PutMousepad(input)); }
private void OnGUI() { if (null == this._mConnectionManager) { GUILayout.Label("Waiting for start...", new GUILayoutOption[0]); return; } ChromaApi chromaApi = this._mConnectionManager.ApiChromaInstance; this._mTextStatus = this._mConnectionManager.ConnectionStatus; GUI.enabled = this._mConnectionManager.Connected; GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label("Unity Plugin - Chroma REST API", new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.Label(this._mTextStatus, new GUILayoutOption[0]); GUILayout.EndHorizontal(); GUILayout.Label("Set a static color on all devices", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); Color backgroundColor = GUI.backgroundColor; GUI.backgroundColor = Color.blue; if (GUILayout.Button("Blue", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(Color.blue); }); } GUI.backgroundColor = Color.green; if (GUILayout.Button("Green", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(Color.green); }); } GUI.backgroundColor = Color.red; if (GUILayout.Button("Red", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(Color.red); }); } GUI.backgroundColor = new Color(1f, 0.5f, 0f); if (GUILayout.Button("Orange", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(new Color(1f, 0.5f, 0f)); }); } GUI.backgroundColor = new Color(0f, 1f, 1f); if (GUILayout.Button("Aqua", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(new Color(0f, 1f, 1f)); }); } GUI.backgroundColor = Color.white; if (GUILayout.Button("White", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectStaticOnAll(Color.white); }); } GUI.backgroundColor = backgroundColor; if (GUILayout.Button("Random", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetKeyboardCustomEffect(); }); } if (GUILayout.Button("Clear", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { this.SetEffectNoneOnAll(); }); } GUILayout.EndHorizontal(); GUILayout.Label("Set a built-in effect on all devices", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("Breathing 1", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_BREATHING, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Color1 = new int?(ChromaUtils.ToBGR(Color.red)); effectInput.Param.Color2 = new int?(ChromaUtils.ToBGR(Color.green)); effectInput.Param.Type = new int?(1); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Breathing 2", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_BREATHING, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Color1 = new int?(ChromaUtils.ToBGR(Color.green)); effectInput.Param.Color2 = new int?(ChromaUtils.ToBGR(Color.yellow)); effectInput.Param.Type = new int?(2); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Reactive 1", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_REACTIVE, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Color = new int?(ChromaUtils.ToBGR(Color.red)); effectInput.Param.Duration = new int?(1); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Reactive 2", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_REACTIVE, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Color = new int?(ChromaUtils.ToBGR(Color.green)); effectInput.Param.Duration = new int?(2); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Reactive 3", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_REACTIVE, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Color = new int?(ChromaUtils.ToBGR(Color.blue)); effectInput.Param.Duration = new int?(3); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Spectrum Cycling", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_SPECTRUMCYCLING, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Wave 1", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_WAVE, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Direction = new int?(1); this.SetEffectOnAll(effectInput); }); } if (GUILayout.Button("Wave 2", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectInput = new EffectInput(EffectType.CHROMA_WAVE, null); effectInput.Param = new EffectInputParam(null, null, null, null, null, null); effectInput.Param.Direction = new int?(2); this.SetEffectOnAll(effectInput); }); } GUILayout.EndHorizontal(); GUILayout.Label("Set a different color to a specific device", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUI.backgroundColor = Color.blue; if (GUILayout.Button("Keyboard", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(Color.blue); ChromaExample01.LogResult("PutKeyboard:", chromaApi.PutKeyboard(effectChromaStatic)); }); } GUI.backgroundColor = Color.green; if (GUILayout.Button("Headset", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(Color.green); ChromaExample01.LogResult("PutHeadset:", chromaApi.PutHeadset(effectChromaStatic)); }); } GUI.backgroundColor = Color.red; if (GUILayout.Button("Mouse", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(Color.red); ChromaExample01.LogResult("PutMouse:", chromaApi.PutMouse(effectChromaStatic)); }); } GUI.backgroundColor = new Color(1f, 0.5f, 0f); if (GUILayout.Button("Mousepad", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(new Color(1f, 0.5f, 0f)); ChromaExample01.LogResult("PutMousepad:", chromaApi.PutMousepad(effectChromaStatic)); }); } GUI.backgroundColor = new Color(0f, 1f, 1f); if (GUILayout.Button("Keypad", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(new Color(0f, 1f, 1f)); ChromaExample01.LogResult("PutKeypad:", chromaApi.PutKeypad(effectChromaStatic)); }); } GUI.backgroundColor = Color.white; if (GUILayout.Button("ChromaLink", new GUILayoutOption[] { GUILayout.Height(50f) })) { ChromaUtils.RunOnThread(delegate { EffectInput effectChromaStatic = ChromaExample01.GetEffectChromaStatic(Color.white); ChromaExample01.LogResult("PutChromaLink:", chromaApi.PutChromaLink(effectChromaStatic)); }); } GUI.backgroundColor = backgroundColor; GUILayout.EndHorizontal(); GUILayout.Label("Play animation...", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); if (GUILayout.Button("Start", new GUILayoutOption[] { GUILayout.Height(50f) })) { this.DoAnimations(); } if (GUILayout.Button("End", new GUILayoutOption[] { GUILayout.Height(50f) })) { this._mPlayAnimation = false; this.StopAnimations(); } GUILayout.EndHorizontal(); GUI.enabled = true; }
// Display the UI in Unity GUI to be compatible with 3.X void OnGUI() { if (null == _mConnectionManager) { GUILayout.Label("Waiting for start..."); return; } ChromaApi chromaApi = _mConnectionManager.ApiChromaInstance; _mTextStatus = _mConnectionManager.ConnectionStatus; GUI.enabled = _mConnectionManager.Connected; GUILayout.BeginHorizontal(); GUILayout.Label("Unity Plugin - Chroma REST API"); GUILayout.FlexibleSpace(); GUILayout.Label(_mTextStatus); GUILayout.EndHorizontal(); GUILayout.Label("Set a static color on all devices"); GUILayout.BeginHorizontal(); Color oldColor = GUI.backgroundColor; const int height = 50; GUI.backgroundColor = Color.blue; if (GUILayout.Button("Blue", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(Color.blue); }); } GUI.backgroundColor = Color.green; if (GUILayout.Button("Green", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(Color.green); }); } GUI.backgroundColor = Color.red; if (GUILayout.Button("Red", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(Color.red); }); } GUI.backgroundColor = new Color(1f, 0.5f, 0f); if (GUILayout.Button("Orange", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(new Color(1f, 0.5f, 0f)); }); } GUI.backgroundColor = new Color(0f, 1f, 1f); if (GUILayout.Button("Aqua", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(new Color(0, 1f, 1f)); }); } GUI.backgroundColor = Color.white; if (GUILayout.Button("White", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectStaticOnAll(Color.white); }); } GUI.backgroundColor = oldColor; if (GUILayout.Button("Random", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetKeyboardCustomEffect(); }); } if (GUILayout.Button("Clear", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { SetEffectNoneOnAll(); }); } GUILayout.EndHorizontal(); GUILayout.Label("Set a built-in effect on all devices"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Breathing 1", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_BREATHING); input.Param = new EffectInputParam(); input.Param.Color1 = ChromaUtils.ToBGR(Color.red); input.Param.Color2 = ChromaUtils.ToBGR(Color.green); input.Param.Type = 1; SetEffectOnAll(input); }); } if (GUILayout.Button("Breathing 2", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_BREATHING); input.Param = new EffectInputParam(); input.Param.Color1 = ChromaUtils.ToBGR(Color.green); input.Param.Color2 = ChromaUtils.ToBGR(Color.yellow); input.Param.Type = 2; SetEffectOnAll(input); }); } if (GUILayout.Button("Reactive 1", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_REACTIVE); input.Param = new EffectInputParam(); input.Param.Color = ChromaUtils.ToBGR(Color.red); input.Param.Duration = 1; SetEffectOnAll(input); }); } if (GUILayout.Button("Reactive 2", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_REACTIVE); input.Param = new EffectInputParam(); input.Param.Color = ChromaUtils.ToBGR(Color.green); input.Param.Duration = 2; SetEffectOnAll(input); }); } if (GUILayout.Button("Reactive 3", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_REACTIVE); input.Param = new EffectInputParam(); input.Param.Color = ChromaUtils.ToBGR(Color.blue); input.Param.Duration = 3; SetEffectOnAll(input); }); } if (GUILayout.Button("Spectrum Cycling", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_SPECTRUMCYCLING); input.Param = new EffectInputParam(); SetEffectOnAll(input); }); } if (GUILayout.Button("Wave 1", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_WAVE); input.Param = new EffectInputParam(); input.Param.Direction = 1; SetEffectOnAll(input); }); } if (GUILayout.Button("Wave 2", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { var input = new EffectInput(EffectType.CHROMA_WAVE); input.Param = new EffectInputParam(); input.Param.Direction = 2; SetEffectOnAll(input); }); } GUILayout.EndHorizontal(); GUILayout.Label("Set a different color to a specific device"); GUILayout.BeginHorizontal(); GUI.backgroundColor = Color.blue; if (GUILayout.Button("Keyboard", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(Color.blue); LogResult("PutKeyboard:", chromaApi.PutKeyboard(input)); }); } GUI.backgroundColor = Color.green; if (GUILayout.Button("Headset", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(Color.green); LogResult("PutHeadset:", chromaApi.PutHeadset(input)); }); } GUI.backgroundColor = Color.red; if (GUILayout.Button("Mouse", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(Color.red); LogResult("PutMouse:", chromaApi.PutMouse(input)); }); } GUI.backgroundColor = new Color(1f, 0.5f, 0f); if (GUILayout.Button("Mousepad", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(new Color(1f, 0.5f, 0f)); LogResult("PutMousepad:", chromaApi.PutMousepad(input)); }); } GUI.backgroundColor = new Color(0f, 1f, 1f); if (GUILayout.Button("Keypad", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(new Color(0f, 1f, 1f)); LogResult("PutKeypad:", chromaApi.PutKeypad(input)); }); } GUI.backgroundColor = Color.white; if (GUILayout.Button("ChromaLink", GUILayout.Height(height))) { // avoid blocking the UI thread ChromaUtils.RunOnThread(() => { EffectInput input = GetEffectChromaStatic(Color.white); LogResult("PutChromaLink:", chromaApi.PutChromaLink(input)); }); } GUI.backgroundColor = oldColor; GUILayout.EndHorizontal(); GUILayout.Label("Play animation..."); GUILayout.BeginHorizontal(); if (GUILayout.Button("Start", GUILayout.Height(height))) { // assets execute on the main thread DoAnimations(); } if (GUILayout.Button("End", GUILayout.Height(height))) { _mPlayAnimation = false; // assets execute on the main thread StopAnimations(); } GUILayout.EndHorizontal(); GUI.enabled = true; }