### Usage example: setup TransformGizmoCustomGizmo in code Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to add the component and assign custom handle meshes programmatically. Requires pre-built handle meshes each with a Collider child. Set gizmoLayer to a dedicated layer so selection raycasts hit them. ```csharp // Create an empty GameObject with a Camera for the gizmo, // then attach custom handle meshes in the inspector. Equivalent setup in code: TransformGizmo gizmo = gameObject.AddComponent(); TransformGizmoCustomGizmo customGizmo = gameObject.AddComponent(); customGizmo.transformGizmo = gizmo; customGizmo.autoFindTransformGizmo = false; customGizmo.gizmoLayer = 8; // a dedicated "Gizmo" layer // Assign pre-built handle meshes (each needs a Collider child): customGizmo.customTranslationGizmos.xAxisGizmo = xArrowMesh.transform; customGizmo.customTranslationGizmos.yAxisGizmo = yArrowMesh.transform; customGizmo.customTranslationGizmos.zAxisGizmo = zArrowMesh.transform; customGizmo.customTranslationGizmos.anyAxisGizmo = centerCubeMesh.transform; ``` -------------------------------- ### Usage example for CustomTransformGizmos Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to assign handle transforms, initialize on a layer, enable, position, orient, scale, and detect the clicked axis. ```csharp CustomTransformGizmos scaleHandles = new CustomTransformGizmos(); scaleHandles.xAxisGizmo = xHandle.transform; scaleHandles.yAxisGizmo = yHandle.transform; scaleHandles.zAxisGizmo = zHandle.transform; scaleHandles.anyAxisGizmo = centerHandle.transform; scaleHandles.Init(8); // put all handles on layer 8 scaleHandles.SetEnable(true); scaleHandles.SetPosition(Vector3.zero); scaleHandles.SetAxis(new AxisInfo() { pivot = Vector3.zero, xDirection = Vector3.right, yDirection = Vector3.up, zDirection = Vector3.forward }); scaleHandles.ScaleMultiply(new Vector4(0, 0, 0, 1f)); // uniform size only Axis hit = scaleHandles.GetSelectedAxis(myHitCollider); if (hit != Axis.None) Debug.Log("Clicked axis: " + hit); ``` -------------------------------- ### GetCenter usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Example usage of the GetCenter extension method with CenterType.All and CenterType.Solo. Requires the RuntimeGizmos namespace. ```csharp using RuntimeGizmos; Vector3 allCenter = someObject.GetCenter(CenterType.All); Vector3 soloCenter = someObject.GetCenter(CenterType.Solo); ``` -------------------------------- ### Programmatic selection and removal example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to add targets, remove one with undo support, and clear without recording an undo command. ```csharp TransformGizmo gizmo = GetComponent(); // Programmatic selection gizmo.AddTarget(cube1.transform); gizmo.AddTarget(cube3.transform); // Undoable removal gizmo.RemoveTarget(cube1.transform); // Clear without recording an undo command gizmo.ClearTargets(false); ``` -------------------------------- ### SetScaleFrom usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Example usage of the SetScaleFrom extension method. Requires the RuntimeGizmos namespace and a Transform object. The worldPivot is the fixed point to scale from. ```csharp using RuntimeGizmos; Transform obj = someGameObject.transform; Vector3 worldPivot = gizmo.pivotPoint; // fixed point to scale from obj.SetScaleFrom(worldPivot, new Vector3(2, 2, 2)); ``` -------------------------------- ### UndoRedo usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to create an UndoRedo instance with a capacity of 50, execute a custom ICommand, and perform undo, redo, and clear operations. Requires a custom ICommand implementation like MyMoveCommand. ```csharp using CommandUndoRedo; UndoRedo history = new UndoRedo(50); MyMoveCommand move = new MyMoveCommand(target); // custom ICommand history.Execute(move); // performs the action and records it history.Undo(); // reverts history.Redo(); // re-applies history.Clear(); // resets both stacks ``` -------------------------------- ### DropoutStack usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Demonstrates pushing items with a capacity of 3. When 'd' is pushed, 'a' is dropped, leaving d, c, b. Pop returns 'd'. ```csharp DropoutStack recent = new DropoutStack(3); recent.Push("a"); recent.Push("b"); recent.Push("c"); recent.Push("d"); // "a" is dropped, stack now d, c, b string top = recent.Pop(); // "d" ``` -------------------------------- ### CommandGroup usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows adding commands to a group and inserting it into UndoRedoManager. One Undo call reverts the whole batch. ```csharp CommandGroup group = new CommandGroup(); foreach (var cmd in myCommands) group.Add(cmd); UndoRedoManager.Insert(group); // one Undo call reverts the whole batch ``` -------------------------------- ### ClosestPointsOnSegmentToLine usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Example of using ClosestPointsOnSegmentToLine to compute distance from a ray to a segment. ```csharp IntersectPoints pts = Geometry.ClosestPointsOnSegmentToLine( segStart, segEnd, ray.origin, ray.direction); float distance = Vector3.Distance(pts.first, pts.second); ``` -------------------------------- ### UndoRedoManager usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows programmatic calls to Undo, Redo, Insert, and Clear. Default hotkeys are ActionKey (LeftShift) + UndoAction (Z) / RedoAction (Y). Insert records a command without executing it; the command must already carry its own old/new state. ```csharp using CommandUndoRedo; // Default hotkeys: ActionKey (LeftShift) + UndoAction (Z) / RedoAction (Y) // Equivalent programmatic calls: UndoRedoManager.Undo(); UndoRedoManager.Redo(); // Record a command without executing it (the command must already // carry its own old/new state, e.g. a TransformCommand built by the gizmo): UndoRedoManager.Insert(myTransformCommand); // Reset history when the scene's selection state changes out-of-band UndoRedoManager.Clear(); ``` -------------------------------- ### GetHandleLength example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to get the world-space handle length for a transform type, optionally for a specific axis and with or without distance compensation. ```csharp TransformGizmo gizmo = GetComponent(); // Handle length in world units at the current camera distance float len = gizmo.GetHandleLength(TransformType.Move); // Scale handle for the X axis, without distance compensation float xScaleLen = gizmo.GetHandleLength(TransformType.Scale, Axis.X, false); ``` -------------------------------- ### LinePlaneIntersect usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Example of using LinePlaneIntersect with a camera ray to detect if the mouse is on the drag plane. ```csharp using RuntimeGizmos; Ray ray = camera.ScreenPointToRay(Input.mousePosition); Vector3 hit = Geometry.LinePlaneIntersect(ray.origin, ray.direction, pivotPoint, planeNormal); if (hit != Vector3.zero) { /* mouse is on the drag plane */ } ``` -------------------------------- ### TransformCommand usage example in TransformGizmo.TransformSelected Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows the intended drag flow: create one TransformCommand per selected target before the drag, store final values after mouse-up, and commit as a single undoable group via CommandGroup and UndoRedoManager.Insert. ```csharp using CommandUndoRedo; using RuntimeGizmos; // One TransformCommand per selected target, captured before the drag List commands = new List(); foreach (Transform target in selectedTargets) { commands.Add(new TransformCommand(gizmo, target)); } // ... drag applies live transform changes ... // After mouse-up: store final values and commit as a single undoable group foreach (ICommand c in commands) ((TransformCommand)c).StoreNewTransformValues(); CommandGroup group = new CommandGroup(); group.Set(commands); UndoRedoManager.Insert(group); // one Ctrl/Shift+Z reverts the whole drag ``` -------------------------------- ### TransformTypeContains usage example Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Shows how to use TransformTypeContains to check if All contains Move or Scale in different spaces. Scale is only contained when space is Local. ```csharp using RuntimeGizmos; bool includesMove = TransformType.All.TransformTypeContains(TransformType.Move, TransformSpace.Global); // true bool includesScale = TransformType.All.TransformTypeContains(TransformType.Scale, TransformSpace.Global); // false bool includesScaleLocal = TransformType.All.TransformTypeContains(TransformType.Scale, TransformSpace.Local); // true ``` -------------------------------- ### ExtTransform.GetCenter extension method Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns the world-space center of the transform based on CenterType. For CenterType.Solo, returns renderer.bounds.center of the object's own first Renderer, or transform.position if none. For CenterType.All, bounds-encapsulates the object's and all descendants' renderer bounds (or positions when no renderer) starting from transform.position. Used by TransformGizmo.SetPivotPoint for center pivoting. Source: Assets/RuntimeGizmo/Helpers/ExtTransform.cs:50. ```csharp public static Vector3 GetCenter(this Transform transform, CenterType centerType) ``` -------------------------------- ### UndoRedoManager.maxUndoStored Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Gets or sets the maximum number of undo steps stored. This property forwards to the internal UndoRedo instance. ```APIDOC ## [PROPERTY] maxUndoStored ### Description Gets or sets the maximum number of undo steps stored. This property forwards to the internal UndoRedo instance. ### Property Signature `public static int maxUndoStored { get; set; }` ### Remarks `TransformGizmo.HandleUndoRedo()` syncs its own `maxUndoStored` field to this every frame. ``` -------------------------------- ### ClampToSegment method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Clamps a point already on the line to the segment. Returns linePoint1 if before start, linePoint2 if past end, decided via ExtVector3.IsInDirection. ```csharp public static Vector3 ClampToSegment(Vector3 point, Vector3 linePoint1, Vector3 linePoint2) ``` -------------------------------- ### Geometry.ClampToSegment Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Clamps a point that lies on a line to the segment defined by two endpoints. Returns the start point if the point is before the segment, the end point if past it, otherwise the original point. ```APIDOC ## Geometry.ClampToSegment ### Description Clamps a point that lies on a line to the segment defined by two endpoints. Returns the start point if the point is before the segment, the end point if past it, otherwise the original point. ### Method `public static Vector3 ClampToSegment(Vector3 point, Vector3 linePoint1, Vector3 linePoint2)` ### Parameters - `point` (Vector3) - Required - Point on the line. - `linePoint1` (Vector3) - Required - Start point of the segment. - `linePoint2` (Vector3) - Required - End point of the segment. ### Returns `Vector3` - The point clamped to the segment: `linePoint1` if the point lies before the segment start, `linePoint2` if it lies past the end, otherwise the original point. ``` -------------------------------- ### Init method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Initializes the gizmo handles: assigns the layer recursively, caches colliders, and stores original local scales. Requires each assigned mesh to have a child Collider. ```csharp public void Init(int layer) ``` -------------------------------- ### Init Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Initializes the gizmo handles by assigning a layer recursively, caching colliders, and storing original local scales. ```APIDOC ## Init ### Description Initializes the gizmo handles by assigning a layer recursively, caching colliders, and storing original local scales. ### Method Init ### Parameters #### Parameters - **layer** (int) - Required - Layer applied recursively to every assigned gizmo GameObject. ### Response Returns `void`. ``` -------------------------------- ### DropoutStack constructors Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Provides two constructors: default (unlimited, int.MaxValue) and with a maxLength capacity. The maxLength constructor sets the capacity. ```csharp public DropoutStack() {} public DropoutStack(int maxLength) ``` -------------------------------- ### CommandGroup constructors Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Provides two constructors: default (empty group) and with an initial command list (copied via AddRange). ```csharp public CommandGroup() {} public CommandGroup(List commands) ``` -------------------------------- ### UndoRedo constructors Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Provides default and parameterized constructors. The parameterless constructor uses default capacity (DropoutStack max length is int.MaxValue). The parameterized constructor sets the maximum number of undoable commands retained. ```csharp public UndoRedo() {} ``` ```csharp public UndoRedo(int maxUndoStored) ``` -------------------------------- ### UndoRedoManager.Execute Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Executes and records a command. ```APIDOC ## [METHOD] Execute ### Description Executes and records a command. ### Method Signature `public static void Execute(ICommand command)` ### Parameters - **command** (ICommand) - Required - The command to execute and record. ``` -------------------------------- ### ScaleMultiply method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Scales each handle relative to its cached original scale using per-axis grow amounts and a uniform multiplier. ```csharp public void ScaleMultiply(Vector4 scaleMultiplier) ``` -------------------------------- ### SelectCommand abstract base class Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Base class for all selection commands. Stores the owning TransformGizmo and the affected Transform. Not directly instantiable. ```csharp public abstract class SelectCommand : ICommand { protected Transform target; protected TransformGizmo transformGizmo; public SelectCommand(TransformGizmo transformGizmo, Transform target); public abstract void Execute(); public abstract void UnExecute(); } ``` -------------------------------- ### SetAxis method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Orients all four handles using Quaternion.LookRotation with the provided axis directions. ```csharp public void SetAxis(AxisInfo axisInfo) ``` -------------------------------- ### SetEnable method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Activates or deactivates all four handle GameObjects, only when their current active state differs. ```csharp public void SetEnable(bool enable) ``` -------------------------------- ### ExtTransform.SetScaleFromOffset Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Scales a Transform from a pivot offset, mimicking Unity editor Center-mode scaling. Has known limitations with non-uniform parent scales. ```APIDOC ## ExtTransform.SetScaleFromOffset ### Description Scales the target Transform to `newScale` while keeping `worldPivot` fixed, using rotation-based offset calculation. ### Method Extension method on `Transform` ### Parameters - `target` (Transform) - Required (extension receiver) - Object to scale. - `worldPivot` (Vector3) - Required - World-space pivot point. - `newScale` (Vector3) - Required - Target local scale. ### Returns - `void` ### Known Limitations - Can be slightly off under a parent with non-uniform scale and rotation (`lossyScale` inaccuracy). - "Will mess up or give undesired results if the target.localScale or target.lossyScale has any set to 0." ``` -------------------------------- ### ExtTransform.SetScaleFromOffset extension method Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Like SetScaleFrom but repositions using target.rotation * Vector3.Scale(... , target.lossyScale), mimicking Unity editor Center-mode scaling from a pivot offset. Corresponds to ScaleType.FromPointOffset. Known limitations: can be slightly off under a parent with non-uniform scale and rotation; will mess up or give undesired results if target.localScale or target.lossyScale has any set to 0. Source: Assets/RuntimeGizmo/Helpers/ExtTransform.cs:27. ```csharp public static void SetScaleFromOffset(this Transform target, Vector3 worldPivot, Vector3 newScale) ``` -------------------------------- ### AddTargetCommand class Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Concrete selection command that adds a target to the gizmo's selection. Execute calls transformGizmo.AddTarget(target, false); UnExecute removes the target and re-adds the captured targetRoots snapshot to restore children removed by adding a parent. ```csharp public class AddTargetCommand : SelectCommand { public AddTargetCommand(TransformGizmo transformGizmo, Transform target, List targetRoots) : base(transformGizmo, target); public override void Execute(); public override void UnExecute(); } ``` -------------------------------- ### ExtVector3.MagnitudeInDirection Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Computes the signed magnitude of a vector along a given direction using the dot product. Optionally normalizes the direction before projection. ```APIDOC ## ExtVector3.MagnitudeInDirection ### Description Computes the signed magnitude of a vector along a given direction using the dot product. Optionally normalizes the direction before projection. ### Method MagnitudeInDirection (static method) ### Signature ```csharp public static float MagnitudeInDirection(Vector3 vector, Vector3 direction, bool normalizeParameters = true) ``` ### Parameters - `vector` (Vector3) - Required - Vector to project. - `direction` (Vector3) - Required - Projection direction (normalized first when `normalizeParameters` is true). - `normalizeParameters` (bool) - Optional (default `true`) - Whether to normalize `direction` before the dot product. ### Returns - `float` - `Vector3.Dot(vector, direction)` (the signed magnitude of `vector` along `direction`). ``` -------------------------------- ### TransformCommand class definition Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Records pre-drag (oldValues) and post-drag (newValues) transform of one target. Execute() applies newValues and refreshes pivot; UnExecute() applies oldValues and refreshes pivot. ```csharp public class TransformCommand : ICommand { public TransformCommand(TransformGizmo transformGizmo, Transform transform); public void StoreNewTransformValues(); public void Execute(); public void UnExecute(); struct TransformValues { public Vector3 position; public Quaternion rotation; public Vector3 scale; } } ``` -------------------------------- ### CustomTransformGizmos class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Serializable class holding per-axis handle mesh references, cached colliders, and original local scales for one transform type. ```csharp [Serializable] public class CustomTransformGizmos ``` -------------------------------- ### UndoRedoManager.Redo Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Redoes the most recently undone command. ```APIDOC ## [METHOD] Redo ### Description Redoes the most recently undone command. ### Method Signature `public static void Redo()` ### Usage Example ```csharp UndoRedoManager.Redo(); ``` ``` -------------------------------- ### ExtTransform.SetScaleFrom Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Scales a Transform to a new scale while keeping a world-space pivot point fixed. Useful for scaling from a specific point. ```APIDOC ## ExtTransform.SetScaleFrom ### Description Scales the target Transform to `newScale` while keeping `worldPivot` fixed in world space. ### Method Extension method on `Transform` ### Parameters - `target` (Transform) - Required (extension receiver) - Object to scale. - `worldPivot` (Vector3) - Required - World-space point that stays fixed during the scale. - `newScale` (Vector3) - Required - Target local scale. ### Returns - `void` ### Request Example ```csharp using RuntimeGizmos; Transform obj = someGameObject.transform; Vector3 worldPivot = gizmo.pivotPoint; // fixed point to scale from obj.SetScaleFrom(worldPivot, new Vector3(2, 2, 2)); ``` ``` -------------------------------- ### ExtMathf class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Public static class in the RuntimeGizmos namespace providing extension-method style helpers on float, Transform, TransformType, or Vector3. Source: Assets/RuntimeGizmo/Helpers/ExtMathf.cs:5. ```csharp public static class ExtMathf ``` -------------------------------- ### SetAxis Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Orients all four handles using Quaternion.LookRotation based on the provided axis directions. ```APIDOC ## SetAxis ### Description Orients all four handles using Quaternion.LookRotation based on the provided axis directions. ### Method SetAxis ### Parameters #### Parameters - **axisInfo** (AxisInfo) - Required - Directions built from `transformGizmo.GetAxisInfo()`. ### Response Returns `void`. ``` -------------------------------- ### ClearTargetsCommand class definition Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Command to clear all targets from the gizmo's selection. Execute calls transformGizmo.ClearTargets(false) and UnExecute re-adds every captured target root via transformGizmo.AddTarget(root, false). Constructor takes the gizmo and a snapshot of the full selection to restore on undo; the base constructor receives null for target. ```csharp public class ClearTargetsCommand : SelectCommand { public ClearTargetsCommand(TransformGizmo transformGizmo, List targetRoots) : base(transformGizmo, null) { this.targetRoots.AddRange(targetRoots); } public override void Execute(); public override void UnExecute(); } ``` -------------------------------- ### UndoRedo Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo A self-contained undo/redo stack pair. Used directly, or via the static UndoRedoManager singleton. ```APIDOC ## UndoRedo ### Description A self-contained undo/redo stack pair. Used directly, or via the static UndoRedoManager singleton. ### Class Definition ```csharp public class UndoRedo ``` ### Constructors - **UndoRedo()** - Default capacity (`DropoutStack` max length is `int.MaxValue`). - **UndoRedo(int maxUndoStored)** - `maxUndoStored`: maximum number of undoable commands retained. ### Properties - **maxUndoStored** (int) - `public int maxUndoStored {get {return undoCommands.maxLength;} set {SetMaxLength(value);}}` (L8). Setting it updates both undo and redo stack capacities. ### Methods - **Clear** - `public void Clear()` (L19) - Empties both the undo and redo stacks. - **Undo** - `public void Undo()` (L25) - Pops the top undo command, calls `UnExecute()`, and pushes it onto the redo stack. No-op when the undo stack is empty. - **Redo** - `public void Redo()` (L35) - Pops the top redo command, calls `Execute()`, and pushes it back onto the undo stack. No-op when the redo stack is empty. - **Insert** - `public void Insert(ICommand command)` (L45) - Pushes `command` onto the undo stack (unless `maxUndoStored <= 0`, in which case it returns without storing) and clears the redo stack. Does **not** execute the command. - **Execute** - `public void Execute(ICommand command)` (L53) - Calls `command.Execute()` then `Insert(command)`. ### Usage Example ```csharp using CommandUndoRedo; UndoRedo history = new UndoRedo(50); MyMoveCommand move = new MyMoveCommand(target); // custom ICommand history.Execute(move); // performs the action and records it history.Undo(); // reverts history.Redo(); // re-applies history.Clear(); // resets both stacks ``` ``` -------------------------------- ### ExtVector3 class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Static helper class for Vector3 operations. Source: Assets/RuntimeGizmo/Helpers/ExtVector3.cs:6. ```csharp public static class ExtVector3 ``` -------------------------------- ### ICommand interface definition Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Defines the contract for undoable commands. Implementations must provide Execute() and UnExecute() methods. Implemented by CommandGroup and all command classes. ```csharp public interface ICommand { void Execute(); void UnExecute(); } ``` -------------------------------- ### ExtTransform.SetScaleFrom extension method Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Scales target to newScale while keeping worldPivot fixed, as if using a parent transform as the new pivot. Sets target.localScale and adjusts target.position. Corresponds to ScaleType.FromPoint. Source: Assets/RuntimeGizmo/Helpers/ExtTransform.cs:10. ```csharp public static void SetScaleFrom(this Transform target, Vector3 worldPivot, Vector3 newScale) ``` -------------------------------- ### ICommand Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo The unit of undoable work. Implementations must be able to run the operation (Execute) and revert it (UnExecute). ```APIDOC ## ICommand ### Description The unit of undoable work. Implementations must be able to run the operation (`Execute`) and revert it (`UnExecute`). ### Interface Definition ```csharp public interface ICommand { void Execute(); void UnExecute(); } ``` ### Methods - **Execute** () - Runs the operation. - **UnExecute** () - Reverts the operation. ``` -------------------------------- ### SetEnable Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Activates or deactivates all four handle GameObjects, only when their current active state differs. ```APIDOC ## SetEnable ### Description Activates or deactivates all four handle GameObjects, only when their current active state differs. ### Method SetEnable ### Parameters #### Parameters - **enable** (bool) - Required - Whether to activate or deactivate the handles. ### Response Returns `void`. ``` -------------------------------- ### SetPosition method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Moves all four handles to the given position, typically set to the gizmo's pivot point. ```csharp public void SetPosition(Vector3 position) ``` -------------------------------- ### UndoRedoManager class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Static facade over a single internal UndoRedo instance. TransformGizmo uses this manager for all selection and transform commands. ```csharp public static class UndoRedoManager ``` -------------------------------- ### MagnitudeInDirection method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns the signed magnitude of vector along direction using Vector3.Dot. Used heavily by TransformGizmo for move/scale/rotate delta projection. Source: Assets/RuntimeGizmo/Helpers/ExtVector3.cs:8. ```csharp public static float MagnitudeInDirection(Vector3 vector, Vector3 direction, bool normalizeParameters = true) ``` -------------------------------- ### UndoRedoManager.Insert Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Records a command without executing it. The command must already carry its own old/new state. ```APIDOC ## [METHOD] Insert ### Description Records a command without executing it. The command must already carry its own old/new state. ### Method Signature `public static void Insert(ICommand command)` ### Parameters - **command** (ICommand) - Required - The command to record. ### Usage Example ```csharp UndoRedoManager.Insert(myTransformCommand); ``` ``` -------------------------------- ### ExtVector3.Abs Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns the component-wise absolute value of a Vector3. ```APIDOC ## ExtVector3.Abs ### Description Returns the component-wise absolute value of a Vector3. ### Method Abs (extension method) ### Signature ```csharp public static Vector3 Abs(this Vector3 vector) ``` ### Parameters - `vector` (Vector3) - Required (extension receiver) - Input. ### Returns - `Vector3` - Component-wise absolute value. ``` -------------------------------- ### SetPosition Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Moves all four handles to the specified position. ```APIDOC ## SetPosition ### Description Moves all four handles to the specified position. ### Method SetPosition ### Parameters #### Parameters - **position** (Vector3) - Required - The position to move the handles to. ### Response Returns `void`. ``` -------------------------------- ### Abs method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Extension method returning component-wise absolute value of a Vector3. Source: Assets/RuntimeGizmo/Helpers/ExtVector3.cs:14. ```csharp public static Vector3 Abs(this Vector3 vector) ``` -------------------------------- ### ExtVector3.IsInDirection Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Determines whether two direction vectors point in the same general direction (positive dot product). ```APIDOC ## ExtVector3.IsInDirection ### Description Determines whether two direction vectors point in the same general direction (positive dot product). ### Method IsInDirection (static method) ### Signature ```csharp public static bool IsInDirection(Vector3 direction, Vector3 otherDirection) ``` ### Parameters - `direction` (Vector3) - Required - First direction. - `otherDirection` (Vector3) - Required - Second direction. ### Returns - `bool` - `Vector3.Dot(direction, otherDirection) > 0f`. ``` -------------------------------- ### TransformGizmoCustomGizmo Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo A MonoBehaviour that attaches to a TransformGizmo and drives it in manual mode, replacing built-in gizmo rendering with user-supplied 3D meshes. It auto-finds the TransformGizmo, sets manual handling, and manages custom gizmo meshes for translation, rotation, and scale. ```APIDOC ## TransformGizmoCustomGizmo ### Description A `MonoBehaviour` that attaches to a `TransformGizmo` and drives it in "manual" mode. Drop it in the scene, assign `transformGizmo` (or let it auto-find), and assign mesh references to the three `CustomTransformGizmos` fields. > Note from source: currently does not really handle `TransformType.All`. ### Public Fields - `autoFindTransformGizmo` (bool) - Default: `true` - If `transformGizmo` is null at `Awake`, find one with `GameObject.FindObjectOfType()`. - `transformGizmo` (TransformGizmo) - Default: `null` - The gizmo component to control. - `customTranslationGizmos` (CustomTransformGizmos) - Default: `new CustomTransformGizmos()` - Meshes used for the Move handles. - `customRotationGizmos` (CustomTransformGizmos) - Default: `new CustomTransformGizmos()` - Meshes used for the Rotate handles. - `customScaleGizmos` (CustomTransformGizmos) - Default: `new CustomTransformGizmos()` - Meshes used for the Scale handles. - `scaleBasedOnDistance` (bool) - Default: `true` - Multiply mesh scale by `scaleMultiplier * transformGizmo.GetDistanceMultiplier()`. - `scaleMultiplier` (float) - Default: `.4f` - Base distance scale factor. - `gizmoLayer` (int) - Default: `2` - Layer assigned to all gizmo meshes; `2` is the `IgnoreRaycast` layer. Set to a layer used only by gizmos so selection raycasts hit them. ### Lifecycle Behavior - `Awake()` — auto-finds the `TransformGizmo`, then sets: - `transformGizmo.manuallyHandleGizmo = true` - `transformGizmo.circularRotationMethod = true` (mesh-based rotation works like turning a wheel) - `mask = LayerMask.GetMask(LayerMask.LayerToName(gizmoLayer))` - calls `Init(gizmoLayer)` on all three `CustomTransformGizmos` (assigns layers, caches colliders and original scales). - `OnEnable()` — subscribes `CheckForSelectedAxis` to `transformGizmo.onCheckForSelectedAxis` and `OnDrawCustomGizmos` to `transformGizmo.onDrawCustomGizmo`. - `OnDisable()` — unsubscribes both. ### Manual Axis Selection `CheckForSelectedAxis()` (private) runs when `manuallyHandleGizmo` is set: - Enables the correct `CustomTransformGizmos` group for the current transform type (`ShowProperGizmoType`, based on `transformGizmo.mainTargetRoot != null` and `transformGizmo.TranslatingTypeContains(...)`). - On left mouse down, raycasts against `mask`; the hit collider is mapped to an `Axis` via each enabled group's `GetSelectedAxis(Collider)` (checked in order: Move → Rotate → Scale). - Reports the result with `transformGizmo.SetTranslatingAxis(type, selectedAxis)`. ### Drawing `OnDrawCustomGizmos()` (private, invoked from `transformGizmo.onDrawCustomGizmo` in `LateUpdate`) calls `DrawCustomGizmo` for each active type: - `customGizmo.SetAxis(transformGizmo.GetAxisInfo())` - `customGizmo.SetPosition(transformGizmo.pivotPoint)` - optionally scales by `scaleMultiplier * GetDistanceMultiplier()` - while scaling, grows the dragged axis by `1f + transformGizmo.totalScaleAmount` ### Usage Example ```csharp // Create an empty GameObject with a Camera for the gizmo, // then attach custom handle meshes in the inspector. Equivalent setup in code: TransformGizmo gizmo = gameObject.AddComponent(); TransformGizmoCustomGizmo customGizmo = gameObject.AddComponent(); customGizmo.transformGizmo = gizmo; customGizmo.autoFindTransformGizmo = false; customGizmo.gizmoLayer = 8; // a dedicated "Gizmo" layer // Assign pre-built handle meshes (each needs a Collider child): customGizmo.customTranslationGizmos.xAxisGizmo = xArrowMesh.transform; customGizmo.customTranslationGizmos.yAxisGizmo = yArrowMesh.transform; customGizmo.customTranslationGizmos.zAxisGizmo = zArrowMesh.transform; customGizmo.customTranslationGizmos.anyAxisGizmo = centerCubeMesh.transform; ``` ``` -------------------------------- ### CommandGroup Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Groups multiple ICommands into one undoable unit. TransformGizmo uses it to make a multi-target transform drag a single undo step. ```APIDOC ## CommandGroup ### Description Groups multiple `ICommand`s into one undoable unit. `TransformGizmo` uses it to make a multi-target transform drag a single undo step. ### Constructors - `public CommandGroup()` - empty group. - `public CommandGroup(List commands)` - `commands`: initial command list (copied via `AddRange`). ### Methods - `public void Set(List commands)` - Replaces the inner list with `commands` (reference assignment, not a copy). - `public void Add(ICommand command)` - Appends a command. - `public void Remove(ICommand command)` - Removes a command. - `public void Clear()` - Empties the group. - `public void Execute()` - Executes all commands in order. - `public void UnExecute()` - Un-executes all commands in reverse order. ### Usage Example ```csharp CommandGroup group = new CommandGroup(); foreach (var cmd in myCommands) group.Add(cmd); UndoRedoManager.Insert(group); // one Undo call reverts the whole batch ``` ``` -------------------------------- ### ExtTransform class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Public static class in the RuntimeGizmos namespace providing extension methods on Transform. Source: Assets/RuntimeGizmo/Helpers/ExtTransform.cs:6. ```csharp public static class ExtTransform ``` -------------------------------- ### CommandGroup class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Declares a class that groups multiple ICommands into one undoable unit. TransformGizmo uses it to make a multi-target transform drag a single undo step. ```csharp public class CommandGroup : ICommand ``` -------------------------------- ### LinePlaneIntersect method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Computes intersection of an infinite line with a plane. Returns Vector3.zero when parallel. Used by TransformGizmo to track the mouse on the drag plane. ```csharp public static Vector3 LinePlaneIntersect(Vector3 linePoint, Vector3 lineVec, Vector3 planePoint, Vector3 planeNormal) ``` -------------------------------- ### ExtMathf.SafeDivide Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Divides two floats safely, returning 0 when the divisor is 0. Used to avoid division by zero in scaling operations. ```APIDOC ## ExtMathf.SafeDivide ### Description Divides `value` by `divider`, returning 0 if `divider` is 0. ### Method Static method on `ExtMathf` ### Parameters - `value` (float) - Required - Numerator. - `divider` (float) - Required - Denominator. ### Returns - `float` - `value / divider`, or `0` when `divider == 0` ``` -------------------------------- ### ScaleMultiply Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Scales each handle relative to its cached original scale based on the provided multiplier. ```APIDOC ## ScaleMultiply ### Description Scales each handle relative to its cached original scale based on the provided multiplier. ### Method ScaleMultiply ### Parameters #### Parameters - **scaleMultiplier** (Vector4) - Required - `x`/`y`/`z` are per-axis grow amounts (used during scale transforming), `w` is the uniform multiplier (distance-based). ### Response Returns `void`. ``` -------------------------------- ### ExtTransform.GetCenter Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns the world-space center of a Transform based on the specified CenterType. Used for pivot point calculation. ```APIDOC ## ExtTransform.GetCenter ### Description Gets the world-space center of the Transform according to the given `CenterType`. ### Method Extension method on `Transform` ### Parameters - `transform` (Transform) - Required (extension receiver) - Object to measure. - `centerType` (CenterType) - Required - `CenterType.Solo`: returns `renderer.bounds.center` of the object's own first `Renderer`, or `transform.position` if none. `CenterType.All`: bounds-encapsulates the object's and all descendants' renderer bounds (or positions when no renderer) starting from `transform.position`. ### Returns - `Vector3` - The world-space center. ### Request Example ```csharp using RuntimeGizmos; Vector3 allCenter = someObject.GetCenter(CenterType.All); Vector3 soloCenter = someObject.GetCenter(CenterType.Solo); ``` ``` -------------------------------- ### GetDistanceMultiplier method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns a scale factor to keep handle sizes constant on screen. For orthographic cameras: Mathf.Max(.01f, myCamera.orthographicSize * 2f). For perspective: Mathf.Max(.01f, Mathf.Abs(ExtVector3.MagnitudeInDirection(pivotPoint - transform.position, myCamera.transform.forward))). Returns 0f when mainTargetRoot is null. ```csharp public float GetDistanceMultiplier() ``` -------------------------------- ### IsInDirection method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns true if the dot product of two directions is greater than zero. Source: Assets/RuntimeGizmo/Helpers/ExtVector3.cs:24. ```csharp public static bool IsInDirection(Vector3 direction, Vector3 otherDirection) ``` -------------------------------- ### ExtMathf.SafeDivide method Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns value / divider, or 0 when divider == 0. Used by ExtTransform.SetScaleFrom to avoid division by zero when a scale axis is 0. Source: Assets/RuntimeGizmo/Helpers/ExtMathf.cs:12. ```csharp public static float SafeDivide(float value, float divider) ``` -------------------------------- ### ExtMathf.Squared extension method Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Extension method on float that returns value * value. Used by TransformGizmo.HandleNearest to compare squared distances via GetHandleLength(...).Squared(). Source: Assets/RuntimeGizmo/Helpers/ExtMathf.cs:7. ```csharp public static float Squared(this float value) ``` -------------------------------- ### GetSelectedAxis method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns the axis corresponding to the collider hit by the selection raycast, or Axis.None if no match. ```csharp public Axis GetSelectedAxis(Collider selectedCollider) ``` -------------------------------- ### ExtMathf.Squared Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Extension method that returns the square of a float value. Used internally for squared distance comparisons. ```APIDOC ## ExtMathf.Squared ### Description Returns the square of the input float value. ### Method Extension method on `float` ### Parameters - `value` (float) - Required (extension receiver) - Value to square. ### Returns - `float` - `value * value` ``` -------------------------------- ### ClosestPointsOnSegmentToLine method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Delegates to ClosestPointsOnTwoLines then clamps first to the segment. Used by TransformGizmo.ClosestDistanceFromMouseToLines for hover detection. ```csharp public static IntersectPoints ClosestPointsOnSegmentToLine(Vector3 segment0, Vector3 segment1, Vector3 linePoint, Vector3 lineDirection) ``` -------------------------------- ### TransformGizmo MonoBehaviour declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Main entry point of the Unity3DRuntimeTransformGizmo library. Must be placed on a GameObject with a Camera component; targets require colliders for selection. ```csharp [RequireComponent(typeof(Camera))] public class TransformGizmo : MonoBehaviour ``` -------------------------------- ### UndoRedoManager.Clear Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Clears all stored commands from the undo/redo history. ```APIDOC ## [METHOD] Clear ### Description Clears all stored commands from the undo/redo history. ### Method Signature `public static void Clear()` ### Usage Example ```csharp UndoRedoManager.Clear(); ``` ``` -------------------------------- ### TransformGizmoCustomGizmo class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Public class declaration for the custom gizmo component. Attach to a TransformGizmo to replace built-in line/plane rendering with user-supplied meshes. Note: does not fully handle TransformType.All. ```csharp public class TransformGizmoCustomGizmo : MonoBehaviour ``` -------------------------------- ### DropoutStack class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Declares a bounded stack built on LinkedList. When full, pushing evicts the oldest element. Used internally by UndoRedo for both stacks. ```csharp public class DropoutStack : LinkedList ``` -------------------------------- ### ClosestPointsOnTwoLines method signature Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Returns closest points on two lines. For parallel lines (d == 0), returns point1 and projection of point1 - point2 onto point2Direction added to point2. Directions are not normalized by design. ```csharp public static IntersectPoints ClosestPointsOnTwoLines(Vector3 point1, Vector3 point1Direction, Vector3 point2, Vector3 point2Direction) ``` -------------------------------- ### UndoRedoManager.Undo Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Undoes the most recent command in the undo history. ```APIDOC ## [METHOD] Undo ### Description Undoes the most recent command in the undo history. ### Method Signature `public static void Undo()` ### Usage Example ```csharp UndoRedoManager.Undo(); ``` ``` -------------------------------- ### ExtVector3.IsParallel Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Checks whether two direction vectors are parallel within a given precision threshold. ```APIDOC ## ExtVector3.IsParallel ### Description Checks whether two direction vectors are parallel within a given precision threshold. ### Method IsParallel (static method) ### Signature ```csharp public static bool IsParallel(Vector3 direction, Vector3 otherDirection, float precision = .0001f) ``` ### Parameters - `direction` (Vector3) - Required - First direction. - `otherDirection` (Vector3) - Required - Second direction. - `precision` (float) - Optional (default `.0001f`) - Threshold for the cross product's squared magnitude. ### Returns - `bool` - `Vector3.Cross(direction, otherDirection).sqrMagnitude < precision`. ``` -------------------------------- ### ClearAndAddTargetCommand class definition Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Command produced when the user clicks a new object with no modifier keys (TransformGizmo.ClearAndAddTarget). Execute() clears targets and adds the new target; UnExecute() removes the target and re-adds previous target roots. ```csharp public class ClearAndAddTargetCommand : SelectCommand { public ClearAndAddTargetCommand(TransformGizmo transformGizmo, Transform target, List targetRoots) : base(transformGizmo, target); public override void Execute(); public override void UnExecute(); } ``` -------------------------------- ### ExtTransformType class declaration Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Static helper class for TransformType operations. Source: Assets/RuntimeGizmo/Helpers/ExtTransformType.cs:5. ```csharp public static class ExtTransformType ``` -------------------------------- ### Geometry.ClosestPointsOnSegmentToLine Source: https://github.com/hiddenmonk/unity3druntimetransformgizmo Finds the closest points between a segment and an infinite line. The point on the segment is clamped to the segment, while the point on the line remains on the infinite line. ```APIDOC ## Geometry.ClosestPointsOnSegmentToLine ### Description Finds the closest points between a segment and an infinite line. The point on the segment is clamped to the segment, while the point on the line remains on the infinite line. ### Method `public static IntersectPoints ClosestPointsOnSegmentToLine(Vector3 segment0, Vector3 segment1, Vector3 linePoint, Vector3 lineDirection)` ### Parameters - `segment0` (Vector3) - Required - Start point of the segment. - `segment1` (Vector3) - Required - End point of the segment. - `linePoint` (Vector3) - Required - Point on the line. - `lineDirection` (Vector3) - Required - Direction of the line. ### Returns `IntersectPoints` - The closest point on the segment (`first`) and the closest point on the line (`second`). ### Request Example ```csharp IntersectPoints pts = Geometry.ClosestPointsOnSegmentToLine( segStart, segEnd, ray.origin, ray.direction); float distance = Vector3.Distance(pts.first, pts.second); ``` ```