使用T GetComponent快速获取组件
代码的展示
// An highlighted block
public static T GetComponent<T>(this GameObject varTran, string varPath) where T : Component
{
if (varTran == null)
return null;
if (string.IsNullOrEmpty(varPath))
return varTran.GetComponent<T>();
Transform TempTran = varTran.transform.Find(varPath);
if (TempTran == null)
return null;
return TempTran.GetComponent<T>();
}