Ejemplo n.º 1
0
 public static EffectResponseId CreateEffectCustom2D(ChromaDevice2DEnum device, EffectArray2dInput input)
 {
     if (ChromaConnectionManager.Instance.Connected)
     {
         ChromaApi apiChromaInstance = ChromaConnectionManager.Instance.ApiChromaInstance;
         return(ChromaUtils.CreateEffectCustom2D(apiChromaInstance, device, input));
     }
     return(null);
 }
Ejemplo n.º 2
0
 public static EffectIdentifierResponse RemoveEffect(string effectId)
 {
     if (ChromaConnectionManager.Instance.Connected)
     {
         ChromaApi apiChromaInstance = ChromaConnectionManager.Instance.ApiChromaInstance;
         return(ChromaUtils.RemoveEffect(apiChromaInstance, effectId));
     }
     return(null);
 }
Ejemplo n.º 3
0
 public static EffectIdentifierResponse SetEffect(string effectId)
 {
     if (ChromaConnectionManager.Instance.Connected)
     {
         ChromaApi api = ChromaConnectionManager.Instance.ApiChromaInstance;
         return(SetEffect(api, effectId));
     }
     return(null);
 }
Ejemplo n.º 4
0
    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));
    }
Ejemplo n.º 5
0
    private void SetEffectNoneOnAll()
    {
        if (!this._mConnectionManager.Connected)
        {
            Debug.LogError("Chroma client is not yet connected!");
            return;
        }
        ChromaApi apiChromaInstance = this._mConnectionManager.ApiChromaInstance;

        ChromaExample01.LogResult("PutChromaLinkNone:", apiChromaInstance.PutChromaLinkNone());
        ChromaExample01.LogResult("PutHeadsetNone:", apiChromaInstance.PutHeadsetNone());
        ChromaExample01.LogResult("PutKeyboardNone:", apiChromaInstance.PutKeyboardNone());
        ChromaExample01.LogResult("PutKeypadNone:", apiChromaInstance.PutKeypadNone());
        ChromaExample01.LogResult("PutMouseNone:", apiChromaInstance.PutMouseNone());
        ChromaExample01.LogResult("PutMousepadNone:", apiChromaInstance.PutMousepadNone());
    }
Ejemplo n.º 6
0
    private void SetKeyboardCustomEffect()
    {
        if (!this._mConnectionManager.Connected)
        {
            Debug.LogError("Chroma client is not yet connected!");
            return;
        }
        ChromaApi apiChromaInstance = this._mConnectionManager.ApiChromaInstance;

        ChromaExample01.LogResult("PutChromaLinkCustom:", apiChromaInstance.PutChromaLinkCustom(ChromaUtils.CreateRandomColors1D(ChromaDevice1DEnum.ChromaLink)));
        ChromaExample01.LogResult("PutHeadsetCustom:", apiChromaInstance.PutHeadsetCustom(ChromaUtils.CreateRandomColors1D(ChromaDevice1DEnum.Headset)));
        ChromaExample01.LogResult("PutKeyboardCustom:", apiChromaInstance.PutKeyboardCustom(ChromaUtils.CreateRandomColors2D(ChromaDevice2DEnum.Keyboard)));
        ChromaExample01.LogResult("PutKeypadCustom:", apiChromaInstance.PutKeypadCustom(ChromaUtils.CreateRandomColors2D(ChromaDevice2DEnum.Keypad)));
        ChromaExample01.LogResult("PutMouseCustom:", apiChromaInstance.PutMouseCustom(ChromaUtils.CreateRandomColors2D(ChromaDevice2DEnum.Mouse)));
        ChromaExample01.LogResult("PutMousepadCustom:", apiChromaInstance.PutMousepadCustom(ChromaUtils.CreateRandomColors1D(ChromaDevice1DEnum.Mousepad)));
    }
Ejemplo n.º 7
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)));
    }
Ejemplo n.º 8
0
    /// <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));
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Clear effect on all devices using PUT
    /// </summary>
    void SetEffectNoneOnAll()
    {
        if (!_mConnectionManager.Connected)
        {
            Debug.LogError("Chroma client is not yet connected!");
            return;
        }

        ChromaApi chromaApi = _mConnectionManager.ApiChromaInstance;

        LogResult("PutChromaLinkNone:", chromaApi.PutChromaLinkNone());
        LogResult("PutHeadsetNone:", chromaApi.PutHeadsetNone());
        LogResult("PutKeyboardNone:", chromaApi.PutKeyboardNone());
        LogResult("PutKeypadNone:", chromaApi.PutKeypadNone());
        LogResult("PutMouseNone:", chromaApi.PutMouseNone());
        LogResult("PutMousepadNone:", chromaApi.PutMousepadNone());
    }
Ejemplo n.º 10
0
        private static EffectResponseId CreateEffectCustom2D(ChromaApi api, ChromaDevice2DEnum device, EffectArray2dInput input)
        {
            if (null == api)
            {
                Debug.LogError("CreateEffectCustom2D: Parameter api is null!");
                return(null);
            }
            if (null == input)
            {
                Debug.LogError("CreateEffectCustom2D: Parameter input is null!");
                return(null);
            }
            int maxRow    = GetMaxRow(device);
            int maxColumn = GetMaxColumn(device);

            if (maxRow != input.Count ||
                (input.Count > 0 &&
                 maxColumn != input[0].Count))
            {
                Debug.LogError(string.Format("CreateEffectCustom2D Array size mismatch row: %d==%d column: %d==%d!",
                                             maxRow,
                                             input.Count,
                                             maxColumn,
                                             input.Count > 0 ? input[0].Count : 0));
            }

            try
            {
                switch (device)
                {
                case ChromaDevice2DEnum.Keyboard:
                    return(api.PostKeyboardCustom(input));

                case ChromaDevice2DEnum.Keypad:
                    return(api.PostKeypadCustom(input));

                case ChromaDevice2DEnum.Mouse:
                    return(api.PostMouseCustom(input));
                }
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 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));
    }
Ejemplo n.º 12
0
        private static EffectResponseId CreateEffectCustom1D(ChromaApi api, ChromaDevice1DEnum device, EffectArray1dInput input)
        {
            if (null == api)
            {
                Debug.LogError("CreateEffectCustom1D: Parameter api is null!");
                return(null);
            }
            if (null == input)
            {
                Debug.LogError("CreateEffectCustom1D: Parameter input is null!");
                return(null);
            }
            int maxLeds = GetMaxLeds(device);

            if (maxLeds != input.Count)
            {
                Debug.LogError(string.Format("CreateEffectCustom1D Array size mismatch element: %d==%d!",
                                             maxLeds,
                                             input.Count));
            }

            try
            {
                switch (device)
                {
                case ChromaDevice1DEnum.ChromaLink:
                    return(api.PostChromaLinkCustom(input));

                case ChromaDevice1DEnum.Headset:
                    return(api.PostHeadsetCustom(input));

                case ChromaDevice1DEnum.Mousepad:
                    return(api.PostMousepadCustom(input));
                }
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 13
0
        private static EffectIdentifierResponse RemoveEffect(ChromaApi api, string effectId)
        {
            if (api == null)
            {
                Debug.LogError("RemoveEffect: Parameter api is null!");
                return(null);
            }
            if (string.IsNullOrEmpty(effectId))
            {
                Debug.LogError("RemoveEffect: Parameter effectId cannot be null or empty!");
                return(null);
            }
            EffectIdentifierInput data = new EffectIdentifierInput(effectId, null);

            try
            {
                return(api.RemoveEffect(data));
            }
            catch (Exception)
            {
            }
            return(null);
        }
Ejemplo n.º 14
0
        private static EffectIdentifierResponse SetEffect(ChromaApi api, string effectId)
        {
            if (null == api)
            {
                Debug.LogError("SetEffect: Parameter api is null!");
                return(null);
            }
            if (string.IsNullOrEmpty(effectId))
            {
                Debug.LogError("SetEffect: Parameter effectId cannot be null or empty!");
                return(null);
            }

            var input = new EffectIdentifierInput(effectId, null);

            try
            {
                return(api.PutEffect(input));
            }
            catch (Exception)
            {
            }
            return(null);
        }
 /// <summary>
 /// Reset the connections
 /// </summary>
 private void ResetConnections()
 {
     // clear the references
     _sApiRazerInstance  = null;
     _sApiChromaInstance = null;
 }
    /// <summary>
    /// Initialize Chroma by hitting the REST server and set the API port
    /// </summary>
    /// <returns></returns>
    void PostChromaSdk()
    {
        _sConnectionIsActive = true;

        //LogOnMainThread("PostChromaSdk:");
        bool reconnect = false;

        try
        {
            if (null != _sApiRazerInstance)
            {
                return;
            }

            // use the Razer API to get the session
            _sApiRazerInstance = new RazerApi();

            if (null == _mInfo)
            {
                SetupDefaultInfo();
            }

            PostChromaSdkResponse result = null;
            DateTime timeout             = DateTime.Now + TimeSpan.FromSeconds(5);
            Thread   thread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    ConnectionStatus = VERSION_CHECK;
                    GetChromaSdkResponse getResult = _sApiRazerInstance.GetChromaSdk();

                    if (null == getResult ||
                        string.IsNullOrEmpty(getResult.Version))
                    {
                        ConnectionStatus = RECONNECT_VERSION_IS_NULL;
                        reconnect        = true;
                        return;
                    }

                    string[] parts = getResult.Version.Split(".".ToCharArray());
                    if (parts.Length != 3)
                    {
                        ConnectionStatus = RECONNECT_VERSION_IS_UNKNOWN;
                        reconnect        = true;
                        return;
                    }
                    int[] version = new int[3];
                    if (int.TryParse(parts[0], out version[0]) &&
                        int.TryParse(parts[1], out version[1]) &&
                        int.TryParse(parts[2], out version[2]))
                    {
                        if (version[0] >= 2 ||
                            (version[0] == 2 &&
                             version[1] >= 3) ||
                            (version[0] == 2 &&
                             version[1] == 3 &&
                             version[2] >= 6))
                        {
                            //good!
                        }
                        else
                        {
                            ConnectionStatus = RECONNECT_SYNAPSE_OUTDATED;
                            reconnect        = true;
                        }
                    }
                    else
                    {
                        ConnectionStatus = RECONNECT_VERSION_IS_UNKNOWN;
                        reconnect        = true;
                    }
                }
                catch (Exception)
                {
                    ConnectionStatus = RECONNECT_SERVER_UNREACHABLE;
                    reconnect        = true;
                }

                if (!reconnect)
                {
                    try
                    {
                        //LogOnMainThread("Initializing...");
                        ConnectionStatus = CONNECTING;
                        result           = _sApiRazerInstance.PostChromaSdk(_mInfo);
                    }
                    catch (Exception)
                    {
                        ConnectionStatus = RECONNECT_SERVER_UNREACHABLE;
                        reconnect        = true;
                    }
                }
            }));
            thread.Start();
            while (_sWaitForExit &&
                   DateTime.Now < timeout &&
                   thread.IsAlive)
            {
                Thread.Sleep(0);
            }
            if (_sWaitForExit &&
                timeout < DateTime.Now &&
                thread.IsAlive)
            {
                //Debug.LogError("Connect: Timeout detected!");
                thread.Abort();
                reconnect        = true;
                ConnectionStatus = RECONNECT_RAZER_API_TIMEOUT;
                ThreadWaitForSecond();
            }

            if (_sWaitForExit)
            {
                if (null != result)
                {
                    //LogOnMainThread(result);

                    // setup the api instance with the session uri
                    _sApiChromaInstance = new ChromaApi(result.Uri);

                    //LogOnMainThread("Init complete.");

                    // use heartbeat to keep the REST API alive
                    DoHeartbeat();
                }
                else
                {
                    //Debug.LogError("Connect: Result is null!");
                    reconnect = true;
                }
            }
        }
        catch (Exception)
        {
            reconnect = true;
        }

        if (reconnect)
        {
            //LogErrorOnMainThread(string.Format("Exception when calling RazerApi.PostChromaSdk: {0}", e));
            _sApiRazerInstance = null;

            //attempt reconnect
            // Coroutines can only start from the main thread
            RunOnMainThread(() =>
            {
                if (_sWaitForExit)
                {
                    // retry
                    SafeStartCoroutine("Initialize", Initialize());
                }
            });
        }

        _sConnectionIsActive = false;
    }
Ejemplo n.º 17
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;
    }
Ejemplo n.º 18
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;
    }