class in UnityEditor.Experimental.TerrainAPI
/
Inherits from:ScriptableObject
Switch to ManualBase 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; } } }
GetDesc | 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. |
OnInspectorGUI | Custom terrain tool OnInspectorGUI callback. |
OnPaint | Custom terrain tool paint callback. |
OnSceneGUI | Custom terrain tool OnSceneGUI callback. |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | 对象的名称。 |
GetInstanceID | 返回对象的实例 ID。 |
ToString | 返回 GameObject 的名称。 |
Destroy | 删除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsOfType | 返回所有类型为 type 的已加载的激活对象的列表。 |
Instantiate | 克隆 original 对象并返回克隆对象。 |
CreateInstance | 创建脚本化对象的实例。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |