记录开发小工具

///修改两个物体下子物体名称
  [MenuItem("GameObject/Gai name", false, 12)]
    public static void Copy()
    {
    
    
        Transform[] trans = Selection.transforms;
        if (trans.Length != 2)
            return;
        Transform target1 = trans[0];
        Transform target2 = trans[1];
        if (target1.childCount == target2.childCount /*&& target1.name == target2.name*/)
        {
    
    
            for (int i = 0; i < target1.childCount; i++)
            {
    
    
                target1.GetChild(i).name = target2.GetChild(i).name;
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            Debug.LogWarning("----------Finish-----------------");
        }
        else
        {
    
    
            Debug.LogWarning("----------长度不一样-----------------");
        }
    }

删除父物体下没有Mesh的物体

  [MenuItem("Tree/删除没有mesh的物体")]
    public static void DestroyNoMeshRendererInChild()
    {
    
    
        GameObject[] selections = Selection.gameObjects;

        for (int i = 0; i < selections.Length; i++)
        {
    
    
            DestroyNoComponentInChild<MeshRenderer>(selections[i].transform);
        }
    }

 public static void DestroyNoComponentInChild<T>(Transform trans, bool destroyThis = false)
    {
    
    
        if (trans.childCount > 0)
        {
    
    
            for (int i = trans.childCount - 1; i >= 0; i--)
            {
    
    
               
                DestroyNoComponentInChild<T>(trans.GetChild(i), true);
            }
        }

        if (destroyThis)
        {
    
    
            if (!trans.TryGetComponent<T>(out T component))
            {
    
    
              
                DestroyImmediate(trans.gameObject);
            }
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        Debug.LogWarning("----------Finish-------------");
    }

//获取所有挂载脚本的物体

 public void ResetHighlight()
    {
    
    
        BTn[] buttons =  FindObjectsOfType<BTn>();//获取场景内挂载Btn的所有
    }

猜你喜欢

转载自blog.csdn.net/weixin_42430280/article/details/133747036