/// <summary> /// Sets an objects position at point with custom origin snapping. /// </summary> public static Vector3 Point(this HUMTransform.Data.To to, Vector3 point, float padding = 0f) { var snapObjectHalf = to.positionData.from.transform.Size().Half(); switch (to.positionData.position) { case HUMTransform.Data.TransformSnapPosition.Center: to.positionData.from.transform.position = point; break; case HUMTransform.Data.TransformSnapPosition.Top: to.positionData.from.transform.position = new Vector3(point.x, point.y - padding - snapObjectHalf.y, point.z); break; case HUMTransform.Data.TransformSnapPosition.Bottom: to.positionData.from.transform.position = new Vector3(point.x, point.y + padding + snapObjectHalf.y, point.z); break; case HUMTransform.Data.TransformSnapPosition.Left: to.positionData.from.transform.position = new Vector3(point.x + padding + snapObjectHalf.x, point.y, point.z); break; case HUMTransform.Data.TransformSnapPosition.Right: to.positionData.from.transform.position = new Vector3(point.x - padding - snapObjectHalf.x, point.y, point.z); break; } return(point); }
/// <summary> /// Starts the operation of snapping to the outside of a bounding box which is created from the center of a transform. /// </summary> public static HUMTransform.Data.ObjectBounds ObjectBounds(this HUMTransform.Data.To to, Transform snapTo) { var snapObjectHalf = to.positionData.from.transform.Size().Half(); var snapToHalf = snapTo.Size().Half(); var snapSurfaceData = new HUMTransform.Data.ObjectBounds(snapTo, to, snapObjectHalf, snapToHalf); return(snapSurfaceData); }
/// <summary> /// Sets a transforms position to a point in space, but locks an axis from being altered. /// </summary> public static Vector2 Point(this HUMTransform.Data.To to, Vector2 point, Axis lockedAxis) { switch (lockedAxis) { case Axis.X: return(Point(to, new Vector3(to.positionData.from.transform.position.x, point.x, point.y))); case Axis.Y: return(Point(to, new Vector3(point.x, to.positionData.from.transform.position.y, point.y))); case Axis.Z: return(Point(to, new Vector3(point.x, point.y, to.positionData.from.transform.position.z))); } return(Vector3.zero); }