private void OnClickFillColumn(int column)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var rows      = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = rows[i];
                if (column < row.Count && column < maxColumn)
                {
                    row[column] = ChromaUtils.ToBGR(_mColor);
                }
            }
            frames[_mCurrentFrame] = rows;
        }
        animation.Frames = frames;
    }
    private void OnClickSaturateButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var frame     = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    Color color = ChromaUtils.ToRGB(row[j]);
                    float max   = Mathf.Max(Mathf.Max(color.r, color.g), color.b);
                    color  = Color.Lerp(Color.black, _mColor, max);
                    row[j] = ChromaUtils.ToBGR(color);
                }
            }
        }
        animation.Frames = frames;
    }
    private void OnClickFillRow(int row)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var rows      = frames[_mCurrentFrame];
            if (row < rows.Count && row < maxRow)
            {
                var colors = rows[row];
                for (int j = 0; j < maxColumn; ++j)
                {
                    colors[j] = ChromaUtils.ToBGR(_mColor);
                }
            }
            frames[_mCurrentFrame] = rows;
        }
        animation.Frames = frames;
    }
    private void OnClickDarkenButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var frame     = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    Color color = ChromaUtils.ToRGB(row[j]);
                    color.r *= 0.75f;
                    color.g *= 0.75f;
                    color.b *= 0.75f;
                    row[j]   = ChromaUtils.ToBGR(color);
                }
            }
        }
        animation.Frames = frames;
    }
Beispiel #5
0
    private void OnClickDarkenButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            var frame   = frames[_mCurrentFrame];
            for (int i = 0; i < maxLeds; ++i)
            {
                Color color = ChromaUtils.ToRGB((int)frame[i]);
                color.r *= 0.75f;
                color.g *= 0.75f;
                color.b *= 0.75f;
                frame[i] = ChromaUtils.ToBGR(color);
            }
        }
        animation.Frames = frames;
    }
Beispiel #6
0
    private void OnClickSaturateButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds = ChromaUtils.GetMaxLeds(device);
            var frame   = frames[_mCurrentFrame];
            for (int i = 0; i < maxLeds; ++i)
            {
                Color color = ChromaUtils.ToRGB((int)frame[i]);
                float max   = Mathf.Max(Mathf.Max(color.r, color.g), color.b);
                color    = Color.Lerp(Color.black, _mColor, max);
                frame[i] = ChromaUtils.ToBGR(color);
            }
        }
        animation.Frames = frames;
    }
Beispiel #7
0
    private static EffectInput GetEffectChromaStatic(Color color)
    {
        EffectInput effectInput = new EffectInput(EffectType.CHROMA_NONE, null);

        effectInput.Effect = EffectType.CHROMA_STATIC;
        int value = ChromaUtils.ToBGR(color);

        effectInput.Param = new EffectInputParam(new int?(value), null, null, null, null, null);
        return(effectInput);
    }
Beispiel #8
0
    /// <summary>
    /// Get Effect: CHROMA_STATIC
    /// </summary>
    /// <param name="color"></param>
    /// <returns></returns>
    private static EffectInput GetEffectChromaStatic(Color color)
    {
        var input = new EffectInput();

        input.Effect = EffectType.CHROMA_STATIC;
        int bgrInt = ChromaUtils.ToBGR(color);

        input.Param = new EffectInputParam(bgrInt);
        return(input);
    }
    private void OnClickColor(int row, int column)
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame < frames.Count)
        {
            int color = ChromaUtils.ToBGR(_mColor);
            frames[_mCurrentFrame][row][column] = color;
            Repaint();
        }
        animation.Frames = frames;
    }
Beispiel #10
0
    private void SetEffectStaticOnAll(Color color)
    {
        if (!this._mConnectionManager.Connected)
        {
            Debug.LogError("Chroma client is not yet connected!");
            return;
        }
        ChromaApi apiChromaInstance = this._mConnectionManager.ApiChromaInstance;
        int       value             = ChromaUtils.ToBGR(color);

        ChromaExample01.LogResult("PutChromaLinkStatic:", apiChromaInstance.PutChromaLinkStatic(new int?(value)));
        ChromaExample01.LogResult("PutHeadsetStatic:", apiChromaInstance.PutHeadsetStatic(new int?(value)));
        ChromaExample01.LogResult("PutKeyboardStatic:", apiChromaInstance.PutKeyboardStatic(new int?(value)));
        ChromaExample01.LogResult("PutKeypadStatic:", apiChromaInstance.PutKeypadStatic(new int?(value)));
        ChromaExample01.LogResult("PutMouseStatic:", apiChromaInstance.PutMouseStatic(new int?(value)));
        ChromaExample01.LogResult("PutMousepadStatic:", apiChromaInstance.PutMousepadStatic(new int?(value)));
    }
Beispiel #11
0
    /// <summary>
    /// Set static effect on all devices using PUT
    /// </summary>
    /// <param name="color"></param>
    void SetEffectStaticOnAll(Color color)
    {
        if (!_mConnectionManager.Connected)
        {
            Debug.LogError("Chroma client is not yet connected!");
            return;
        }

        ChromaApi chromaApi = _mConnectionManager.ApiChromaInstance;
        int       bgrInt    = ChromaUtils.ToBGR(color);

        LogResult("PutChromaLinkStatic:", chromaApi.PutChromaLinkStatic(bgrInt));
        LogResult("PutHeadsetStatic:", chromaApi.PutHeadsetStatic(bgrInt));
        LogResult("PutKeyboardStatic:", chromaApi.PutKeyboardStatic(bgrInt));
        LogResult("PutKeypadStatic:", chromaApi.PutKeypadStatic(bgrInt));
        LogResult("PutMouseStatic:", chromaApi.PutMouseStatic(bgrInt));
        LogResult("PutMousepadStatic:", chromaApi.PutMousepadStatic(bgrInt));
    }
    private void OnClickContrastButton()
    {
        ChromaSDKAnimation2D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice2DEnum device = animation.Device;
            int maxRow    = ChromaUtils.GetMaxRow(device);
            int maxColumn = ChromaUtils.GetMaxColumn(device);
            var frame     = frames[_mCurrentFrame];
            for (int i = 0; i < maxRow; ++i)
            {
                var row = frame[i];
                for (int j = 0; j < maxColumn; ++j)
                {
                    Color color = ChromaUtils.ToRGB(row[j]);
                    float avg   = (color.r + color.g + color.b) / 3f;
                    if (avg < 0.5f)
                    {
                        color.r *= 0.75f;
                        color.g *= 0.75f;
                        color.b *= 0.75f;
                    }
                    else if (avg > 0.5f)
                    {
                        color.r = Mathf.Min(1f, color.r * 1.25f);
                        color.g = Mathf.Min(1f, color.g * 1.25f);
                        color.b = Mathf.Min(1f, color.b * 1.25f);
                    }
                    row[j] = ChromaUtils.ToBGR(color);
                }
            }
        }
        animation.Frames = frames;
    }
Beispiel #13
0
    private void OnClickFillButton()
    {
        ChromaSDKAnimation1D animation = GetAnimation();

        EditorUtility.SetDirty(animation);
        var frames = animation.Frames; //copy

        Unload();

        if (_mCurrentFrame >= 0 &&
            _mCurrentFrame < frames.Count)
        {
            ChromaDevice1DEnum device = animation.Device;
            int maxLeds  = ChromaUtils.GetMaxLeds(device);
            var elements = ChromaUtils.CreateColors1D(device);
            for (int i = 0; i < maxLeds; ++i)
            {
                elements[i] = ChromaUtils.ToBGR(_mColor);
            }
            frames[_mCurrentFrame] = elements;
        }
        animation.Frames = frames;
    }
    private void CaptureFrame()
    {
        if (_mAnimation && _mRenderTexture && _mRenderCamera)
        {
            if (_mAnimation is ChromaSDKAnimation1D)
            {
                ChromaSDKAnimation1D animation = (ChromaSDKAnimation1D)_mAnimation;
                animation.Unload();
                int maxLeds = ChromaUtils.GetMaxLeds(animation.Device);

                _mTempTexture        = new Texture2D(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, TextureFormat.RGB24, false);
                RenderTexture.active = _mRenderTexture;
                _mRenderCamera.Render();
                DisplayRenderTexture(0, maxLeds, 1);
                _mTempTexture.ReadPixels(new Rect(0, 0, _mTempTexture.width, _mTempTexture.height), 0, 0, false);
                _mTempTexture.Apply();
                TextureScale.Bilinear(_mTempTexture, maxLeds, 1);
                _mTempTexture.Apply();
                RenderTexture.active = null;
                Color[] pixels = _mTempTexture.GetPixels();
                List <EffectArray1dInput> frames = animation.Frames;
                EffectArray1dInput        frame  = ChromaUtils.CreateColors1D(animation.Device);
                int index = 0;
                if (frame.Count > 0)
                {
                    for (int i = 0; i < maxLeds; ++i)
                    {
                        Color color = pixels[index];
                        frame[i] = ChromaUtils.ToBGR(color);
                        ++index;
                    }
                }
#if !SHOW_TEMP_TEXTURE
                DestroyImmediate(_mTempTexture);
#endif
                frames.Add(frame);
                animation.Frames = frames;
                ChromaSDKAnimationBaseEditor.GoToLastFrame();
            }
            else if (_mAnimation is ChromaSDKAnimation2D)
            {
                ChromaSDKAnimation2D animation = (ChromaSDKAnimation2D)_mAnimation;
                animation.Unload();
                int maxRow    = ChromaUtils.GetMaxRow(animation.Device);
                int maxColumn = ChromaUtils.GetMaxColumn(animation.Device);

                _mTempTexture        = new Texture2D(RENDER_TEXTURE_SIZE, RENDER_TEXTURE_SIZE, TextureFormat.RGB24, false);
                RenderTexture.active = _mRenderTexture;
                _mRenderCamera.Render();
                DisplayRenderTexture(0, maxColumn, maxRow);
                _mTempTexture.ReadPixels(new Rect(0, 0, _mTempTexture.width, _mTempTexture.height), 0, 0, false);
                _mTempTexture.Apply();
                TextureScale.Bilinear(_mTempTexture, maxColumn, maxRow);
                _mTempTexture.Apply();
                RenderTexture.active = null;
                Color[] pixels = _mTempTexture.GetPixels();
                List <EffectArray2dInput> frames = animation.Frames;
                EffectArray2dInput        frame  = ChromaUtils.CreateColors2D(animation.Device);
                int index = 0;
                for (int i = maxRow - 1; i >= 0; --i)
                {
                    List <int> row = frame[i];
                    for (int j = 0; j < maxColumn; ++j)
                    {
                        Color color = pixels[index];
                        row[j] = ChromaUtils.ToBGR(color);
                        ++index;
                    }
                }
#if !SHOW_TEMP_TEXTURE
                DestroyImmediate(_mTempTexture);
#endif
                frames.Add(frame);
                animation.Frames = frames;
                ChromaSDKAnimationBaseEditor.GoToLastFrame();
            }
        }
    }
Beispiel #15
0
    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;
    }
Beispiel #16
0
    // 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;
    }