41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
|
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
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|