15[WorkbenchToolAttribute(
"Batch prefabs operations tool",
"### Creating new prefabs ###\nTo create new prefabs you need to fill 'Prefab Config', 'Path To Save' and\n'Models To Process'\n\nIf Generate Names is checked, there is no need to fill in New Names array\nUse Prefab Config to store additional settings in new prefab.\n\nOnce everything is set, click on 'Create' button to create new prefabs\n\n### Modifying existing prefabs ###\nTo modify prefabs you need to have at least one prefab in\n'Prefabs To Process' array selected & valid config selected in\n'Prefabs Config'\n\nWith those 2 parameters set, click on 'Modify' button to modify selected prefabs",
"2", awesomeFontCode: 0xF085)]
16class SCR_BatchPrefabsOperationsTool : WorldEditorTool
18 [
Attribute(
"1", UIWidgets.ComboBox,
"File system where new prefabs will be created",
"", SCR_ParamEnumArray.FromAddons(),
"General")]
19 protected int m_iAddonToUse;
21 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Choose a base class of your prefabs.",
"et", null,
"Create")]
22 protected ResourceName m_sBaseClass;
24 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Choose a path to save your prefabs.",
"unregFolders", null,
"Create")]
25 protected ResourceName m_sPathToSave;
27 [
Attribute(
"", UIWidgets.ResourceAssignArray,
"Choose XOB files to process.",
"xob", null,
"Create")]
28 protected ref array<ResourceName> m_aModelsToProcess;
30 [
Attribute(
"", UIWidgets.EditBox,
"Choose new names of your prefabs.",
"et", null,
"Create")]
31 protected ref array<string> m_aNewNames;
33 [
Attribute(
"", UIWidgets.CheckBox,
"Generate names from source files.",
"", null,
"Create")]
34 protected bool m_bGenerateNames;
36 [
Attribute(
"", UIWidgets.ResourceAssignArray,
"Choose prefabs to process.",
"et", null,
"Modify")]
37 protected ref array<ResourceName> m_aPrefabsToProcess;
39 [
Attribute(defvalue:
"",
desc:
"All prefabs in this directory will be processed. Replaces Prefabs To Process array",
params:
"unregFolders",
category:
"Modify")]
40 protected ResourceName m_sDirectoryToProcess;
42 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Pick a config with template configuration.",
"conf", null,
"Modify")]
43 protected ResourceName m_sPrefabConfig;
51 protected void ProcessComponents(IEntitySource entSrc, SCR_BatchPrefabTemplates prefabGeneratorConfig)
53 IEntityComponentSource component;
54 array<ref ContainerIdPathEntry> containerPath = {};
55 foreach (SCR_BatchPrefabTemplatesData currentComp : prefabGeneratorConfig.m_ComponentsArray)
57 int action = currentComp.m_ComponentAction;
60 component = SCR_BaseContainerTools.FindComponentSource(entSrc, currentComp.m_ComponentName);
68 component = m_API.CreateComponent(entSrc, currentComp.m_ComponentName);
74 bool success = m_API.DeleteComponent(entSrc, component);
76 Print(
"Unable to delete " + currentComp.m_ComponentName +
" from " + entSrc +
". Component is probably inherited",
LogLevel.WARNING);
81 containerPath.Clear();
83 ProcessAttributes(entSrc, component, containerPath, currentComp.m_ComponentAttributesArray);
96 protected void ProcessAttributes(IEntitySource entSrc, IEntitySource entSrcAttribute, array<ref ContainerIdPathEntry> containerPath, array<ref SCR_BatchPrefabTemplatesAttributes> TemplateData)
99 foreach (
int currentAtributeIndex, SCR_BatchPrefabTemplatesAttributes currentAttribute : TemplateData)
101 string attributeName = currentAttribute.m_AttributeName;
102 string attributeValue = currentAttribute.m_AttributeValue;
103 int attributeOperation = currentAttribute.m_AttributeOperation;
104 if (attributeOperation == SCR_EBatchPrefabOperationFlag.MATH)
106 float m_fCurrentValue;
107 entSrcAttribute.Get(attributeName, m_fCurrentValue);
110 string attributeValueShort = attributeValue;
111 attributeValueShort.Replace(
"*",
"");
112 attributeValueShort.Replace(
"/",
"");
113 float operand = attributeValueShort.ToFloat();
114 if (attributeValue.StartsWith(
"+") || attributeValue.StartsWith(
"-"))
115 m_fCurrentValue = m_fCurrentValue + operand;
117 if (attributeValue.StartsWith(
"/"))
118 m_fCurrentValue = m_fCurrentValue / operand;
120 if (attributeValue.StartsWith(
"*"))
121 m_fCurrentValue = m_fCurrentValue * operand;
123 attributeValue = m_fCurrentValue.ToString();
126 if (attributeOperation == SCR_EBatchPrefabOperationFlag.ENUM)
129 entSrcAttribute.Get(attributeName, m_iCurrentValue);
130 if (attributeValue.StartsWith(
"+"))
131 m_iCurrentValue = m_iCurrentValue | attributeValue.ToInt();
133 if (attributeValue.StartsWith(
"-"))
134 m_iCurrentValue = m_iCurrentValue &~ attributeValue.ToInt();
136 attributeValue = m_iCurrentValue.ToString();
139 m_API.SetVariableValue(entSrc, containerPath, attributeName, attributeValue);
157 if (!m_aModelsToProcess)
159 Print(
"Models To Process is empty. Please fill it with at least one model",
LogLevel.ERROR);
165 Print(
"Path To Save is empty. Please select valid save location",
LogLevel.ERROR);
171 Print(
"Base Class is empty. Please select valid base prefab for your window",
LogLevel.ERROR);
175 if (!m_bGenerateNames && !m_aNewNames)
177 Print(
"New Names and Generate Names are empty. Please either check Generate Names or type in new names",
LogLevel.ERROR);
182 if (m_sPathToSave.Contains(
"{") && m_sPathToSave.Contains(
"}"))
184 int guidBracket = m_sPathToSave.IndexOf(
"}");
185 m_sPathToSave = m_sPathToSave.Substring(guidBracket+ 1, m_sPathToSave.Length() - guidBracket - 1);
189 string addon = SCR_AddonTool.ToFileSystem(SCR_AddonTool.GetAddonID(m_iAddonToUse));
193 Workbench.GetAbsolutePath(addon + m_sPathToSave, absPath);
197 IEntitySource entitySource;
198 array<ref ContainerIdPathEntry> containerPath;
200 SCR_BatchPrefabTemplates prefabGeneratorConfig;
201 int layerId = m_API.GetCurrentEntityLayerId();
202 foreach (
int currentIndex, ResourceName currentElement : m_aModelsToProcess)
205 string modelName = currentElement;
207 Print(
"Processing " +
string.Format(
"@\"%1\"", currentElement.GetPath()),
LogLevel.NORMAL);
209 m_API.BeginEntityAction(
"Processing " + modelName);
212 entitySource = m_API.CreateEntity(m_sBaseClass,
string.Empty, layerId, null, vector.Zero, vector.Zero);
217 if (!(SCR_BaseContainerTools.FindComponentSource(entitySource,
"MeshObject")))
218 m_API.CreateComponent(entitySource,
"MeshObject");
220 containerPath.Clear();
222 m_API.SetVariableValue(entitySource, containerPath,
"Object", modelName);
226 holder = BaseContainerTools.LoadContainer(m_sPrefabConfig);
231 prefabGeneratorConfig = SCR_BatchPrefabTemplates.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
232 ProcessAttributes(entitySource, entitySource, containerPath, prefabGeneratorConfig.m_AttributesArray);
233 ProcessComponents(entitySource, prefabGeneratorConfig);
237 if (m_bGenerateNames)
239 array<string> tempArray = {};
240 modelName.Split(
"/", tempArray,
false);
241 tempName = tempArray[tempArray.Count()-1];
242 tempName.Replace(
".xob",
"");
246 tempName = m_aNewNames[currentIndex];
250 bool fileCreated = m_API.CreateEntityTemplate(entitySource, FilePath.Concat(absPath, tempName +
".et"));
253 m_API.DeleteEntity(entitySource);
254 m_API.EndEntityAction();
263 protected void ExecuteModify()
266 if (!m_aPrefabsToProcess && !m_sDirectoryToProcess)
268 Print(
"m_aPrefabsToProcess & m_sDirectoryToProcess is empty. Please fill with at least one prefab",
LogLevel.ERROR);
272 if (!m_sPrefabConfig)
274 Print(
"Missing config file for batch prefab operation!",
LogLevel.ERROR);
278 if (!m_sDirectoryToProcess.IsEmpty())
280 string addon = SCR_AddonTool.ToFileSystem(SCR_AddonTool.GetAddonID(m_iAddonToUse));
283 SearchResourcesFilter filter =
new SearchResourcesFilter();
284 filter.fileExtensions = {
"et" };
285 filter.rootPath = addon + m_sDirectoryToProcess.GetPath();
286 ResourceDatabase.SearchResources(filter, m_aPrefabsToProcess.Insert);
288 Print(
"Processing " + m_aPrefabsToProcess.Count(),
LogLevel.NORMAL);
291 if (m_aPrefabsToProcess.IsEmpty())
293 Print(
"There are no valid prefabs in selected folder",
LogLevel.ERROR);
298 IEntitySource entitySource;
299 IEntitySource prefab;
300 array<ref ContainerIdPathEntry> containerPath;
302 SCR_BatchPrefabTemplates prefabGeneratorConfig;
303 int layerId = m_API.GetCurrentEntityLayerId();
304 foreach (
int currentIndex, ResourceName currentElement : m_aPrefabsToProcess)
307 string modelName = currentElement;
309 Print(
"Processing " +
string.Format(
"@\"%1\"", currentElement.GetPath()),
LogLevel.NORMAL);
313 entitySource = m_API.CreateEntity(currentElement,
string.Empty, layerId, null, vector.Zero, vector.Zero);
315 prefab = entitySource.GetAncestor();
320 holder = BaseContainerTools.LoadContainer(m_sPrefabConfig);
325 prefabGeneratorConfig = SCR_BatchPrefabTemplates.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
326 ProcessAttributes(prefab, prefab, containerPath, prefabGeneratorConfig.m_AttributesArray);
327 ProcessComponents(prefab, prefabGeneratorConfig);
331 m_API.DeleteEntity(entitySource);
335 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
343 protected string m_aParamString[4];
347 void SCR_BatchPrefabTitle(
string paramString1,
string paramString2 =
"",
string paramString3 =
"",
string paramString4 =
"")
349 m_aParamString[0] = paramString1;
350 m_aParamString[1] = paramString2;
351 m_aParamString[2] = paramString3;
352 m_aParamString[3] = paramString4;
360 for (
int i = 1; i <= 4; i++)
363 prop = m_aParamString[i - 1];
364 if (!source.Get(prop, temp))
367 title = title + temp;
370 return title !=
string.Empty;
375enum SCR_EBatchPrefabOperationFlag
382enum SCR_EBatchPrefabOperationComponentFlag
390class SCR_BatchPrefabTemplates
392 [
Attribute(
desc:
"Array of attributes which be aplied to prefab (not to its components)")]
393 ref array<ref SCR_BatchPrefabTemplatesAttributes> m_AttributesArray;
395 [
Attribute(
desc:
"Array of components which will be added or modified")]
396 ref array<ref SCR_BatchPrefabTemplatesData> m_ComponentsArray;
399[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"Component: ",
"m_ComponentName")]
400class SCR_BatchPrefabTemplatesData
403 string m_ComponentName;
405 [
Attribute(defvalue:
"1", UIWidgets.ComboBox,
desc:
"Create new component if its missing prefab", enumType: SCR_EBatchPrefabOperationComponentFlag)]
406 SCR_EBatchPrefabOperationComponentFlag m_ComponentAction;
408 [
Attribute(
desc:
"Array of attributes which will be modified inside component belonging to prefab. If component is not present, new one will be created")]
409 ref array<ref SCR_BatchPrefabTemplatesAttributes> m_ComponentAttributesArray;
412[
BaseContainerProps(configRoot:
false), SCR_BatchPrefabTitle(
"m_AttributeName",
": ",
"m_AttributeValue")]
413class SCR_BatchPrefabTemplatesAttributes
416 string m_AttributeName;
418 [
Attribute(
desc:
"Value which will be stored in prefab. Simple math (adding, multiplying & dividing) & bitwise operations are allowed (use + to add and - to remove flag)")]
419 string m_AttributeValue;
421 [
Attribute(
"1", UIWidgets.ComboBox,
category:
"",
desc:
"Specifies type of operation that is performed.", enumType: SCR_EBatchPrefabOperationFlag)]
422 SCR_EBatchPrefabOperationFlag m_AttributeOperation;
425 ref array<ref SCR_BatchPrefabTemplatesAttributes> m_SubAttributesArray;
void ContainerIdPathEntry(string propertyName, int index=-1)
bool Execute(notnull SCR_AIGroupUtilityComponent groupUtility, vector targetPosition, SCR_AIActivitySmokeCoverFeatureProperties smokeCoverProperties, notnull array< AIAgent > avoidAgents, notnull array< AIAgent > excludeAgents, int maxPositionCount=1, SCR_AIActivityBase contextActivity=null)
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
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
@ DELETE
Further load on the instance is aborted and is deleted immediately.
class SCR_BaseManualCameraComponent _WB_GetCustomTitle(BaseContainer source, out string title)