UI-查找游戏物体

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;
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值