2[
WorkbenchPluginAttribute(name:
"Playmode Entity Spawner", wbModules: {
"WorldEditor" }, shortcut:
"Ctrl+Alt+E", awesomeFontCode: 0xF055)]
3class SCR_EntitySpawnerPlugin : WorkbenchPlugin
8 [
Attribute(
desc:
"When enabled, previously spawned entity will be deleted upon creation of the new one.")]
9 protected bool m_bReplacePrevious;
11 [
Attribute(
desc:
"When enabled, the entity will be created on camera position and shot towards cursor.")]
12 protected bool m_bShootFromCamera;
14 [
Attribute(
desc:
"When enabled, this window won't be shown again when you activate the plugin.\nYou can still access it Plugins > Settings > Entity Spawner.")]
15 protected bool m_bDontShowThisAgain;
19 protected static const string DESCRIPTION =
"Spawn prefabs during play mode for easy debugging.\nWorks only when playing in viewport, not in full-screen.";
26 Print(
"Cannot spawn entity in editor mode, only in play mode.",
LogLevel.WARNING);
45 float cursorX, cursorY;
46 if (inputManager.IsContextActive(
"MenuContext"))
49 cursorX = inputManager.GetActionValue(
"MouseX");
50 cursorY = inputManager.GetActionValue(
"MouseY");
55 cursorX = workspace.GetWidth() * 0.5;
56 cursorY = workspace.GetHeight() * 0.5;
61 vector startPos = workspace.ProjScreenToWorld(workspace.DPIUnscale(cursorX), workspace.DPIUnscale(cursorY), outDir, world, -1);
65 trace.Start = startPos;
66 trace.End = startPos + outDir;
70 if (startPos[1] > world.GetOceanBaseHeight())
73 float traceDis = world.TraceMove(trace, null);
74 if (traceDis == 1 && !m_bShootFromCamera)
76 Print(
"Cannot spawn entity, cursor is not pointing at surface.",
LogLevel.WARNING);
81 if (!m_bDontShowThisAgain && !Workbench.ScriptDialog(
"Configure 'Playmode Entity Spawner' plugin", DESCRIPTION,
this))
89 Print(
"Cannot spawn entity, prefab not defined. Configure it in Plugins > Settings > Entity Spawner.",
LogLevel.WARNING);
95 Math3D.AnglesToMatrix(
Vector(outDir.VectorToAngles()[0], 0, 0), spawnParams.Transform);
96 if (m_bShootFromCamera)
97 spawnParams.Transform[3] = startPos;
99 spawnParams.Transform[3] = startPos + outDir * traceDis;
104 if (m_bShootFromCamera)
108 physics.SetVelocity(outDir * 0.1);
112 Print(
string.Format(
"Entity @\"%1\" spawned at %2",
m_sPrefab.GetPath(), spawnParams.Transform[3]),
LogLevel.NORMAL);
114 Print(
string.Format(
"Error when spawning entity @\"%1\" at %2",
m_sPrefab.GetPath(), spawnParams.Transform[3]),
LogLevel.WARNING);
120 Workbench.ScriptDialog(
"Configure 'Playmode Entity Spawner' plugin", DESCRIPTION,
this);
const int TRACE_LAYER_CAMERA
ArmaReforgerScripted GetGame()
enum EAITargetInfoCategory m_Entity
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)