3 name:
"Missing Ruin Prefabs Creator",
5 description:
"Create Prefabs for ruin models that do not have any",
6 wbModules: {
"WorldEditor" },
7 awesomeFontCode: 0xF6BE)]
8class SCR_RuinPrefabCreatorPlugin : WorkbenchPlugin
10 protected static const ResourceName RUIN_BASE =
"{A7C1BCA45681EB56}Prefabs/Structures/Core/BuildingRuin_base.et";
15 if (!SCR_WorldEditorToolHelper.GetWorldEditorAPI())
23 array<ResourceName> prefablessRuins = GetRuinModelsWithoutPrefabs(ruinModels, ruinPrefabs);
29 Print(
"treating " + prefablessRuins.Count() +
" prefabless ruins",
LogLevel.NORMAL);
33 string absoluteFilePath;
34 if (!Workbench.GetAbsolutePath(relativeFilePath, absoluteFilePath,
false))
40 string absoluteFilePathPrefix = absoluteFilePath.Substring(0, absoluteFilePath.IndexOf(relativeFilePath));
42 string fileName =
FilePath.StripExtension(
FilePath.StripPath(absoluteFilePath));
44 if (!relativePath.StartsWith(
"Assets/"))
50 string relativePrefabFilePath =
"Prefabs" + relativePath.Substring(6, relativePath.Length() - 6) + fileName +
".et";
51 string absolutePrefabFilePath = absoluteFilePathPrefix + relativePrefabFilePath;
53 if (
FileIO.FileExists(absolutePrefabFilePath))
55 Print(
"Skipping " + relativeFilePath +
" as " + absolutePrefabFilePath +
" already exists",
LogLevel.NORMAL);
59 ResourceName createdPrefab = SCR_PrefabHelper.CreatePrefabFromXOB(
resourceName, absolutePrefabFilePath, RUIN_BASE,
true);
62 Print(
"Cannot create Prefab at " + absolutePrefabFilePath,
LogLevel.WARNING);
73 protected array<ResourceName> GetRuinModelsWithoutPrefabs(notnull array<ResourceName> ruinModels, notnull array<ResourceName> ruinPrefabs)
80 set<ResourceName> ruinXobSet =
new set<ResourceName>();
83 resource =
Resource.Load(ruinPrefab);
84 if (!resource.IsValid())
86 Print(
"Invalid Ruin Prefab (invalid resource) " + ruinPrefab,
LogLevel.WARNING);
90 baseResourceObject = resource.GetResource();
91 if (!baseResourceObject)
93 Print(
"Invalid Ruin Prefab (no baseResourceObject) " + ruinPrefab,
LogLevel.WARNING);
97 entitySource = baseResourceObject.ToEntitySource();
100 Print(
"Invalid Ruin Prefab (no entitySource) " + ruinPrefab,
LogLevel.WARNING);
104 ResourceName ruinXOB = GetModelFromPrefab(entitySource);
107 Print(
"Invalid Ruin Prefab (no model) " + ruinPrefab,
LogLevel.NORMAL);
111 ruinXobSet.Insert(ruinXOB);
114 array<ResourceName> result = {};
117 if (!ruinXobSet.Contains(ruinXOB))
118 result.Insert(ruinXOB);
132 meshComp.Get(
"Object", result);
154 protected void SCR_RuinPrefabCreatorPlugin();
ResourceName resourceName
Object holding reference to resource. In destructor release the resource.
static array< ResourceName > SearchWorkbenchResources(array< string > fileExtensions=null, array< string > searchStrArray=null, string rootPath="", bool recursive=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.