Advertisement
Guest User

GrassPainterEditor.cs

a guest
Jan 29th, 2022
6,489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.88 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4.  
  5. [CustomEditor(typeof(GrassPainter))]
  6. [InitializeOnLoad]
  7. public class GrassPainterEditor : Editor
  8. {
  9.     GrassPainter grassPainter;
  10.     readonly string[] toolbarStrings = { "Add", "Remove", "Edit", "Reproject" };
  11.  
  12.     readonly string[] toolbarStringsEdit = { "Edit Colors", "Edit Length/Width", "Both" };
  13.  
  14.     private void OnEnable()
  15.     {
  16.         grassPainter = (GrassPainter)target;
  17.     }
  18.     void OnSceneGUI()
  19.     {
  20.         //base
  21.         Handles.color = Color.green;
  22.         Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  23.         Handles.color = new Color(0, 0.5f, 0, 0.4f);
  24.         Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  25.  
  26.         if (grassPainter.toolbarInt == 1)
  27.         {
  28.             Handles.color = Color.red;
  29.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  30.             Handles.color = new Color(0.5f, 0f, 0f, 0.4f);
  31.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  32.         }
  33.         if (grassPainter.toolbarInt == 2)
  34.         {
  35.             Handles.color = Color.yellow;
  36.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  37.             Handles.color = new Color(0.5f, 0.5f, 0f, 0.4f);
  38.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  39.             // falloff
  40.             Handles.color = Color.yellow;
  41.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize * grassPainter.brushFalloffSize);
  42.             Handles.color = new Color(0.5f, 0.5f, 0f, 0.4f);
  43.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize * grassPainter.brushFalloffSize);
  44.         }
  45.         if (grassPainter.toolbarInt == 3)
  46.         {
  47.             Handles.color = Color.cyan;
  48.             Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  49.             Handles.color = new Color(0, 0.5f, 0.5f, 0.4f);
  50.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  51.         }
  52.     }
  53.  
  54.     public override void OnInspectorGUI()
  55.     {
  56.         EditorGUILayout.LabelField("Grass Limit", EditorStyles.boldLabel);
  57.         EditorGUILayout.BeginHorizontal();
  58.         EditorGUILayout.LabelField(grassPainter.i.ToString() + "/", EditorStyles.label);
  59.         grassPainter.grassLimit = EditorGUILayout.IntField(grassPainter.grassLimit);
  60.         EditorGUILayout.EndHorizontal();
  61.         EditorGUILayout.Space();
  62.         EditorGUILayout.LabelField("Hit Settings", EditorStyles.boldLabel);
  63.         LayerMask tempMask = EditorGUILayout.MaskField("Hit Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.hitMask), InternalEditorUtility.layers);
  64.         grassPainter.hitMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask);
  65.         LayerMask tempMask2 = EditorGUILayout.MaskField("Painting Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.paintMask), InternalEditorUtility.layers);
  66.         grassPainter.paintMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask2);
  67.         EditorGUILayout.Space();
  68.         EditorGUILayout.LabelField("Paint Status (Right-Mouse Button to paint)", EditorStyles.boldLabel);
  69.         grassPainter.toolbarInt = GUILayout.Toolbar(grassPainter.toolbarInt, toolbarStrings);
  70.         EditorGUILayout.Space();
  71.         EditorGUILayout.LabelField("Brush Settings", EditorStyles.boldLabel);
  72.         grassPainter.brushSize = EditorGUILayout.Slider("Brush Size", grassPainter.brushSize, 0.1f, 10f);
  73.  
  74.         if (grassPainter.toolbarInt == 0)
  75.         {
  76.             grassPainter.normalLimit = EditorGUILayout.Slider("Normal Limit", grassPainter.normalLimit, 0f, 1f);
  77.             grassPainter.density = EditorGUILayout.Slider("Density", grassPainter.density, 0.1f, 10f);
  78.         }
  79.  
  80.         if (grassPainter.toolbarInt == 2)
  81.         {
  82.             grassPainter.toolbarIntEdit = GUILayout.Toolbar(grassPainter.toolbarIntEdit, toolbarStringsEdit);
  83.             EditorGUILayout.Space();
  84.             EditorGUILayout.LabelField("Flood Options", EditorStyles.boldLabel);
  85.             EditorGUILayout.BeginHorizontal();
  86.             if (GUILayout.Button("Flood Colors"))
  87.             {
  88.                 grassPainter.FloodColor();
  89.             }
  90.             if (GUILayout.Button("Flood Length/Width"))
  91.             {
  92.                 grassPainter.FloodLengthAndWidth();
  93.             }
  94.             EditorGUILayout.EndHorizontal();
  95.             EditorGUILayout.LabelField("Soft Falloff Settings", EditorStyles.boldLabel);
  96.             grassPainter.brushFalloffSize = EditorGUILayout.Slider("Brush Falloff Size", grassPainter.brushFalloffSize, 0.01f, 1f);
  97.             grassPainter.Flow = EditorGUILayout.Slider("Brush Flow", grassPainter.Flow, 0.1f, 10f);
  98.         }
  99.  
  100.         if (grassPainter.toolbarInt == 0 || grassPainter.toolbarInt == 2)
  101.         {
  102.             EditorGUILayout.Space();
  103.             EditorGUILayout.LabelField("Width and Length ", EditorStyles.boldLabel);
  104.             grassPainter.sizeWidth = EditorGUILayout.Slider("Grass Width", grassPainter.sizeWidth, 0f, 2f);
  105.             grassPainter.sizeLength = EditorGUILayout.Slider("Grass Length", grassPainter.sizeLength, 0f, 2f);
  106.             EditorGUILayout.Space();
  107.             EditorGUILayout.LabelField("Color", EditorStyles.boldLabel);
  108.             grassPainter.AdjustedColor = EditorGUILayout.ColorField("Brush Color", grassPainter.AdjustedColor);
  109.             EditorGUILayout.LabelField("Random Color Variation", EditorStyles.boldLabel);
  110.             grassPainter.rangeR = EditorGUILayout.Slider("Red", grassPainter.rangeR, 0f, 1f);
  111.             grassPainter.rangeG = EditorGUILayout.Slider("Green", grassPainter.rangeG, 0f, 1f);
  112.             grassPainter.rangeB = EditorGUILayout.Slider("Blue", grassPainter.rangeB, 0f, 1f);
  113.         }
  114.  
  115.         if (grassPainter.toolbarInt == 3)
  116.         {
  117.             EditorGUILayout.Space();
  118.             EditorGUILayout.BeginHorizontal();
  119.             EditorGUILayout.LabelField("Reprojection Y Offset", EditorStyles.boldLabel);
  120.  
  121.             grassPainter.reprojectOffset = EditorGUILayout.FloatField(grassPainter.reprojectOffset);
  122.             EditorGUILayout.EndHorizontal();
  123.         }
  124.         EditorGUILayout.Space();
  125.         EditorGUILayout.Space();
  126.         EditorGUILayout.Space();
  127.         if (GUILayout.Button("Clear Mesh"))
  128.         {
  129.             if (EditorUtility.DisplayDialog("Clear Painted Mesh?",
  130.                "Are you sure you want to clear the mesh?", "Clear", "Don't Clear"))
  131.             {
  132.                 grassPainter.ClearMesh();
  133.             }
  134.         }
  135.  
  136.  
  137.  
  138.  
  139.     }
  140.  
  141. }
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement