# coding: utf-8import unreal
defcast(object_to_cast, object_class):try:return object_class.cast(object_to_cast)except:returnNonedefgetAllActors(use_selection=False, actor_class=None, actor_tag=None):if use_selection:
selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()# 从被选中的Actor中过滤出指定类型的Actorif actor_class:
class_actors =[x for x in selected_actors if cast(x, actor_class)]# 再过滤出含指定Tag的if actor_tag:
tag_actors =[
x for x in class_actors if x.actor_has_tag(actor_tag)]return tag_actors
elif actor_class:
actors = unreal.GameplayStatics.get_all_actors_of_class(
unreal.EditorLevelLibrary.get_editor_world(),
actor_class
)# 通过标签过滤if actor_tag:return[x for x in actors if x.actor_has_tag(actor_tag)]elif actor_tag:return unreal.GameplayStatics.get_all_actors_with_tag(
unreal.EditorLevelLibrary.get_editor_world(),
actor_tag
)else:return unreal.GameplayStatics.get_all_actors_of_class(
unreal.EditorLevelLibrary.get_editor_world(),
unreal.Actor
)