using FishNet.Documenting;
using FishNet.Object;
using UnityEngine;
namespace FishNet.Utility.Extension
{
[APIExclude]
public static class TransformFN
{
///
/// Sets values of TransformProperties to a transforms world properties.
///
public static TransformProperties GetWorldProperties(this Transform t)
{
TransformProperties tp = new TransformProperties(t.position, t.rotation, t.localScale);
return tp;
}
///
/// Sets values of TransformPropertiesCls to a transforms world properties.
///
public static void SetWorldProperties(this TransformPropertiesCls tp, Transform t)
{
tp.Position = t.position;
tp.Rotation = t.rotation;
tp.LocalScale = t.localScale;
}
///
/// Sets the offset values of target from a transform.
///
/// Position offset result.
/// Rotation offset result.
public static void SetTransformOffsets(this Transform t, Transform target, ref Vector3 pos, ref Quaternion rot)
{
if (target == null)
return;
pos = (target.position - t.position);
rot = (target.rotation * Quaternion.Inverse(t.rotation));
}
///
/// Sets the offset values of target from a transform.
///
/// Position offset result.
/// Rotation offset result.
public static TransformProperties GetTransformOffsets(this Transform t, Transform target)
{
if (target == null)
return default;
return new TransformProperties(
(target.position - t.position),
(target.rotation * Quaternion.Inverse(t.rotation)),
(target.localScale - t.localScale)
);
}
///
/// Sets local position and rotation for a transform.
///
public static void SetLocalPositionAndRotation(this Transform t, Vector3 pos, Quaternion rot)
{
t.localPosition = pos;
t.localRotation = rot;
}
///
/// Sets local position, rotation, and scale for a transform.
///
public static void SetLocalPositionRotationAndScale(this Transform t, Vector3 pos, Quaternion rot, Vector3 scale)
{
t.localPosition = pos;
t.localRotation = rot;
t.localScale = scale;
}
}
}