/// <summary> /// Align all transforms rotation with one Transform, or on mini/max values of boundaries /// </summary> /// <param name="referenceTransform"> /// A <see cref="Transform"/> which all other transforms will be aligned with, if alignType is "mean" /// </param> /// <param name="transformList"> /// The <see cref="Transform[]"/> of all objects to be aligned /// </param> /// <param name="axis"> /// The axis to align on : <see cref="Vector3.one"/> to align all axis, <see cref="Vector3.right"/> to align on the X axis, <see cref="Vector3.up"/> to align on the Y axis, <see cref="Vector3.forward"/> to align on the Z axis /// </param> /// <param name="alignType"> /// Witch type of alignement we do, from the <see cref="Landmark"/> enum /// </param> public static void AlignRotation(Transform referenceTransform, Transform[] transformList, Vector3 axis, Landmark alignType) { // Get the rotation from the active selected object Vector3 activeRotation = referenceTransform.eulerAngles; // If alignment is not the mean one, search the min or max oriented object Vector3 markRotation = referenceTransform.eulerAngles; if (alignType == Landmark.minimum) { markRotation = BasicExtents.GetMinMarkRotation(referenceTransform.eulerAngles, transformList); } else if (alignType == Landmark.maximum) { markRotation = BasicExtents.GetMaxMarkRotation(referenceTransform.eulerAngles, transformList); } activeRotation = markRotation; foreach (Transform nextTransform in transformList) { Vector3 newRot; // Apply the angles changes from the axis to align with newRot.x = (axis == Vector3.one || axis == Vector3.right) ? activeRotation.x : nextTransform.eulerAngles.x; newRot.y = (axis == Vector3.one || axis == Vector3.up) ? activeRotation.y : nextTransform.eulerAngles.y; newRot.z = (axis == Vector3.one || axis == Vector3.forward) ? activeRotation.z : nextTransform.eulerAngles.z; nextTransform.rotation = Quaternion.Euler(newRot); } }
/// <summary> /// Align all transforms local scale with one Transform, or on mini/max values of boundaries /// </summary> /// <param name="referenceTransform"> /// A <see cref="Transform"/> which all other transforms will be aligned with, if alignType is "mean" /// </param> /// <param name="transformList"> /// The <see cref="Transform[]"/> of all objects to be aligned /// </param> /// <param name="axis"> /// The axis to align on : <see cref="Vector3.one"/> to align all axis, <see cref="Vector3.right"/> to align on the X axis, <see cref="Vector3.up"/> to align on the Y axis, <see cref="Vector3.forward"/> to align on the Z axis /// </param> /// <param name="alignType"> /// Witch type of alignement we do, from the <see cref="Landmark"/> enum /// </param> public static void AlignScale(Transform referenceTransform, Transform[] transformList, Vector3 axis, Landmark alignType) { // Get the local scale from the active selected object Vector3 activeScale = referenceTransform.localScale; // If alignment is not the mean one, search the min or max positioned object Vector3 markScale = referenceTransform.localScale; if (alignType == Landmark.minimum) { markScale = BasicExtents.GetMinMarkScale(referenceTransform.localScale, transformList); } else if (alignType == Landmark.maximum) { markScale = BasicExtents.GetMaxMarkScale(referenceTransform.localScale, transformList); } activeScale = markScale; foreach (Transform nextTransform in transformList) { Vector3 newScale; // Apply the angles changes from the axis to align with newScale.x = (axis == Vector3.one || axis == Vector3.right) ? activeScale.x : nextTransform.localScale.x; newScale.y = (axis == Vector3.one || axis == Vector3.up) ? activeScale.y : nextTransform.localScale.y; newScale.z = (axis == Vector3.one || axis == Vector3.forward) ? activeScale.z : nextTransform.localScale.z; nextTransform.localScale = newScale; } }
/// <summary> /// Retrieve the maximum coordinates for each axis from a transform list /// </summary> /// <param name="referencePosition"> /// The first position to be used as a reference, in a <see cref="Vector3"/> /// </param> /// <param name="transformList"> /// The <see cref="Transform[]"/> to retrieve position from /// </param> /// <returns> /// The maximum extents in a <see cref="Vector3"/> /// </returns> public static Vector3 GetMaxMarkPosition(Vector3 referencePosition, Transform[] transformList, BoundType type) { switch (type) { case BoundType.Collider: return(ColliderExtents.GetMaxMarkPosition(referencePosition, transformList)); case BoundType.Renderer: return(RendererExtents.GetMaxMarkPosition(referencePosition, transformList)); default: return(BasicExtents.GetMaxMarkPosition(referencePosition, transformList)); } }
/// <summary> /// Linear (local) Scale distribution /// </summary> /// <param name="activeTransform"> /// The <see cref="Transform"/> to use as the first transform /// </param> /// <param name="transformList"> /// All <see cref="Transform[]"/> to be distributed /// </param> /// <param name="sortBy"> /// The axis which is used to sort the transform list, <see cref="SortAxis"/> /// </param> /// <param name="axis"> /// The axis to distribute the transforms on, using the same <see cref="Vector3"/> format /// </param> public static void DistributeScale(Transform activeTransform, Transform[] transformList, SortAxis sortBy, Vector3 axis) { if (transformList.Length == 0) { return; } // Get the min and max marks Vector3 minMarkScale = BasicExtents.GetMinMarkScale(activeTransform.localScale, transformList); Vector3 maxMarkScale = BasicExtents.GetMaxMarkScale(activeTransform.localScale, transformList); // Interval Vector3 distanceBetween = (maxMarkScale - minMarkScale) / (transformList.Length - 1); // Delta from minMark Vector3 delta = Vector3.zero; // List of selected objects, to sort from the min position to the max position List <Transform> list = new List <Transform>(transformList); // Sort the selected objects as requested switch (sortBy) { case SortAxis.Z: list.Sort(ByVector3PositionZ); break; case SortAxis.Y: list.Sort(ByVector3PositionY); break; default: list.Sort(ByVector3PositionX); break; } foreach (Transform nextTransform in list) { Vector3 newPos; newPos.x = (axis == Vector3.one || axis == Vector3.right) ? minMarkScale.x + delta.x : nextTransform.localScale.x; newPos.y = (axis == Vector3.one || axis == Vector3.up) ? minMarkScale.y + delta.y : nextTransform.localScale.y; newPos.z = (axis == Vector3.one || axis == Vector3.forward) ? minMarkScale.z + delta.z : nextTransform.localScale.z; nextTransform.localScale = newPos; delta += distanceBetween; } }