Guest User

EditorGrassPainter.cs

a guest
Jul 16th, 2021
4,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.57 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4.  
  5. [CustomEditor(typeof(GrassPainter))]
  6. [InitializeOnLoad]
  7. public class EditorGrassPainter : Editor
  8. {
  9.     GrassPainter grassPainter;
  10.     readonly string[] toolbarStrings = { "Add", "Remove", "Edit" };
  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.cyan;
  22.         Handles.DrawWireDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, grassPainter.brushSize);
  23.         Handles.color = new Color(0, 0.5f, 0.5f, 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.brushFalloffSize);
  42.             Handles.color = new Color(0.5f, 0.5f, 0f, 0.4f);
  43.             Handles.DrawSolidDisc(grassPainter.hitPosGizmo, grassPainter.hitNormal, Mathf.Clamp(grassPainter.brushFalloffSize, 0, grassPainter.brushSize));
  44.         }
  45.     }
  46.  
  47.     public override void OnInspectorGUI()
  48.     {
  49.         EditorGUILayout.LabelField("Grass Limit", EditorStyles.boldLabel);
  50.  
  51.         EditorGUILayout.BeginHorizontal();
  52.         EditorGUILayout.LabelField(grassPainter.i.ToString() + "/", EditorStyles.label);
  53.         grassPainter.grassLimit = EditorGUILayout.IntField(grassPainter.grassLimit);
  54.         EditorGUILayout.EndHorizontal();
  55.         EditorGUILayout.Space();
  56.         EditorGUILayout.LabelField("Hit Settings", EditorStyles.boldLabel);
  57.         LayerMask tempMask = EditorGUILayout.MaskField("Hit Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.hitMask), InternalEditorUtility.layers);
  58.         grassPainter.hitMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask);
  59.         LayerMask tempMask2 = EditorGUILayout.MaskField("Painting Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(grassPainter.paintMask), InternalEditorUtility.layers);
  60.         grassPainter.paintMask = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask2);
  61.         EditorGUILayout.Space();
  62.         EditorGUILayout.LabelField("Paint Status (Right-Mouse Button to paint)", EditorStyles.boldLabel);
  63.         grassPainter.toolbarInt = GUILayout.Toolbar(grassPainter.toolbarInt, toolbarStrings);
  64.         EditorGUILayout.Space();
  65.         EditorGUILayout.LabelField("Brush Settings", EditorStyles.boldLabel);
  66.  
  67.         grassPainter.brushSize = EditorGUILayout.Slider("Brush Size", grassPainter.brushSize, 0.1f, 10f);
  68.  
  69.         if (grassPainter.toolbarInt == 0)
  70.         {
  71.             grassPainter.normalLimit = EditorGUILayout.Slider("Normal Limit", grassPainter.normalLimit, 0f, 1f);
  72.             grassPainter.density = EditorGUILayout.Slider("Density", grassPainter.density, 0.1f, 10f);
  73.  
  74.         }
  75.         if (grassPainter.toolbarInt == 2)
  76.         {
  77.             grassPainter.toolbarIntEdit = GUILayout.Toolbar(grassPainter.toolbarIntEdit, toolbarStringsEdit);
  78.             EditorGUILayout.Space();
  79.             EditorGUILayout.LabelField("Soft Falloff Settings", EditorStyles.boldLabel);
  80.             grassPainter.brushFalloffSize = EditorGUILayout.Slider("Brush Falloff Size", grassPainter.brushFalloffSize, 0.1f, 10f);
  81.             grassPainter.Flow = EditorGUILayout.Slider("Brush Flow", grassPainter.Flow, 1, 20f);
  82.  
  83.         }
  84.  
  85.  
  86.         if (grassPainter.toolbarInt == 0 || grassPainter.toolbarInt == 2)
  87.         {
  88.  
  89.  
  90.             EditorGUILayout.Space();
  91.             EditorGUILayout.LabelField("Width and Length ", EditorStyles.boldLabel);
  92.             grassPainter.sizeWidth = EditorGUILayout.Slider("Grass Width", grassPainter.sizeWidth, 0f, 2f);
  93.             grassPainter.sizeLength = EditorGUILayout.Slider("Grass Length", grassPainter.sizeLength, 0f, 2f);
  94.             EditorGUILayout.Space();
  95.             EditorGUILayout.LabelField("Color", EditorStyles.boldLabel);
  96.             grassPainter.AdjustedColor = EditorGUILayout.ColorField("Brush Color", grassPainter.AdjustedColor);
  97.             EditorGUILayout.LabelField("Random Color Variation", EditorStyles.boldLabel);
  98.             grassPainter.rangeR = EditorGUILayout.Slider("Red", grassPainter.rangeR, 0f, 1f);
  99.             grassPainter.rangeG = EditorGUILayout.Slider("Green", grassPainter.rangeG, 0f, 1f);
  100.             grassPainter.rangeB = EditorGUILayout.Slider("Blue", grassPainter.rangeB, 0f, 1f);
  101.         }
  102.  
  103.         if (GUILayout.Button("Clear Mesh"))
  104.         {
  105.             if (EditorUtility.DisplayDialog("Clear Painted Mesh?",
  106.                "Are you sure you want to clear the mesh?", "Clear", "Don't Clear"))
  107.             {
  108.                 grassPainter.ClearMesh();
  109.             }
  110.         }
  111.     }
  112.  
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment