using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
public static class ffind
{
//查找子类的物体
public static Transform Ficd(Transform tr, string ne, bool param = false)
{
if (null == tr)
{
return null;
}
Transform[] trs = tr.GetComponentsInChildren<Transform>(param);
int len = trs.Length;
for (int i = 0; i < len; ++i)
{
Transform Tar = trs[i];
if (ne == Tar.name)
{
return Tar;
}
}
return null;
}
public static Component Ficd(string typeStr, Component host, string ne = null)
{
if (host != null)
{
Type type = Type.GetType(typeStr);
if (type == null)
{
type = Type.GetType(string.Format("UnityEngine.{0},UnityEngine", typeStr));
}
if (string.IsNullOrEmpty(ne))
{
return host.GetComponent(type);
}
else
{
Component[] trs = host.GetComponentsInChildren(type, true);
for (int i = 0; i < trs.Length; ++i)
{
if (trs[i] != null)
{
if (ne == trs[i].name)
{
return trs[i];
}
}
}
}
}
return null;
}
public static T Ficd<T>(Component host, string name = null) where T : Component
{
if (host == null)
{
}
else if (string.IsNullOrEmpty(name))
{
return host.GetComponent<T>();
}
else
{
T[] ctrs = host.GetComponentsInChildren<T>(true);
for (int i = 0; i < ctrs.Length; i++)
{
if (ctrs[i] != null)
{
if (name == ctrs[i].name)
{ return ctrs[i]; }
}
}
}
return null;
}
}