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

  

上一篇:Unity 导入本地包失败


下一篇:Unity手游性能蓝皮书