112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
import unreal
|
|
|
|
|
|
MAP_PATH = "/Game/Maps/L_LuaDemo"
|
|
|
|
|
|
def main():
|
|
level_sub = unreal.get_editor_subsystem(unreal.LevelEditorSubsystem)
|
|
actor_sub = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)
|
|
|
|
unreal.log(f"[CreateDemoMap] Creating level: {MAP_PATH}")
|
|
ok = level_sub.new_level(MAP_PATH)
|
|
if not ok:
|
|
raise RuntimeError(f"Failed to create new level at {MAP_PATH}")
|
|
|
|
# 1. Floor plane with grid material
|
|
floor = actor_sub.spawn_actor_from_class(
|
|
unreal.StaticMeshActor,
|
|
unreal.Vector(0.0, 0.0, 0.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
floor.set_actor_label("DemoFloor")
|
|
floor.set_actor_scale3d(unreal.Vector(25.0, 25.0, 1.0))
|
|
plane_mesh = unreal.EditorAssetLibrary.load_asset("/Engine/BasicShapes/Plane")
|
|
if plane_mesh:
|
|
floor.static_mesh_component.set_static_mesh(plane_mesh)
|
|
grid_mat = unreal.EditorAssetLibrary.load_asset("/Engine/EngineMaterials/WorldGridMaterial")
|
|
if grid_mat:
|
|
floor.static_mesh_component.set_material(0, grid_mat)
|
|
|
|
# 2. Directional sun light
|
|
sun = actor_sub.spawn_actor_from_class(
|
|
unreal.DirectionalLight,
|
|
unreal.Vector(0.0, 0.0, 500.0),
|
|
unreal.Rotator(-45.0, -35.0, 0.0),
|
|
)
|
|
sun.set_actor_label("DemoSunLight")
|
|
sun_comp = sun.light_component
|
|
sun_comp.set_mobility(unreal.ComponentMobility.MOVABLE)
|
|
sun_comp.set_intensity(4.0)
|
|
try:
|
|
sun_comp.set_editor_property("atmosphere_sun_light", True)
|
|
except Exception:
|
|
pass
|
|
|
|
# 3. SkyLight
|
|
sky_light = actor_sub.spawn_actor_from_class(
|
|
unreal.SkyLight,
|
|
unreal.Vector(0.0, 0.0, 600.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
sky_light.set_actor_label("DemoSkyLight")
|
|
sky_comp = sky_light.light_component
|
|
sky_comp.set_mobility(unreal.ComponentMobility.MOVABLE)
|
|
try:
|
|
sky_comp.set_editor_property("real_time_capture", True)
|
|
except Exception:
|
|
pass
|
|
|
|
# 4. SkyAtmosphere & ExponentialHeightFog
|
|
sky_atmo = actor_sub.spawn_actor_from_class(
|
|
unreal.SkyAtmosphere,
|
|
unreal.Vector(0.0, 0.0, 0.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
sky_atmo.set_actor_label("DemoSkyAtmosphere")
|
|
|
|
fog = actor_sub.spawn_actor_from_class(
|
|
unreal.ExponentialHeightFog,
|
|
unreal.Vector(0.0, 0.0, 0.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
fog.set_actor_label("DemoHeightFog")
|
|
|
|
# 5. PlayerStart facing +X toward LuaDemoActor
|
|
player_start = actor_sub.spawn_actor_from_class(
|
|
unreal.PlayerStart,
|
|
unreal.Vector(-450.0, 0.0, 100.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
player_start.set_actor_label("DemoPlayerStart")
|
|
|
|
# 6. LuaDemoActor driven by Script/lua/Game/LuaDemoActor.lua
|
|
demo_actor_class = unreal.load_class(None, "/Script/UnrealLuaDemo.LuaDemoActor")
|
|
if demo_actor_class is None:
|
|
raise RuntimeError("Could not load /Script/UnrealLuaDemo.LuaDemoActor")
|
|
|
|
demo_actor = actor_sub.spawn_actor_from_class(
|
|
demo_actor_class,
|
|
unreal.Vector(0.0, 0.0, 140.0),
|
|
unreal.Rotator(0.0, 0.0, 0.0),
|
|
)
|
|
demo_actor.set_actor_label("LuaDemoActor")
|
|
|
|
# 7. Set level GameMode override to ALuaGameModeBase
|
|
world = unreal.get_editor_subsystem(unreal.UnrealEditorSubsystem).get_editor_world()
|
|
if world:
|
|
ws = world.get_world_settings()
|
|
gm_class = unreal.load_class(None, "/Script/UnrealLuaDemo.LuaGameModeBase")
|
|
if ws and gm_class:
|
|
ws.set_editor_property("default_game_mode", gm_class)
|
|
|
|
saved = level_sub.save_current_level()
|
|
if not saved:
|
|
raise RuntimeError(f"Failed to save level {MAP_PATH}")
|
|
|
|
unreal.log(f"[CreateDemoMap] Successfully created and saved {MAP_PATH}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|