BaseHeightAdjustEditor - jimdroberts/FishMMO GitHub Wiki
BaseHeightAdjustEditor is an abstract Unity editor class for FishMMO that enables height adjustment of selected GameObjects in the scene view using mouse events and raycasting. It provides a foundation for custom editor tools that require interactive object placement or alignment in the Unity Editor.
-
private GameObject clickedObject
The GameObject that was clicked and is being adjusted.
-
protected void OnSceneGUI()
Called by Unity to draw the scene GUI. Handles mouse events for height adjustment.
-
protected void HandleMouseEvents()
Handles mouse down and up events to trigger height adjustment logic.
-
protected virtual void HandleMouseDown(GameObject clickedObject)
Called when the left mouse button is pressed on a GameObject. Can be overridden for custom logic. Parameters: - GameObject clickedObject: The GameObject that was clicked. Returns: void. No exceptions are thrown.
-
protected virtual void HandleMouseUp(GameObject clickedObject)
Called when the left mouse button is released on a GameObject. Performs a sphere cast to adjust the object's height to the hit point. Parameters: - GameObject clickedObject: The GameObject that was released. Returns: void. No exceptions are thrown.
- Create a new class that derives from BaseHeightAdjustEditor.
- Implement or override HandleMouseDown and HandleMouseUp for custom height adjustment logic.
- Attach the custom editor to the desired GameObject type using Unity's [CustomEditor] attribute.
// Example 1: Creating a custom height adjust editor
[CustomEditor(typeof(MyGameObjectType))]
public class MyHeightAdjustEditor : BaseHeightAdjustEditor
{
protected override void HandleMouseDown(GameObject clickedObject)
{
// Custom logic for mouse down event
}
protected override void HandleMouseUp(GameObject clickedObject)
{
// Custom logic for mouse up event
base.HandleMouseUp(clickedObject); // Optionally call base logic
}
}
- Use this base class to build interactive editor tools for object placement and alignment.
- Override HandleMouseDown and HandleMouseUp for specialized behaviors.
- Document custom editor tools for maintainability and team usage.