Making some Types and Properties public to allow building of custom tools with it#629
Making some Types and Properties public to allow building of custom tools with it#629CortiWins wants to merge 5 commits into
Conversation
All other statics about the current selection are also public.
Useful to set it via ToolManager.SetActiveTool
Useful to set via ToolManager.SetActiveContext
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr-agent |
PR Code Suggestions ✨No code suggestions found for the PR. |
Class: TextureMoveTool Method: DoToolUI Snapping is done by using EditorSnapping.MoveSnap on the moved position. There are three handles - Slider2D - Slider1D Up ( Green arrow) - Slider1D Right (RedArrow) The Slider2D has an explicit individual snap value of 0.0f. The Slider1Ds use a method override that internally applies -1.0f as a snap factor. The position done via Slider1D is snapped to 1.0 increments before getting to the MoveSnap line where the acutual snap settings are applied.
| { | ||
| [EditorTool("Cut Tool", typeof(ProBuilderMesh), typeof(PositionToolContext))] | ||
| class CutTool : EditorTool | ||
| public class CutTool : EditorTool |
There was a problem hiding this comment.
We should make that sealed, so that it's possible to reference it but that should be all.
| public class CutTool : EditorTool | |
| public sealed class CutTool : EditorTool |
There was a problem hiding this comment.
I'm a fan of sealing things that are not made to be extended. So thumbs up for that.
| [Icon("Packages/com.unity.probuilder/Content/Icons/EditableMesh/EditMeshContext.png")] | ||
| [EditorToolContext("ProBuilder", typeof(ProBuilderMesh))] | ||
| class PositionToolContext : EditorToolContext | ||
| public class PositionToolContext : EditorToolContext |
There was a problem hiding this comment.
We should make that sealed, so that it's possible to reference it but that should be all.
| public class PositionToolContext : EditorToolContext | |
| public sealed class PositionToolContext : EditorToolContext |
| } | ||
|
|
||
| class TextureToolContext : EditorToolContext | ||
| public class TextureToolContext : EditorToolContext |
There was a problem hiding this comment.
We should make that sealed, so that it's possible to reference it but that should be all.
| public class TextureToolContext : EditorToolContext | |
| public sealed class TextureToolContext : EditorToolContext |
| // Disable Snap for the individual handles. Snap is applied if movement is detected. | ||
| const float SnapFactor = 0.0f; | ||
|
|
||
| m_Position = Handles.Slider2D(m_Position, | ||
| Vector3.forward, | ||
| Vector3.right, | ||
| Vector3.up, | ||
| HandleUtility.GetHandleSize(m_Position) * .2f, | ||
| Handles.RectangleHandleCap, | ||
| 0f, | ||
| SnapFactor, | ||
| false); | ||
|
|
||
| Handles.color = Color.green; | ||
|
|
||
| m_Position = Handles.Slider(m_Position, Vector3.up); | ||
| m_Position = Handles.Slider(m_Position, Vector3.up, HandleUtility.GetHandleSize(m_Position), Handles.ArrowHandleCap, SnapFactor); | ||
|
|
||
| Handles.color = Color.red; | ||
|
|
||
| m_Position = Handles.Slider(m_Position, Vector3.right); | ||
| m_Position = Handles.Slider(m_Position, Vector3.right, HandleUtility.GetHandleSize(m_Position), Handles.ArrowHandleCap, SnapFactor); |
There was a problem hiding this comment.
These can be removed as I'm landing a fix on another PR :D
|
Hey @CortiWins, |
|
@lopezt-unity I am not that surprised by the answer. The whole concept of tools and contexts is a bit...semi public right now. I helped on an addon called "ProBuilderPlus" by ex-Unity ProBuilder creator GabrielW and that required a bit of reflection to use the ToolManager.Tool and ToolManager.Context functions. Maybe a compromise is a property that returns the type like Because the use of knowing the exact Types is not changing something about their instances, but using them for setting and comparing ToolManager.Tool and ToolManager.Context throught ToolManager.SetActiveTool(Type)/ToolManager.SetActiveContextType). |
Sorry, I should express a little better :) |
Purpose of this PR
The changes make three types public
This allows to build shortcuts that probuilder into the respective tools and edit mode.
The changes one property public
it is calculated and updated in the same way all other public statistics are, so making it public allows to build UI that shows statistics.