Version: 2023.1

TerrainPaintTool<T0>

class in UnityEditor.TerrainTools

/

继承自:ScriptableSingleton_1

切换到手册

描述

地形绘制工具的基类。

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

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

公共函数

GetDescription检索自定义地形工具的描述。
GetName检索自定义地形工具的名称。
OnDisable在销毁工具时调用。
OnEnable在创建工具时调用。
OnEnterToolMode在激活工具时调用。
OnExitToolMode在工具变为非活动状态时调用。
OnInspectorGUI自定义地形工具 OnInspectorGUI 回调。
OnPaint自定义地形工具绘制回调。
OnRenderBrushPreviewUse 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自定义地形工具 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.

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

受保护的函数

SaveSaves the current state of the ScriptableSingleton.

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。
CreateInstance创建脚本化对象的实例。
GetFilePathGet the file path where this ScriptableSingleton is saved to.

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。

消息

Awake当 ScriptableObject 脚本启动时调用此函数。
OnDestroy当脚本化对象将销毁时调用此函数。
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
Reset重置为默认值。