Example #1
0
 /// <summary>
 /// Pastes the details from another brush
 /// </summary>
 public void PasteDetails(BrushObject brush)
 {
     if (brush != null)
     {
         parentContainer     = brush.parentContainer;
         allowIntercollision = brush.allowIntercollision;
         alignToSurface      = brush.alignToSurface;
         randomizeXRotation  = brush.randomizeXRotation;
         randomizeYRotation  = brush.randomizeYRotation;
         randomizeZRotation  = brush.randomizeZRotation;
         density             = brush.density;
         brushSize           = brush.brushSize;
         minScale            = brush.minScale;
         maxScale            = brush.maxScale;
         offsetFromPivot     = brush.offsetFromPivot;
         rotOffsetFromPivot  = brush.rotOffsetFromPivot;
     }
 }
        void OnGUI()
        {
            if (!Application.isPlaying)
            {
                SerializedObject serializedObject_brushObject = null;
                int prevSelectedBrushCollectionIndex          = selectedBrushCollectionIndex;
                if (brushes != null)
                {
                    serializedObject_brushObject = new SerializedObject(brushes);
                }
                EditorGUIUtility.wideMode = true;


                #region Header

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Brush Collection:", EditorStyles.boldLabel);
                BrushCollection.BrushCollectionList brushCollectionList = BrushCollection.GetBrushCollectionsInProject();
                selectedBrushCollectionIndex = EditorGUILayout.Popup(selectedBrushCollectionIndex, brushCollectionList.GetNameList());
                if (prevSelectedBrushCollectionIndex != selectedBrushCollectionIndex)
                {                                                     //select only when brush collection changed
                    brushes = brushCollectionList.brushCollections[selectedBrushCollectionIndex];
                    brushes.SetLastUsedBrushCollection();
                }
                if (GUILayout.Button("+"))
                {
                    StringPopupWindow.Init(this, BrushCollection.CreateInstance, BrushCollection.newBrushCollectionName, "Create new BrushCollection", "Asset Name");
                }
                EditorGUILayout.EndHorizontal();


                //The active BrushList asset
                //brushes = EditorGUILayout.ObjectField(brushes, typeof(Object), true) as BrushCollection;


                #endregion

                #region Scroll view
                //scroll view
                scrollViewScrollPosition = EditorGUILayout.BeginScrollView(scrollViewScrollPosition, false, false);
                int rowLength    = 1;
                int maxRowLength = Mathf.FloorToInt((this.position.width - 35) / 100);
                if (maxRowLength < 1)
                {
                    maxRowLength = 1;
                }

                foreach (BrushObject brObj in brushes.brushes)
                {
                    //check if brushObject is null, if so skip this brush
                    if (brObj == null || brObj.brushObject == null)
                    {
                        continue;
                    }

                    //check if row is longer than max row length
                    if (rowLength > maxRowLength)
                    {
                        rowLength = 1;
                        EditorGUILayout.EndHorizontal();
                    }
                    //begin row if rowLength == 1
                    if (rowLength == 1)
                    {
                        EditorGUILayout.BeginHorizontal();
                    }

                    //change color
                    Color guiColor = GUI.backgroundColor;
                    if (brushes.selectedBrushes.Contains(brObj))
                    {
                        GUI.backgroundColor = SelectedColor;
                        if (brushes.primarySelectedBrush == brObj)
                        {
                            GUI.backgroundColor = PrimarySelectedColor;
                        }
                    }

                    //Create the brush entry in the scroll view and check if the user clicked on the created button (change the currently selected/edited brush accordingly and add it to the current brushes if possible)
                    GUIContent btnContent = new GUIContent(AssetPreview.GetAssetPreview(brObj.brushObject), brObj.brushObject.name);
                    if (GUILayout.Button(btnContent, GUILayout.Width(100), GUILayout.Height(100)))
                    {
                        //Add and remove brushes from the current brushes list
                        if (Event.current.control && !brushes.selectedBrushes.Contains(brObj))
                        {
                            brushes.selectedBrushes.Add(brObj);
                        }
                        else if (brushes.selectedBrushes.Contains(brObj))
                        {
                            brushes.selectedBrushes.Remove(brObj);
                        }

                        //select the currently edited brush and deselect all selected brushes
                        if (!Event.current.control)
                        {
                            brushes.selectedBrushes.Clear();
                            brushes.primarySelectedBrush = brObj;
                            brushes.selectedBrushes.Add(brObj);
                        }
                    }

                    GUI.backgroundColor = guiColor;
                    rowLength++;
                }

                //check if row is longer than max row length
                if (rowLength > maxRowLength)
                {
                    rowLength = 1;
                    EditorGUILayout.EndHorizontal();
                }
                //begin row if rowLength == 1
                if (rowLength == 1)
                {
                    EditorGUILayout.BeginHorizontal();
                }

                //add button
                if (GUILayout.Button("+", GUILayout.Width(100), GUILayout.Height(100)))
                {
                    AddObjectPopup.Init(brushes.brushes, this);
                }
                Color guiColorBGC = GUI.backgroundColor;

                //end horizontal and scroll view again
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndScrollView();

                #endregion

                #region Actions Group


                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = green;
                if (GUILayout.Button(new GUIContent("Add Brush", "Add a new brush to the selection.")))
                {
                    AddObjectPopup.Init(brushes.brushes, this);
                }

                EditorGUI.BeginDisabledGroup(brushes.selectedBrushes.Count == 0 || brushes.primarySelectedBrush == null);
                GUI.backgroundColor = red;
                //remove selected brushes button
                if (GUILayout.Button(new GUIContent("Remove Current Brush(es)", "Removes the currently selected brush.")))
                {
                    if (brushes.selectedBrushes != null)
                    {
                        foreach (BrushObject brush in brushes.selectedBrushes)
                        {
                            brushes.brushes.Remove(brush);
                        }
                        brushes.selectedBrushes = new List <BrushObject>();
                    }
                }
                EditorGUI.EndDisabledGroup();
                //remove all brushes button
                EditorGUI.BeginDisabledGroup(brushes.brushes.Count == 0);
                if (GUILayout.Button(new GUIContent("Clear Brushes", "Removes all brushes.")) && RemoveAllBrushes_Dialog(brushes.brushes.Count))
                {
                    brushes.RemoveAllBrushes();
                    copy = null;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
                GUI.backgroundColor = guiColorBGC;

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);
                EditorGUILayout.BeginHorizontal();
                isPlacingEnabled = EditorGUILayout.Toggle(new GUIContent("Painting ebanled", "Should painting of gameobjects via left click be enabled?"), isPlacingEnabled);
                isErasingEnabled = EditorGUILayout.Toggle(new GUIContent("Erasing ebanled", "Should erasing of gameobjects via right click be enabled?"), isErasingEnabled);
                EditorGUILayout.EndHorizontal();
                guiColorBGC = GUI.backgroundColor;

                if (brushes.selectedBrushes.Count > 0)
                {
                    brushes.spawnedObjects.RemoveAll(a => a == null);
                    EditorGUI.BeginDisabledGroup(brushes.spawnedObjects.Count == 0);

                    GUI.backgroundColor = green;
                    if (GUILayout.Button(new GUIContent("Permanently Apply Spawned GameObjects (" + brushes.spawnedObjects.Count + ")", "Permanently apply the gameobjects that have been spawned with GO brush, so they can not be erased by accident anymore.")))
                    {
                        brushes.ApplyCachedObjects();
                        lastPlacementPositions.Clear();
                    }


                    GUI.backgroundColor = red;
                    if (GUILayout.Button(new GUIContent("Remove All Spawned GameObjects (" + brushes.spawnedObjects.Count + ")", "Removes all spawned objects from the scene that have not been applied before.")) && RemoveAllCachedObjects_Dialog(brushes.spawnedObjects.Count))
                    {
                        brushes.DeleteSpawnedObjects();
                        lastPlacementPositions.Clear();
                    }
                    EditorGUI.EndDisabledGroup();
                }



                GUI.backgroundColor = guiColorBGC;

                #endregion

                #region Brush Details
                //don't show the details of the current brush if we do not have selected a current brush
                if (brushes.selectedBrushes != null && brushes.primarySelectedBrush != null && brushes.brushes.Count > 0 && brushes.selectedBrushes.Count > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal();
                    GUI.backgroundColor = yellow;
                    EditorGUILayout.LabelField("Brush Details" + " - (" + brushes.primarySelectedBrush.brushObject.name + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Copy", "Copies the brush."), GUILayout.MaxWidth(50)))
                    {
                        copy = brushes.primarySelectedBrush;
                    }
                    EditorGUI.BeginDisabledGroup(copy == null);
                    if (GUILayout.Button(new GUIContent("Paste", "Pastes the details of the brush in the clipboard."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.PasteDetails(copy);
                    }
                    GUI.backgroundColor = guiColorBGC;
                    EditorGUI.EndDisabledGroup();
                    if (GUILayout.Button(new GUIContent("Reset", "Restores the defaults settings of the brush details."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.ResetDetails();
                    }
                    EditorGUILayout.EndHorizontal();

                    brushes.primarySelectedBrush.parentContainer    = EditorGUILayout.ObjectField("Parent", brushes.primarySelectedBrush.parentContainer, typeof(Transform), true) as Transform;
                    brushes.primarySelectedBrush.density            = EditorGUILayout.Slider(new GUIContent("Density", "Changes the density of the brush, i.e. how many gameobjects are spawned inside the radius of the brush."), brushes.primarySelectedBrush.density, 0f, 5f);
                    brushes.primarySelectedBrush.brushSize          = EditorGUILayout.Slider(new GUIContent("Brush Size", "The radius of the brush."), brushes.primarySelectedBrush.brushSize, 0f, 25f);
                    brushes.primarySelectedBrush.offsetFromPivot    = EditorGUILayout.Vector3Field(new GUIContent("Offset from Pivot", "Changes the offset of the spawned gameobject from the calculated position. This allows you to correct the position of the spawned objects, if you find they are floating for example due to a not that correct pivot on the gameobject/prefab."), brushes.primarySelectedBrush.offsetFromPivot);
                    brushes.primarySelectedBrush.rotOffsetFromPivot = EditorGUILayout.Vector3Field(new GUIContent("Rotational Offset", "Changes the rotational offset that is applied to the prefab/gameobject when spawning it. This allows you to current the rotation of the spawned objects."), brushes.primarySelectedBrush.rotOffsetFromPivot);


                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Min and Max Scale", "The min and max range of the spawned gameobject. If they are not the same value a random value in between the min and max is going to be picked."));
                    EditorGUILayout.MinMaxSlider(ref brushes.primarySelectedBrush.minScale, ref brushes.primarySelectedBrush.maxScale, 0.001f, 50);
                    brushes.primarySelectedBrush.minScale = EditorGUILayout.FloatField(brushes.primarySelectedBrush.minScale);
                    brushes.primarySelectedBrush.maxScale = EditorGUILayout.FloatField(brushes.primarySelectedBrush.maxScale);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    brushes.primarySelectedBrush.randomizeXRotation = EditorGUILayout.Toggle(new GUIContent("Randomize X Rotation", "Should the rotation be randomized on the x axis?"), brushes.primarySelectedBrush.randomizeXRotation);
                    brushes.primarySelectedBrush.randomizeYRotation = EditorGUILayout.Toggle(new GUIContent("Randomize Y Rotation", "Should the rotation be randomized on the y axis?"), brushes.primarySelectedBrush.randomizeYRotation);
                    brushes.primarySelectedBrush.randomizeZRotation = EditorGUILayout.Toggle(new GUIContent("Randomize Z Rotation", "Should the rotation be randomized on the z axis?"), brushes.primarySelectedBrush.randomizeZRotation);
                    EditorGUILayout.EndHorizontal();

                    brushes.primarySelectedBrush.alignToSurface = EditorGUILayout.Toggle(new GUIContent("Align to Surface", "This option allows you to align the instantiated gameobjects to the surface you are painting on."), brushes.primarySelectedBrush.alignToSurface);

                    brushes.primarySelectedBrush.allowIntercollision = EditorGUILayout.Toggle(new GUIContent("Allow Intercollision", "Should the spawned objects be considered for the spawning of new objects? If so, newly spawned objects can be placed on top of previously (not yet applied) objects."), brushes.primarySelectedBrush.allowIntercollision);


                    EditorGUILayout.Space();
                    EditorGUILayout.Space();


                    GUI.backgroundColor = yellow;
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Filters" + " - (" + brushes.primarySelectedBrush.brushObject.name + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Copy", "Copies the brush."), GUILayout.MaxWidth(50)))
                    {
                        copy = brushes.primarySelectedBrush;
                    }
                    EditorGUI.BeginDisabledGroup(copy == null);
                    if (GUILayout.Button(new GUIContent("Paste", "Pastes the filters of the brush in the clipboard."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.PasteFilters(copy);
                    }
                    EditorGUI.EndDisabledGroup();
                    GUI.backgroundColor = guiColorBGC;
                    if (GUILayout.Button(new GUIContent("Reset", "Restores the defaults settings of the brush filters."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.ResetFilters();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Min and Max Slope", "The range of slope that is required for an object to be placed. If the slope is not in that range, no object is going to be placed."));
                    EditorGUILayout.MinMaxSlider(ref brushes.primarySelectedBrush.minSlope, ref brushes.primarySelectedBrush.maxSlope, 0, 360);
                    brushes.primarySelectedBrush.minSlope = EditorGUILayout.FloatField(brushes.primarySelectedBrush.minSlope);
                    brushes.primarySelectedBrush.maxSlope = EditorGUILayout.FloatField(brushes.primarySelectedBrush.maxSlope);
                    EditorGUILayout.EndHorizontal();

                    SerializedProperty sp = serializedObject_brushObject.FindProperty("primarySelectedBrush").FindPropertyRelative("layerFilter");

                    EditorGUILayout.BeginHorizontal();
                    brushes.primarySelectedBrush.isTagFilteringEnabled = EditorGUILayout.Toggle("Enable Tag Filtering", brushes.primarySelectedBrush.isTagFilteringEnabled);
                    if (brushes.primarySelectedBrush.isTagFilteringEnabled)
                    {
                        brushes.primarySelectedBrush.tagFilter = EditorGUILayout.TagField(new GUIContent("Tag Filter", "Limits the painting to objects that have a specific tag on them."), brushes.primarySelectedBrush.tagFilter);
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    serializedObject_brushObject.ApplyModifiedProperties();
                }

                //save AssetDatabase on any change
                if (GUI.changed && brushes != null)
                {
                    brushes.Save();
                }
                #endregion
            }
        }
Example #3
0
 /// <summary>
 /// Removes all brushes from this brush collection
 /// </summary>
 public void RemoveAllBrushes()
 {
     brushes.Clear();
     primarySelectedBrush = null;
     selectedBrushes.Clear();
 }