public void Reset(bool loadAndStore = true)
        {
            if (loadAndStore)
            {
                LoadDataHolder();
            }
            EditorData.HighestDistributedLevel = -1;

            EditorData.Grids.Clear();
            Data.Clear();

            CleanupPlacedObjects(EditorData, 0);
            EditorData.PlacedObjects.Clear();

            UIData.SelectedLevelIndex = 0;
            UIData.InsertLevelAt      = 0;
            EditorData.Grids.Add(new StoredGrid());
            EditorData.PlacedObjects.Add(new GameObjectList());
            Data.Add(new PoissonData());

            SelectedData = Data[UIData.SelectedLevelIndex];

            ModeData.RealtimePreview = false;

            EditorData.UpdateAllowVisualTransformChanges(DataHolder.IsWindow);
            EditorData.UpdateVisualTexture(ModeData, SelectedData);

            if (loadAndStore)
            {
                StoreDataHolder();
            }
        }
 private void SetReadOnly(int end)
 {
     for (int i = 0; i <= end; ++i)
     {
         EditorData.PlacedObjects[i].Clear();
         EditorData.Grids[i].ReadOnly = true;
     }
     EditorData.UpdateAllowVisualTransformChanges(DataHolder.IsWindow);
     SceneView.RepaintAll();
 }
        private bool CreateDistributionButtons(float halfWidth, EditorGUI.ChangeCheckScope changeScope)
        {
            bool needSaving = false;

            GUILayout.Label("", GUI.skin.horizontalSlider);

            EditorGUILayout.BeginVertical(RowStyle, GUILayout.MaxWidth(halfWidth * 2 + ColumnGap));
            bool isValidSurface, preValid, currValid, postValid;
            int  highestValid;

            ValidateSettings(true, out isValidSurface, out preValid, out currValid, out postValid, out highestValid);
            EditorGUILayout.EndVertical();

            if (DataHolder.IsWindow)
            {
                EditorGUILayout.BeginHorizontal(RowStyle);
                EditorGUILayout.BeginVertical(LeftColumnStyle, GUILayout.MaxWidth(halfWidth));
            }

            if (ModeData.RealtimePreview && isValidSurface && highestValid >= 0 && !EditorData.Grids[UIData.SelectedLevelIndex].ReadOnly && (changeScope.changed || (!EditorData.LastFrameValid && highestValid > EditorData.HighestDistributedLevel)))
            {
                if (_modeHasChanged)
                {
                    DistributePoisson(0, highestValid, true);
                }
                else
                {
                    DistributePoisson(Mathf.Max(Mathf.Min(EditorData.HighestDistributedLevel, UIData.SelectedLevelIndex), 0), highestValid, true);
                }
            }
            EditorData.LastFrameValid = isValidSurface && preValid && currValid && postValid;

            using (new EditorGUI.DisabledScope(!isValidSurface))
            {
                using (new EditorGUI.DisabledScope(!(preValid && currValid) || EditorData.Grids[UIData.SelectedLevelIndex].ReadOnly))
                {
                    if (GUILayout.Button(new GUIContent("Distribute Level: [0 - " + UIData.SelectedLevelIndex + "]"), ButtonStyle))
                    {
                        DistributePoisson(0, UIData.SelectedLevelIndex, false);
                    }
                }
                using (new EditorGUI.DisabledScope(!(currValid && EditorData.HighestDistributedLevel >= UIData.SelectedLevelIndex - 1) || EditorData.Grids[UIData.SelectedLevelIndex].ReadOnly))
                {
                    if (GUILayout.Button(new GUIContent("Distribute Level: " + UIData.SelectedLevelIndex), ButtonStyle))
                    {
                        DistributePoisson(UIData.SelectedLevelIndex, UIData.SelectedLevelIndex, false);
                    }
                }
                using (new EditorGUI.DisabledScope(!(currValid && postValid && EditorData.HighestDistributedLevel >= UIData.SelectedLevelIndex - 1) || EditorData.Grids.Last().ReadOnly))
                {
                    if (GUILayout.Button(new GUIContent("Distribute Level: [" + UIData.SelectedLevelIndex + " - " + (Data.Count - 1) + "]"), ButtonStyle))
                    {
                        DistributePoisson(UIData.SelectedLevelIndex, Data.Count - 1, false);
                    }
                }
                using (new EditorGUI.DisabledScope(!(preValid && currValid && postValid) || EditorData.Grids.Last().ReadOnly))
                {
                    if (GUILayout.Button(new GUIContent("Distribute All"), ButtonStyle))
                    {
                        DistributePoisson(0, Data.Count - 1, false);
                    }
                }
            }

            if (DataHolder.IsWindow)
            {
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(RightColumnStyle, GUILayout.MaxWidth(halfWidth));
                using (new EditorGUI.DisabledScope(EditorData.Grids[UIData.SelectedLevelIndex].ReadOnly || EditorData.HighestDistributedLevel < UIData.SelectedLevelIndex))
                {
                    if (GUILayout.Button(new GUIContent("Apply [0 - " + UIData.SelectedLevelIndex + "]"), ButtonStyle))
                    {
                        SetReadOnly(UIData.SelectedLevelIndex);
                        UIData.InsertLevelAt = Mathf.Max(Data.Count, UIData.SelectedLevelIndex + 1);
                        needSaving           = true;
                    }
                }
                using (new EditorGUI.DisabledScope(EditorData.HighestDistributedLevel == -1 || EditorData.Grids[EditorData.HighestDistributedLevel].ReadOnly))
                {
                    if (GUILayout.Button(new GUIContent("Apply [0 - " + EditorData.HighestDistributedLevel + "]"), ButtonStyle))
                    {
                        SetReadOnly(EditorData.HighestDistributedLevel);
                        UIData.InsertLevelAt = Mathf.Max(Data.Count, EditorData.HighestDistributedLevel + 1);
                        needSaving           = true;
                    }
                }
            }
            using (new EditorGUI.DisabledScope(EditorData.HighestDistributedLevel == -1 || EditorData.Grids[EditorData.HighestDistributedLevel].ReadOnly))
            {
                if (GUILayout.Button(new GUIContent("Clear Unapplied Levels"), ButtonStyle))
                {
                    CleanupPlacedObjects(EditorData, 0);

                    EditorData.HighestDistributedLevel = -1;
                    for (int i = 0; i < EditorData.Grids.Count; ++i)
                    {
                        if (EditorData.Grids[i].ReadOnly)
                        {
                            EditorData.HighestDistributedLevel = i;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (EditorData.HighestDistributedLevel == -1)
                    {
                        EditorData.UpdateAllowVisualTransformChanges(DataHolder.IsWindow);
                    }
                }
            }
            using (new EditorGUI.DisabledScope(EditorData.HighestDistributedLevel == -1))
            {
                if (GUILayout.Button(new GUIContent("Reset Settings"), ButtonStyle))
                {
                    Reset(false);
                    needSaving = true;
                }
            }

            if (DataHolder.IsWindow)
            {
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
            return(needSaving);
        }