Advertisement
Guest User

GrassPainterEditor.cs

a guest
Jan 27th, 2021
13,909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.22 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4.  
  5. [CustomEditor(typeof(GeometryGrassPainter))]
  6. public class GrassPainterEditor : Editor
  7. {
  8.     GeometryGrassPainter grassPainter;
  9.     readonly string[] toolbarStrings = { "Add", "Remove", "Edit" };
  10.  
  11.     private void OnEnable()
  12.     {
  13.         grassPainter = (GeometryGrassPainter)target;
  14.     }
  15.  
  16.     void OnSceneGUI()
  17.     {
  18.         Handles.color = Color.cyan;
  19.         Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  20.         Handles.color = new Color(0, 0.5f, 0.5f, 0.4f);
  21.         Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  22.         if (grassPainter.toolbarInt == 1)
  23.         {
  24.             Handles.color = Color.red;
  25.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  26.             Handles.color = new Color(0.5f, 0f, 0f, 0.4f);
  27.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  28.         }
  29.         if (grassPainter.toolbarInt == 2)
  30.         {
  31.             Handles.color = Color.yellow;
  32.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  33.             Handles.color = new Color(0.5f, 0.5f, 0f, 0.4f);
  34.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  35.         }
  36.     }
  37.  
  38.     public override void OnInspectorGUI()
  39.     {
  40.         EditorGUILayout.LabelField("Grass Limit", EditorStyles.boldLabel);
  41.         EditorGUILayout.BeginHorizontal();
  42.         EditorGUILayout.LabelField(grassPainter.i.ToString() + "/", EditorStyles.label);
  43.         grassPainter.grassLimit = EditorGUILayout.IntField(grassPainter.grassLimit);
  44.         EditorGUILayout.EndHorizontal();
  45.         EditorGUILayout.Space();
  46.         EditorGUILayout.LabelField("Paint Status (Right-Mouse Button to paint)", EditorStyles.boldLabel);
  47.         grassPainter.toolbarInt = GUILayout.Toolbar(grassPainter.toolbarInt, toolbarStrings);
  48.         EditorGUILayout.Space();
  49.         EditorGUILayout.LabelField("Brush Settings", EditorStyles.boldLabel);
  50.         LayerMask tempMask = EditorGUILayout.MaskField("Hit Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.hitMask), InternalEditorUtility.layers);
  51.         grassPainter.hitMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask);
  52.         LayerMask tempMask2 = EditorGUILayout.MaskField("Painting Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.paintMask), InternalEditorUtility.layers);
  53.         grassPainter.paintMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask2);
  54.  
  55.         grassPainter.brushSize = EditorGUILayout.Slider("Brush Size", grassPainter.brushSize, 0.1f, 10f);
  56.         grassPainter.density = EditorGUILayout.Slider("Density", grassPainter.density, 0.1f, 10f);
  57.         grassPainter.normalLimit = EditorGUILayout.Slider("Normal Limit", grassPainter.normalLimit, 0f, 1f);
  58.  
  59.  
  60.         EditorGUILayout.Space();
  61.         EditorGUILayout.LabelField("Width and Length ", EditorStyles.boldLabel);
  62.         grassPainter.sizeWidth = EditorGUILayout.Slider("Grass Width", grassPainter.sizeWidth, 0f, 2f);
  63.         grassPainter.sizeLength = EditorGUILayout.Slider("Grass Length", grassPainter.sizeLength, 0f, 2f);
  64.         EditorGUILayout.Space();
  65.         EditorGUILayout.LabelField("Color", EditorStyles.boldLabel);
  66.         grassPainter.AdjustedColor = EditorGUILayout.ColorField("Brush Color", grassPainter.AdjustedColor);
  67.         EditorGUILayout.LabelField("Random Color Variation", EditorStyles.boldLabel);
  68.         grassPainter.rangeR = EditorGUILayout.Slider("Red", grassPainter.rangeR, 0f, 1f);
  69.         grassPainter.rangeG = EditorGUILayout.Slider("Green", grassPainter.rangeG, 0f, 1f);
  70.         grassPainter.rangeB = EditorGUILayout.Slider("Blue", grassPainter.rangeB, 0f, 1f);
  71.  
  72.         if (GUILayout.Button("Clear Mesh"))
  73.         {
  74.             if (EditorUtility.DisplayDialog("Clear Painted Mesh?",
  75.                "Are you sure you want to clear the mesh?", "Clear", "Don't Clear"))
  76.             {
  77.                 grassPainter.ClearMesh();
  78.             }
  79.         }
  80.     }
  81.  
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement