import os import unreal # NOTE 生成一个 Unreal Class 对象 @unreal.uclass() classPyBPFunctionLibrary(unreal.BlueprintFunctionLibrary): # NOTE 蓝图库分类设置为 Python Blueprint @unreal.ufunction(static=True,meta=dict(Category="Python Blueprint")) defTestFunction(): unreal.SystemLibrary.print_string(None,'Python Test Function Run',text_color=[255,255,255,255])
@unreal.ufunction(params=[str],ret=str,static=True,meta=dict(Category="Python Blueprint")) defTestReadFile(filepath): ifnot os.path.exists(filepath): return'' withopen(filepath,'r') as f: data = f.read() return data
我在 C 盘建了 txt ,写入了 read from text file 的数据 通过 Python 封装就可以读取到里面的数据了,省得用 C++ 去写。
import os import unreal # NOTE 生成一个 Unreal Class 对象 @unreal.uclass() classPyBPFunctionLibrary(unreal.BlueprintFunctionLibrary): # NOTE 蓝图库分类设置为 Python Blueprint @unreal.ufunction(static=True,meta=dict(Category="Python Blueprint")) defTestFunction(): unreal.SystemLibrary.print_string(None,'Python Test Function Run',text_color=[255,255,255,255])
@unreal.ufunction(params=[str],ret=str,static=True,meta=dict(Category="Python Blueprint")) defTestReadFile(filepath): ifnot os.path.exists(filepath): return'' withopen(filepath,'r') as f: data = f.read() return data @unreal.ufunction(params=[unreal.Array(str)],ret=str,static=True,meta=dict(Category="Python Blueprint")) defTestReadArrayFile(file_list): data = "" for filepath in file_list: ifnot os.path.exists(filepath): continue withopen(filepath,'r') as f: data += f.read() return data