예제 #1
0
    void OnGUI()
    {
        GUILayout.BeginVertical();

        //Creates the camera selection drop down menu
        GUILayout.BeginHorizontal();
        selectedCameraIndex = EditorGUILayout.Popup("Choose a Camera", selectedCameraIndex, cameraOptions, EditorStyles.popup);
        GUILayout.EndHorizontal();

        //Buttons and status
        bool captureButton = false;

        GUILayout.BeginHorizontal();
        bool streamButton = GUILayout.Button(streamText, GUILayout.Width(200));

        GUILayout.Space(5);
        if (GUIKeyDown(KeyCode.Space))
        {
            streamButton = true;
        }
        if (!isStreaming)
        {
            GUI.enabled = false;
        }
        captureButton = GUILayout.Button("Place Objects", GUILayout.ExpandWidth(true));
        if (!isStreaming)
        {
            GUI.enabled = true;
        }
        GUILayout.Space(5);
        bool undoButton = GUILayout.Button("Undo Last", GUILayout.Width(200));

        //bool clearButton = GUILayout.Button("Clear All", GUILayout.Width(100));
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();


        //We interrupt this gross UI stuff to bring you some logic
        if (undoButton)
        {
            while (GameObject.FindGameObjectWithTag("scanned_group") != null)
            {
                clearObjectsInScene();
            }
        }

        if (streamButton)
        {
            //if streaming, stop it
            if (isStreaming)
            {
                isStreaming = false;
                streamText  = "Start Stream";
                if (camera != null)
                {
                    camera.StopCapture();
                }
            }

            //if not streaming, start it
            else
            {
                isStreaming = true;
                streamText  = "Stop Stream";

                //Create an instance of the camera
                cameraName = cameraOptions[selectedCameraIndex];
                cameraType = cameraNameLookup[cameraName];

                if (cameraType != null)
                {
                    camera = (ICamera)Activator.CreateInstance(cameraType);
                    camera.StartCapture();
                }
            }
        }

        if (captureButton && camera != null)
        {
            runningAlgorithm = true;
        }

        //Update ColorDepthImage
        if (isStreaming)
        {
            updateCam();
        }

        drawStreams();
        algorithm.DrawSettings();

        updateGUI = false;
    }