tzbm123456 发表于 2023-1-15 16:22:54

<UE4: Python编写编辑器插件>

<UE4: Python编写编辑器插件>
2023年1月15日

tzbm123456 发表于 2023-1-15 16:28:42

本帖最后由 tzbm123456 于 2023-1-21 23:35 编辑

1、设置添加Python插件:

2、设置启动执行Python文件,自动索检目录

3、手动装载和执行Python文件

import AddMenu//装载AddMenu.py文件
AddMenu.add_menu_00()//执行AddMenu.py文件中的add_menu_00()函数
4、Python文件案例

5、特别说明:
(1)init_unreal.py
      文件如果编辑器在任何已配置其使用的路径中检测到名称为`init_unreal.py`的脚本文件,编辑器会立即运行该脚本。
(2)项目生成不能用Game模式


(3)建议Archtecture模式,空文件28.6M

(4)创建Asset_02\Intermediate\PythonStub目录须勾选下列选项




(5)重载的方法:
   >如果你安装的 Python 版本 <3.4 则需要使用如下代码
      reload(AddMenu)
      AddMenu.func01()
   >如果你安装的 Python 版本 >= 3.4 则需要使用如下代码
      import importlib
      importlib.reload(AddMenu)
    AddMenu.func01()

tzbm123456 发表于 2023-1-16 00:01:11

本帖最后由 tzbm123456 于 2023-1-23 21:15 编辑

1、网址:https://blog.csdn.net/qq_43471727/article/details/117778326
2、UE4配置网址:https://zhuanlan.zhihu.com/p/416619202

3、VSC配置网址:https://blog.csdn.net/woysihsb/article/details/122242385


4、视频1网址:https://www.bilibili.com/video/BV1PE411d7z8/?p=1&vd_source=9f0356a99281dd90abd48bc2d2760dc6

5、视频2网址:https://www.bilibili.com/video/BV1y7411N7qL/?spm_id_from=333.788











tzbm123456 发表于 2023-1-23 21:12:01

本帖最后由 tzbm123456 于 2023-1-29 17:05 编辑

1、将python文件,加密成UE4可用的pyd文件
网址:https://blog.csdn.net/weixin_43912248/article/details/122424873
2、UE4 python scrpit——导入资产
网址:https://blog.csdn.net/weixin_43912248/article/details/121794493
3、UE4 Python批量修改材质实例的父材质
网址:https://zhuanlan.zhihu.com/p/563666183
4、UE4 Python脚本编辑器扩展
网址:https://zhuanlan.zhihu.com/p/371234422
5、UE4 Python进行批量资产性能检查
网址:https://zhuanlan.zhihu.com/p/570345152
6、UE4 Python批量重命名Unreal Assets
网址:https://blog.csdn.net/qq_40610977/article/details/114365157
7、Python in UE4 -- 4.26API翻译
https://zhuanlan.zhihu.com/p/463972229

tzbm123456 发表于 2023-1-28 00:14:16

本帖最后由 tzbm123456 于 2023-1-29 13:59 编辑

1、资源是否存在:
aa='/Game/Mesh/MyMesh01'
print(unrealm.EditorAssetLibrary.does_asset_exist(aa))
2、目录是否存在:
tmpDir='/Game/Mesh'
print(unrealm.EditorAssetLibrary.does_directory_exist(tmpDir))
3、选择资源操作集
#1、 选择给定名称静态网格资源
    asset=['/Game/Mesh/MyMesh'];
    tmpEnt=unreal.EditorAssetLibrary.sync_browser_to_objects(asset);
    print(tmpEnt);

#2、获取已选择的资源数组
    editor_util=unreal.EditorUtilityLibrary();
    selected_assets=editor_util.get_selected_assets();

#3、获取资源数组第一个元素的类型名称tmpAssetTypeName
    tmpAssetTypeName=selected_assets.get_class().get_name();
    print(tmpAssetTypeName);
    # 打印出:StaticMesh

#4、获取静态网格资源的材质数组tmpMatArr
    tmpMatArr=selected_assets.static_materials;
    print(tmpMatArr);
    # 打印出:[{material_interface: Material'"/Game/Material/MyMat_01.MyMat_01"', material_slot_name: "BasicShapeMaterial", uv_channel_data: {}}]

#5、获取静态网格材质数量tmpMatNum
    tmpStaicMesh=selected_assets;
    tmpMeshLib=unreal.EditorStaticMeshLibrary();
    tmpMatNum=tmpMeshLib.get_number_materials(tmpStaicMesh);
    print(tmpMatNum);
    # 打印出:1

#6、获取材质数组tmpMatArr中第一个材质的类型名称tmpMatTypeName
    tmpMatTypeName=tmpMatArr.material_interface.get_class().get_name();
    print(tmpMatTypeName);
    # 打印出:Material 或 MaterialInstanceConstant

#7、创建名称assetname
    asset_type="Type";
    asset_name="assetName";
    index=0;
    asset_variation="VA";
    assetname = ("{}_{}_{}_{}").format(asset_type,asset_name,index,asset_variation)

#8、获取材质中的贴图数组tmpTextureArr
    tmpMatLib = unreal.MaterialEditingLibrary();
    tmpMat = tmpMatArr.material_interface;
    tex_set = set();
    tmpMatType = tmpMat.get_class().get_name()
if tmpMatType == "Material":      tex_group =tmpMatLib.get_used_textures(tmpMat)
      for item in tex_group:
            tex_set.add(item)
            tmpStr=item.get_full_name();
            #tmpStr为'Texture2D /Game/Material/biaozhu.biaozhu'字符
            tmpArr=tmpStr.split(" ");
            tmpPath=tmpArr;
            print("Texture路径:"+tmpPath);
if tmpMatType == 'MaterialInstanceConstant':      # 获取材质实例tmpMat的父项材质的贴图组tex_group
      tex_group =tmpMatLib.get_used_textures(tmpMat.parent)
      for item in tex_group:
            tmpStr=item.get_full_name();
            #tmpStr为'Texture2D /Game/Material/biaozhu.biaozhu'字符
            tmpArr=tmpStr.split(" ");
            tmpPath=tmpArr;
            print("Texture路径:"+tmpPath);

    # if tmpMatType == 'MaterialInstanceConstant':
    #   tex_group = tmpMat.get_editor_property('texture_parameter_values')
    #   for item in tex_group:
    #         tex_set.add(item.parameter_value)
    #         print(item.parameter_value.get_name())
    print('相关贴图数目为:' + str(len(tex_set)))







tzbm123456 发表于 2023-1-29 04:12:06

本帖最后由 tzbm123456 于 2023-2-5 02:24 编辑

<>查阅网格资源的材质和贴图
一、思维流程
1、手动选择资源;
2、获取已选择资源集——EditorUtilityLibrary.get_selected_assets();
3、提取选择集中StaicMesh——get_class().get_name();
4、获取StaicMesh中的材质集Materials——static_materials;
5、遍历材质集中的材质,获取材质名称、路径和关联的纹理(名称、路径)
(1)获取材质名称、路径get_full_name()——unreal._ObjectBase类中的功能函数;
(2)创建材质编辑器MaterialEditingLibrary();
(3)通过材质编辑器获取其贴图集get_uesd_texture(tmpMat);
(4)遍历贴图集,获取其名称、路径get_full_name()——unreal._ObjectBase类中的功能函数;

tzbm123456 发表于 2023-2-5 02:24:43

本帖最后由 tzbm123456 于 2023-2-5 02:32 编辑

一、工作步骤2023.02.05
1、创建资源项目,例如:TreeAsset;
2、找到导入资源文件,将其资源迁入至资源项目中,选择TreeAsset目录中的Content目录;
3、选择新增目录,并将显示目录勾选取消;

4、将所有资源拖入指定目录,例如:'Asset/02/00131/'目录中;
5、选择'Asset/02/00131/'目录中任意文件,执行'扩展功能'菜单中'更新名称'



页: [1]
查看完整版本: <UE4: Python编写编辑器插件>