This commit is contained in:
2026-06-09 09:18:17 +07:00
parent 3578a2750c
commit 71a096556a
5777 changed files with 6675 additions and 13 deletions

View File

@@ -1,61 +0,0 @@
/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Utility
{
using UnityEngine;
/// <summary>
/// Extension methods for the UnityEngine.Transform class.
/// </summary>
public static class TransformExtensions
{
/// <summary>
/// Sets the parent of the transform object to the specified parent.
/// </summary>
/// <param name="transform">The transform to set the parent of.</param>
/// <param name="parent">The parent of the transform.</param>
public static void SetParentOrigin(this Transform transform, Transform parent)
{
transform.parent = parent;
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity;
transform.localScale = Vector3.one;
}
/// <summary>
/// Recursively sets the layer on all of the children.
/// </summary>
/// <param name="transform">The transform to set the layer on.</param>
/// <param name="layer">The layer to set.</param>
public static void SetLayerRecursively(this Transform transform, int layer)
{
transform.gameObject.layer = layer;
for (int i = 0; i < transform.childCount; ++i) {
transform.GetChild(i).SetLayerRecursively(layer);
}
}
/// <summary>
/// Returns the component of the specified type in the GameObject or any of its parents.
/// </summary>
/// <param name="transform">The transform to get the component on.</param>
/// <typeparam name="T">The type of component to return.</typeparam>
/// <returns>THe component of the specified type in the GameObject or any of its parents. Can be null.</returns>
public static T GetComponentInParentIncludeInactive<T>(this Transform transform) where T : Component
{
var parent = transform;
T component;
while (parent != null) {
if ((component = parent.GetComponent<T>()) != null) {
return component;
}
parent = parent.parent;
}
return null;
}
}
}