Пример #1
0
    public override void OnInspectorGUI()
    {
        //DrawDefaultInspector();
        _targetsChanged = 0;
        _content        = (ColorTrackerPanel)target;
        _colorTargets   = _content.colorTargets;

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Options", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();

        GUI.enabled        = !Application.isPlaying;
        _content.inputType = (InputType)EditorGUILayout.EnumPopup("Input", _content.inputType);
        _content.accuracy  = (TrackerAccuracy)EditorGUILayout.EnumPopup("Accuracy", _content.accuracy);

        GUI.enabled = true;
        _content.enableColorTrack = EditorGUILayout.Toggle(enableColorTrackDescription, _content.enableColorTrack);

        if (_content.enableColorTrack)
        {
            _content.useKalmanFilter = EditorGUILayout.Toggle(kalmanDescription, _content.useKalmanFilter);
        }

        _content.enableColorMap = EditorGUILayout.Toggle(enableColorMapDescription, _content.enableColorMap);

        if (_content.enableColorMap)
        {
            _content.colorMapPointSpacing = EditorGUILayout.IntField(pointSpacingDescription, _content.colorMapPointSpacing);
        }

        GUI.enabled          = (_content.enableColorTrack || _content.enableColorMap);
        _content.playOnAwake = EditorGUILayout.Toggle(playOnAwakeDescription, _content.playOnAwake);

        EditorGUILayout.Separator();

        serializedObject.Update();
        list.DoLayoutList();
        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.LabelField("Controls", EditorStyles.boldLabel);

        GUILayout.BeginHorizontal();

        ColorTracker tracker         = _content.GetColorTracker();
        bool         controlsEnabled = tracker != null;

        GUI.enabled = controlsEnabled && !tracker.isRunning;
        if (GUILayout.Button("Start", GUILayout.Height(30)))
        {
            _content.StartColorTracker();
        }

        GUI.enabled = controlsEnabled && tracker.isRunning;
        if (GUILayout.Button("Stop", GUILayout.Height(30)))
        {
            _content.StopColorTracker();
        }

        GUI.enabled = _colorTargets.Count > 0;
        if (GUILayout.Button("Remove all targets", GUILayout.Height(30)))
        {
            _colorTargets.Clear();
            OnChangedHandler(null);
        }

        if (_targetsChanged > 0 && Application.isPlaying)
        {
            _content.UpdateColorTargets();
        }

        GUILayout.EndHorizontal();
        GUI.enabled = true;
        EditorGUILayout.Separator();

        if (_colorTargets.Count == 0)
        {
            EditorGUILayout.HelpBox("You must add at least one target!", MessageType.Error);
        }

        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(target);
        }
    }