Experimental: this API is experimental and might be changed or removed in the future.

TerrainPaintTool<T0>

class in UnityEditor.Experimental.TerrainAPI

/

Inherits from:ScriptableSingleton_1

Switch to Manual

Description

Base class for terrain painting tools.

Derive from this class to implement your own terrain painting tools.

using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.TerrainAPI;

namespace UnityEditor.Experimental.TerrainAPI { 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 GetDesc() { return "Left click to raise.\n\nHold shift and left click to lower."; }

public override void OnSceneGUI(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)TerrainPaintUtility.BuiltinPaintMaterialPasses.RaiseLowerHeight);

TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - MyPaintHeightTool"); return false; } } }

Public Functions

GetDescRetrieves the description of the custom terrain tool.
GetNameRetrieves the name of the custom terrain tool.
OnDisableCalled when the tool is destroyed.
OnEnableCalled when the tool is created.
OnEnterToolModeCalled when the tool is activated.
OnExitToolModeCalled when the tool becomes inactive.
OnInspectorGUICustom terrain tool OnInspectorGUI callback.
OnPaintCustom terrain tool paint callback.
OnSceneGUICustom terrain tool OnSceneGUI callback.

Inherited members

Static Variables

instanceGets the instance of the Singleton. Unity creates the Singleton instance when this property is accessed for the first time. If you use the FilePathAttribute, then Unity loads the data on the first access as well.

Protected Functions

SaveSaves the current state of the ScriptableSingleton.

Static Functions

GetFilePathGet the file path where this ScriptableSingleton is saved to.