其他分享
首页 > 其他分享> > Unity遍历预制体,代码修改参数

Unity遍历预制体,代码修改参数

作者:互联网

// 在菜单来创建 选项 , 点击该选项执行搜索代码  
    [MenuItem("Assets/CheckPrefabAnchor修改预制体锚点", false, 10)]
    static void CheckPrefabAnchor()
    {
        int num = 0;
        GameObject[] gameObjects = Selection.gameObjects;
        Debug.Log("本次遍历总数量" + gameObjects.Length);
        foreach (var item in gameObjects)
        {
            if (!item.name.StartsWith("UI_"))//过滤条件
            {
                Debug.Log(item.name + "不符合锚点判断条件");
                continue;
            }
            UIPanel[] uipanels = item.GetComponentsInChildren<UIPanel>(true);
 
            foreach (UIPanel uipanel in uipanels)
            {
                if (uipanel.isAnchored)
                {
                    uipanel.bottomAnchor.target = null;
                    uipanel.topAnchor.target = null;
                    uipanel.leftAnchor.target = null;
                    uipanel.rightAnchor.target = null;
                    Debug.Log(item.name + "/" + uipanel.name + "符合锚点祛除条件", item);
                    num += 1;
                }
                EditorUtility.SetDirty(uipanel);
            }
        }
        Debug.Log("符合要求数量" + num);
        AssetDatabase.SaveAssets();
    }

  

标签:遍历,Log,uipanel,Debug,item,Unity,预制,gameObjects,null
来源: https://www.cnblogs.com/guangzhiruijie/p/15825455.html