zoukankan      html  css  js  c++  java
  • unity transform 常用操作

    1.寻找物体

    1.1 寻找满足条件的子物体

    `    public static Transform FindObj(Transform transform, Func<Transform, bool> condition, bool isGrandsonObj = false)
    {
        Transform[] allChilds = transform.GetComponentsInRealChildren<Transform>(isGrandsonObj);
    
        foreach (Transform child in allChilds)
        {
            if (condition(child))
            {
                return child;
            }
        }
    
        return transform;
    }
    
    public static Transform FindObj(Transform transform, string tag, bool isGrandsonObj = false)
    {
        return FindObj(transform, (t) => t.tag.Equals(tag), isGrandsonObj);
    }`
    

    1.2 寻找一组满足条件的子物体

    `    public static List<Transform> FindObjs(Transform transform, Func<Transform, bool> condition, bool isGrandsonObj = false)
    {
        Transform[] allChilds = transform.GetComponentsInRealChildren<Transform>(isGrandsonObj);
        List<Transform> list = new List<Transform>();
    
        foreach (Transform child in allChilds)
        {
            if (condition(child))
            {
                list.Add(child);
            }
        }
        return list;
    }
    
    public static List<Transform> FindObjs(Transform transform, string tag, bool isGrandsonObj = false)
    {
        return FindObjs(transform, (t) => t.tag.Equals(tag), isGrandsonObj);
    }`
    

    2. 操作一组物体

    2.1 对一组满足条件物体进行操作

    `    public static void AddActionObjects(Transform[] transform, Func<Transform, bool> condition, Action<Transform> action)
    {
        foreach (Transform child in transform)
        {
            if (condition(child))
            {
                action(child);
            }
        }
    }`
    

    2.2 常用扩展方法

    `    public static void AddActionObjects(Transform[] transform, Action<Transform> action)
    {
        AddActionObjects(transform, (t) => true, action);
    }
    
    public static void AddActionObjects(Transform transform, Func<Transform, bool> condition, Action<Transform> action, bool isGrandsonObj = false)
    {
        Transform[] allChilds = transform.GetComponentsInChildren<Transform>(isGrandsonObj);
        AddActionObjects(allChilds, condition, action);
    }
    
    public static void AddActionObjects(Transform transform, Action<Transform> action, bool isGrandsonObj = false)
    {
        AddActionObjects(transform, (t) => true, action, isGrandsonObj);
    }
    
    public static void AddActionObjects(Transform transform, string tag, Action<Transform> action, bool isGrandsonObj = false)
    {
        AddActionObjects(transform, (t) => t.tag.Equals(tag), action, isGrandsonObj);
    }
    

    `

  • 相关阅读:
    MySQL:Mysql字符串截取函数SUBSTRING的用法说明
    windows2003+iis6.0+php(fastcgi)5.3+wincache+memcached
    apache 80端口未被占用,启动不了的问题
    服务器端口大全
    UCenter 表结构
    “来自客户端名 a 的远程会话超出了所允许的失败登录最大次数。强行终止了会话。”原因及解决方法
    开发云应用从何入手?
    Building Nutch: Open Source Search
    Nutch0.9加入ICTCLAS 支持中文分词等(转)
    OWL解惑 :AllValuesFrom与Range的区别 关于Domain和Range
  • 原文地址:https://www.cnblogs.com/programmingAdorableNew/p/10348234.html
Copyright © 2011-2022 走看看