地形绘制工具的基类。
可以从此类派生来实现您自己的地形绘制工具。
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 | 自定义地形工具绘制回调。 |
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 | 自定义地形工具 OnSceneGUI 回调。 |
instance | Gets 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. |
GetInstanceID | Gets the instance ID of the object. |
ToString | 返回对象的名称。 |
Save | Saves the current state of the ScriptableSingleton. |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
FindObjectsOfType | Gets a list of all loaded objects of Type type. |
Instantiate | 克隆 original 对象并返回克隆对象。 |
CreateInstance | 创建脚本化对象的实例。 |
GetFilePath | Get the file path where this ScriptableSingleton is saved to. |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Awake | 当 ScriptableObject 脚本启动时调用此函数。 |
OnDestroy | 当脚本化对象将销毁时调用此函数。 |
OnValidate | Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector. |
Reset | 重置为默认值。 |