using UnityEngine.Scripting.APIUpdating;
namespace UnityEngine.U2D.IK
{
///
/// General utilities for 2D IK.
///
[MovedFrom("UnityEngine.Experimental.U2D.IK")]
public class IKUtility
{
///
/// Check if a Unity Transform is a descendent of another Unity Transform.
///
/// Unity Transform to check.
/// Unity Transform ancestor.
/// Returns true if the Unity Transform is a descendent. False otherwise.
public static bool IsDescendentOf(Transform transform, Transform ancestor)
{
Debug.Assert(transform != null, "Transform is null");
Transform currentParent = transform.parent;
while (currentParent)
{
if (currentParent == ancestor)
return true;
currentParent = currentParent.parent;
}
return false;
}
///
/// Gets the hierarchy depth of a Unity Transform.
///
/// Unity Transform to check.
/// Integer value for hierarchy depth.
public static int GetAncestorCount(Transform transform)
{
Debug.Assert(transform != null, "Transform is null");
int ancestorCount = 0;
while (transform.parent)
{
++ancestorCount;
transform = transform.parent;
}
return ancestorCount;
}
///
/// Gets the maximum chain count for a IKChain2D.
///
/// IKChain2D to query.
/// Integer value for the maximum chain count.
public static int GetMaxChainCount(IKChain2D chain)
{
int maxChainCount = 0;
if (chain.effector)
maxChainCount = GetAncestorCount(chain.effector) + 1;
return maxChainCount;
}
}
}