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

TerrainPaintTool<T0>

class in UnityEditor.Experimental.TerrainAPI

/

继承自:ScriptableSingleton_1

切换到手册

描述

地形绘制工具的基类。

可以从此类派生来实现您自己的地形绘制工具。

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; } } }

公共函数

GetDesc检索自定义地形工具的描述。
GetName检索自定义地形工具的名称。
OnDisable在销毁工具时调用。
OnEnable在创建工具时调用。
OnEnterToolMode在激活工具时调用。
OnExitToolMode在工具变为非活动状态时调用。
OnInspectorGUI自定义地形工具 OnInspectorGUI 回调。
OnPaint自定义地形工具绘制回调。
OnSceneGUI自定义地形工具 OnSceneGUI 回调。

继承的成员

静态变量

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.

受保护的函数

SaveSaves the current state of the ScriptableSingleton.

静态函数

GetFilePathGet the file path where this ScriptableSingleton is saved to.