3 name:
"Entities Setup",
5 description:
"Set up world's Entities",
7 wbModules: {
"WorldEditor" },
8 awesomeFontCode: 0xF0AC)]
9class SCR_WorldSetupPlugin_Entities : SCR_WorldSetupPluginBasePlugin
11 [
Attribute(defvalue: DEFAULT_CONFIG,
params:
"conf class=SCR_WorldSetupPluginConfig")]
14 [
Attribute(defvalue:
"0",
desc:
"Create Prefab's child from the provided one in the selected addon and use it instead of using the provided Prefab directly")]
15 protected bool m_bCopyPrefabsToAddon;
18 protected int m_iAddon;
21 protected ref SCR_WorldSetupPluginConfig m_Config;
22 protected ref set<string> m_ClassNames =
new set<string>();
23 protected ref set<string> m_Prefabs =
new set<string>();
25 protected static const ResourceName DEFAULT_CONFIG =
"{1DD914C62E44CDEB}Configs/Workbench/WorldEditor/WorldSetupPlugin/0_MinimalWorldSetup.conf";
28 protected override void Run()
33 if (!Workbench.ScriptDialog(
34 "World Setup (required entities creation)",
35 "This plugin helps generating default entities to setup a freshly created world properly.\n" +
36 "Pick a config of your choice (keep the default one if it is good enough).\n\n" +
37 "Entities will be created in the currently selected layer.",
52 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
60 BaseWorld baseWorld = worldEditorAPI.GetWorld();
68 worldEditorAPI.GetWorldPath(worldPath);
69 if (worldPath.IsEmpty())
71 Print(
"No world is currently loaded or the world has not yet been saved to storage",
LogLevel.WARNING);
79 protected bool LoadConfig()
81 if (m_sConfig.IsEmpty())
82 m_sConfig = DEFAULT_CONFIG;
85 if (!resource.IsValid())
91 m_Config =
new SCR_WorldSetupPluginConfig();
92 BaseContainerTools.WriteToInstance(m_Config, resource.GetResource().ToBaseContainer());
98 protected void CreateEntities()
100 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
106 for (
int i, count = worldEditorAPI.GetEditorEntityCount(); i < count; i++)
108 entitySource = worldEditorAPI.GetEditorEntity(i);
109 if (!worldEntitySource && entitySource.GetClassName().ToType() == GenericWorldEntity)
110 worldEntitySource = entitySource;
114 m_ClassNames.Insert(entitySource.GetClassName());
116 ancestor = entitySource.GetAncestor();
118 m_Prefabs.Insert(ancestor.GetResourceName());
122 bool manageEditAction = SCR_WorldEditorToolHelper.BeginEntityAction();
123 foreach (SCR_WorldSetupPluginConfig_Entity entry : m_Config.m_aEntities)
125 CreateEntityFromEntry(entry);
127 SCR_WorldEditorToolHelper.EndEntityAction(manageEditAction);
133 protected IEntitySource CreateEntityFromEntry(notnull SCR_WorldSetupPluginConfig_Entity entry)
135 if (entry.m_sPrefab.IsEmpty())
137 Print(
"An entry does not have class name or Prefab",
LogLevel.WARNING);
141 if (entry.m_bMustBeUniqueByPrefab && m_Prefabs.Contains(entry.m_sPrefab))
143 Print(
"Entry skipped as another Entity originates from the same Prefab " + entry.m_sPrefab,
LogLevel.WARNING);
148 if (!resource.IsValid())
150 Print(
"Entry has an invalid Prefab " + entry.m_sPrefab,
LogLevel.WARNING);
154 string className = resource.GetResource().ToBaseContainer().GetClassName();
156 if (entry.m_bMustBeUniqueByClassName && m_ClassNames.Contains(className))
158 Print(
"Entry skipped as a " + className +
" entity is already present",
LogLevel.WARNING);
165 if (m_bCopyPrefabsToAddon)
166 prefab = CreatePrefabChildInAddon(prefab, m_iAddon);
168 if (prefab.IsEmpty())
170 Print(
"Child Prefab could not be created ",
LogLevel.WARNING);
174 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
175 IEntitySource entitySource = worldEditorAPI.CreateEntity(prefab,
string.Empty, worldEditorAPI.GetCurrentEntityLayerId(), null, entry.m_vPosition, entry.m_vAngles);
178 Print(
"Entity failed to be created by World Editor API " + prefab,
LogLevel.WARNING);
182 if (entry.m_aAdditionalValues && !entry.m_aAdditionalValues.IsEmpty())
184 foreach (SCR_WorldSetupPluginConfig_EntitySourceKeyValue kvp : entry.m_aAdditionalValues)
186 if (!worldEditorAPI.SetVariableValue(entitySource, null, kvp.m_sKey, kvp.m_sValue))
187 PrintFormat(
"Cannot set variable value \"%1\" (value: %2)", kvp.m_sKey, kvp.m_sValue, level:
LogLevel.WARNING);
191 m_ClassNames.Insert(className);
192 m_Prefabs.Insert(prefab);
201 m_ClassNames.Clear();
207 protected bool ButtonRun()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void Cleanup()
Cleanup component.
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
Object holding reference to resource. In destructor release the resource.
static ParamEnumArray FromAddons(int titleFormat=2, int hideCoreModules=0)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute