-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUEUtil.py
53 lines (40 loc) · 1.45 KB
/
UEUtil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import inspect
def get_class_by_path(path):
import unreal_engine as ue
try:
return ue.find_class(path)
except:
try:
return ue.find_object(path)
except:
return None
import unreal_engine as ue
STRUCT_MAP = {
ue.FVector2D: get_class_by_path("Vector2D"),
ue.FLinearColor: get_class_by_path("LinearColor")
}
def create_struct_from_dict(struct, props):
struct = STRUCT_MAP.get(struct, struct)
kwargs = {}
print(struct)
structKeys = struct.properties()
structDict = struct.as_dict()
for key in structKeys:
if key not in props: continue
valueTy = STRUCT_MAP.get(type(structDict[key]), type(structDict[key]))
if valueTy == ue.UScriptStruct:
kwargs[key] = create_struct_from_dict(valueTy.get_struct(), props[key])
print(f"STRUCT [{key}]")
return struct(**kwargs)
KEYS_TO_IGNORE = ["ColorTag", "Font"]
def set_properties_by_json(obj, props, to_ignore = []):
import unreal_engine as ue
for key in obj.properties():
if key not in props or key in to_ignore or key in KEYS_TO_IGNORE: continue
jsonValue = props[key]
prevValue = getattr(obj, key)
prevValueType = type(prevValue)
if prevValueType == ue.UScriptStruct:
print(f"{key}")
newValue = create_struct_from_dict(prevValue.get_struct(), jsonValue)
setattr(obj, key, newValue)