Files
Main/Assets/GameAssets/Resources/GameUI/Common/UnityEngine/TransformExtension.cs
2025-01-25 04:38:09 +08:00

41 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text;
namespace UnityEngine
{
/// <summary>
/// Transform的扩展
/// </summary>
public static class TransformExtension
{
/// <summary>
/// 获取组件的操作,如果有则直接获取,没有,则添加
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="trans"></param>
/// <returns></returns>
public static T RequireComponent<T>(this Transform trans) where T : Component
{
var cm = trans.GetComponent<T>();
if (cm == null)
{
cm = trans.gameObject.AddComponent<T>();
}
return cm;
}
/// <summary>
/// 设置Parent集成Cinematic Editor后有用到tranform.SetParent这种写法
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="trans"></param>
/// <returns></returns>
public static void SetParent<T>(this Transform trans) where T : Component
{
}
}
}