3class SCR_EditableEntityMaintenancePlugin : WorkbenchPlugin
6 protected string m_sAddon;
14 protected static const ref array<string> UNIQUE_COMPONENTS = {
"MeshObject",
"RigidBody",
"RplComponent",
"Hierarchy",
"SCR_DestructionMultiPhaseComponent" };
19 string uniqueComponentClasses;
20 foreach (
int i,
string uniqueComponent : UNIQUE_COMPONENTS)
23 uniqueComponentClasses +=
"\n";
24 uniqueComponentClasses +=
" - " + uniqueComponent;
27 if (!Workbench.ScriptDialog(
"Maintain Editable Entities",
string.Format(
"Go through all entity prefabs in the folder and remove duplicate components of following types:\n%1", uniqueComponentClasses),
this))
30 array<ResourceName> resources = {};
32 SearchResourcesFilter filter =
new SearchResourcesFilter();
33 filter.fileExtensions = {
"et" };
34 filter.rootPath =
path;
35 ResourceDatabase.SearchResources(filter, resources.Insert);
39 IEntitySource entitySource, ancestorSource;
40 BaseContainerList componentsArray, ancestorComponentsArray;
41 array<BaseContainer> ancestorComponents = {};
42 array<BaseContainer> componentsToRemove = {};
43 array<string> componentClasses = {};
44 string componentClass;
45 IEntityComponentSource component;
46 foreach (ResourceName prefab : resources)
48 resource = Resource.Load(prefab);
49 if (!resource.IsValid())
51 PrintFormat(
"Cannot load %1 | %2:%3", prefab + FilePath.StripPath(__FILE__), __LINE__, level:
LogLevel.WARNING);
55 entitySource = resource.GetResource().ToEntitySource();
57 componentsToRemove.Clear();
58 componentClasses.Clear();
61 ancestorSource = entitySource.GetAncestor();
64 ancestorComponentsArray = ancestorSource.GetObjectArray(
"components");
65 for (
int i = 0, count = ancestorComponentsArray.Count(); i < count; i++)
67 ancestorComponents.Insert(ancestorComponentsArray.Get(i));
72 componentsArray = entitySource.SetObjectArray(
"components");
73 int componentCount = componentsArray.Count();
74 for (
int i = 0; i < componentCount; i++)
76 component = componentsArray.Get(i);
77 componentClass = component.GetClassName();
79 if (componentClasses.Contains(componentClass) && UNIQUE_COMPONENTS.Contains(componentClass) && !ancestorComponents.Contains(component))
82 componentsToRemove.Insert(component);
87 componentClasses.Insert(componentClass);
91 if (!componentsToRemove.IsEmpty())
93 foreach (BaseContainer componentToRemove : componentsToRemove)
95 Print(
string.Format(
"@\"%1\": Removed duplicate component %2", entitySource.GetResourceName().GetPath(), componentToRemove.GetClassName()),
LogLevel.WARNING);
96 componentsArray.Remove(componentToRemove);
99 BaseContainerTools.SaveContainer(entitySource, prefab);
104 Print(
string.Format(
"%1 prefabs checked, %2 repaired.", resources.Count(), repairedCount),
LogLevel.NORMAL);
109 protected bool ButtonRun()
116 protected bool ButtonClose()
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.
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