3class SCR_UpdateAllEditablePrefabsPlugin : WorkbenchPlugin
5 [
Attribute(defvalue:
"{90B4D95CF3610F3D}Configs/Workbench/EditablePrefabs/EditablePrefabsConfig.conf",
desc:
"",
params:
"conf")]
6 protected ResourceName m_sConfig;
8 [
Attribute(
desc:
"Enable to only check for renamed or delete files, don't update their content.")]
9 protected bool m_bOnlyFileChanges;
11 protected static const string META_EXTENSION =
".meta";
14 protected void DeleteEmptyDirectoriesCallback(
string path,
FileAttribute attributes)
21 protected void DeleteEmptyDirectories(
string path)
23 FileIO.FindFiles(DeleteEmptyDirectoriesCallback,
path,
string.Empty);
29 if (!Workbench.ScriptDialog(
"Configure 'Update All Editable Prefabs' plugin",
"Batch operation applied on all auto-generated editable prefabs\n(check the config to see which folders will be affected).\n\nWARNING: This operation can take several minutes to perform!",
this))
32 EditablePrefabsConfig config = EditablePrefabsConfig.GetConfig(m_sConfig);
33 if (!config || !config.IsValid())
36 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
40 Workbench.OpenModule(WorldEditor);
41 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
45 WorldEditorAPI api = worldEditor.GetApi();
54 string targetPath = config.GetTargetPathAuto();
56 WBProgressDialog progress =
new WBProgressDialog(
"Processing Prefabs...", resourceManager);
57 Print(
string.Format(
"Updating editable entity prefabs STARTED at '%1'", targetPath),
LogLevel.DEBUG);
59 if (!config.CreateWorld())
63 array<ResourceName> resources = {};
65 SearchResourcesFilter filter =
new SearchResourcesFilter();
66 filter.fileExtensions = {
"et" };
67 ResourceDatabase.SearchResources(filter, resources.Insert);
68 int resourcesCount = resources.Count();
71 array<string> toRebuild = {};
73 api.BeginEntityAction();
74 float prevProgress, currProgress;
75 foreach (
int i, ResourceName prefab : resources)
77 prefabPath = prefab.GetPath();
78 if (!prefabPath.StartsWith(targetPath))
81 prefabPath = config.VerifyEditablePrefab(api, prefab, m_bOnlyFileChanges);
82 if (!prefabPath.IsEmpty())
83 toRebuild.Insert(prefabPath);
85 currProgress = i / resourcesCount;
86 if (currProgress - prevProgress >= 0.01)
88 progress.SetProgress(currProgress);
89 prevProgress = currProgress;
93 api.EndEntityAction();
96 resourceManager.RebuildResourceFiles(toRebuild,
"PC");
98 DeleteEmptyDirectories(targetPath);
102 Print(
string.Format(
"Updating editable entity prefabs FINISHED at '%1'", targetPath),
LogLevel.DEBUG);
107 protected bool ButtonRun()
114 protected bool ButtonClose()
120class SCR_ConfirmationDialogWorkbench
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
FileAttribute
File attributes. See FileDescription.