UE4_Python_自動化導入素材腳本_音頻_圖片_FBX

1 新建項目,開啓插件
在這裏插入圖片描述
2 項目設置—>Python
在這裏插入圖片描述
3 資源加載腳本 AssetFunctions.py(目錄跟上圖的目錄一致)

導入FBX

import unreal

asset_path =  "E:/fireAxe.FBX"
asset_path2 =  "E:/fireAxe2.FBX"

def ImportMyAssets():
    asset_task = buildImportTask(asset_path,'/Game/Object')
    asset2_task = buildImportTask(asset_path2, '/Game/Object')
    executeImportTasks([asset_task,asset2_task])


# https://api.unrealengine.com/INT/PythonAPI/class/AssetToolsHelpers.html
def buildImportTask(filename,destination_path):
    task = unreal.AssetImportTask()
    task.set_editor_property('automated',True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', destination_path)
    task.set_editor_property('filename',filename)
    task.set_editor_property('replace_existing',False)
    task.set_editor_property('save',False)
    return task

# https://api.unrealengine.com/INT/PythonAPI/class/AssetTools.html
def executeImportTasks(tasks):
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)


在這裏插入圖片描述

4 依次執行

 import AssetFunctions as AF
 AF.ImportMyAssets()

5 然後,素材自動導入到項目中
在這裏插入圖片描述

導入音頻和圖片

import unreal

texture_tga = "E:/Test/Img.TGA"
sound_wav = "E:/Test/bgm.WAV"


def importMyAssets():
    sound_task = buildImportTask(sound_wav, '/Game/Sounds')
    texture_task = buildImportTask(texture_tga, '/Game/Textures')
    executeImportTasks([sound_task, texture_task])


def buildImportTask(filename, destination_path):
    task = unreal.AssetImportTask()
    task.set_editor_property('automated', True)
    task.set_editor_property('destination_name', '')
    task.set_editor_property('destination_path', destination_path)
    task.set_editor_property('filename', filename)
    task.set_editor_property('replace_existing', True)
    task.set_editor_property('save', True)
    return task


def executeImportTasks(tasks):
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)






在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章