public override void OnInspectorGUI()
        {
            EditorGUILayout.PropertyField(_probeMaskProperty);
            EditorGUILayout.PropertyField(_ignoreMaskProperty);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(_assetProperty);
            EditorGUI.EndChangeCheck();

            if (GUI.changed)
                TryFindFogDataAsset();

            GUI.enabled = !EditorApplication.isPlaying && _dataAsset && _currentState == State.Idle;
            DrawDebugGUI();

            if (GUILayout.Button("Generate Vision Probes"))
            {
                if (EditorApplication.isPlaying)
                {
                    _errorMessage = "Cannot generate probes while in playmode.";
                }
                else
                {
                    var result = EditorUtility.DisplayDialog("Probe Generation",
                        "Are you sure you want to generate probes? This may take some time.", "Yes", "No");

                    if (result)
                    {
                        _errorMessage = null;
                        TryFindFogDataAsset();

                        _currentJob = EditorProgressJob.Start(GenerateProbeData());

                        //  Force a clean up
                        GC.Collect();
                    }
                }
            }

            GUI.enabled = true;

            VisionProbeGenerationProgressBar();

            if (!string.IsNullOrEmpty(_errorMessage))
                EditorGUILayout.HelpBox(_errorMessage, MessageType.Error);

            serializedObject.ApplyModifiedProperties();
        }
 private void OnDisable()
 {
     EditorApplication.update -= UpdateState;
     _tempProbeData = null;
     _currentJob = null;
     _currentState = State.Idle;
 }
        private void UpdateState()
        {
            if (_currentState == State.GeneratingProbes)
            {
                if (_currentJob.Finished)
                {
                    _currentJob = EditorProgressJob.Start(FindProbeNeighbours());
                }
            }
            else
            {
                if (_currentState == State.LinkingNeighbours)
                {
                    if (_currentJob.Finished)
                    {
                        _dataAsset.SetData(_tempProbeData);
                        EditorUtility.SetDirty(_dataAsset);

                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                        CancelCurrentJob();

                        Repaint();
                    }
                }
            }
        }
 private void CancelCurrentJob()
 {
     _currentJob.Stop();
     _currentJob = null;
     _currentState = State.Idle;
     EditorUtility.ClearProgressBar();
     EditorApplication.update -= UpdateState;
 }