TerrainPaintTool<T>
Base class for terrain painting tools.
Read time 5 minutesLast updated 11 days ago
Definition
- Type: Class
- Namespace: UnityEditor.TerrainTools
- Assembly: UnityEditor
- Inherits from: ScriptableSingleton<T>
public abstract class TerrainPaintTool<T> : ScriptableSingleton<T> where T : TerrainPaintTool<T>
Remarks
Derive from this class to implement your own terrain painting tools.
Examples
using UnityEngine;using UnityEditor;using UnityEngine.TerrainTools;namespace UnityEditor.TerrainTools{ public class MyPaintHeightTool : TerrainPaintTool<MyPaintHeightTool> { Material m_Material = null; Material GetPaintMaterial() { if (m_Material == null) m_Material = new Material(Shader.Find("Hidden/Terrain/PaintHeight")); return m_Material; } public override string GetName() { return "My Paint Height Tool"; } public override string GetDescription() { return "Left click to raise.\n\nHold shift and left click to lower."; } public override void OnRenderBrushPreview(Terrain terrain, IOnSceneGUI editContext) { TerrainPaintUtilityEditor.ShowDefaultPreviewBrush(terrain, editContext.brushTexture, editContext.brushSize); } public override bool OnPaint(Terrain terrain, IOnPaint editContext) { Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial(); float rotationDegrees = 0.0f; BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, rotationDegrees); PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds()); // apply brush Vector4 brushParams = new Vector4(editContext.brushStrength * 0.01f, 0.0f, 0.0f, 0.0f); mat.SetTexture("_BrushTex", editContext.brushTexture); mat.SetVector("_BrushParams", brushParams); TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat); Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainBuiltinPaintMaterialPasses.RaiseLowerHeight); TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - MyPaintHeightTool"); return false; } }}
Methods
Method | Description |
|---|---|
| GetDescription | Retrieves the description of the custom terrain tool. |
| GetName | Retrieves the name of the custom terrain tool. |
| OnDisable | Called when the tool is destroyed. |
| OnEnable | Called when the tool is created. |
| OnEnterToolMode | Called when the tool is activated. |
| OnExitToolMode | Called when the tool becomes inactive. |
| OnInspectorGUI | Custom terrain tool OnInspectorGUI callback. |
| OnPaint | Custom terrain tool paint callback. |
| OnRenderBrushPreview | Use this method to implement custom tool preview and UI behavior that will only render while the mouse is within the SceneView bounds or while you're actively using this tool. |
| OnSceneGUI | Custom terrain tool OnSceneGUI callback. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |