Example #1
0
    private void OnGUI()
    {
        GUILayout.BeginVertical();

        _camIndex = GUILayout.TextField(_camIndex);

        if (GUILayout.Button("Open"))
        {
            int camIndex = 0;

            if (int.TryParse(_camIndex, out camIndex))
            {
                WebCamera webCam = WebCamera.Get(camIndex);

                webCam.Open(1280, 720);

                if (imgCamera != null)
                {
                    imgCamera.texture = webCam.CamTexture;
                }
            }
        }

        if (GUILayout.Button("Pause"))
        {
            int camIndex = 0;

            if (int.TryParse(_camIndex, out camIndex))
            {
                WebCamera.Get(camIndex).Pause();
            }
        }

        if (GUILayout.Button("Close"))
        {
            int camIndex = 0;

            if (int.TryParse(_camIndex, out camIndex))
            {
                WebCamera.Get(camIndex).Close();

                if (imgCamera != null)
                {
                    imgCamera.texture = null;
                }
            }
        }

        if (GUILayout.Button("Reconnect"))
        {
            int camIndex = 0;

            if (int.TryParse(_camIndex, out camIndex))
            {
                WebCamera.Get(camIndex).ReConnect(1280, 720);
            }
        }

        if (GUILayout.Button("Snapshot"))
        {
            int camIndex = 0;

            if (int.TryParse(_camIndex, out camIndex))
            {
                WebCamera.Get(camIndex).Snapshot((Texture2D tex) =>
                {
                    if (imgSnapshot != null)
                    {
                        imgSnapshot.texture = tex;
                    }
                });
            }
        }

        GUILayout.EndVertical();
    }