4 [
Attribute(
"1",
desc:
"When enabled, preview prefab can be used also in runtime, not only when spawning from prefab.")]
11 protected ref array<ref SCR_BasePreviewEntry>
m_aEntries;
29 for (
int i = 0; i < count; i++)
40 outEntries.Insert(entryCopy);
101 static void GeneratePreviewEntries(WorldEditorAPI api, IEntitySource entitySource)
104 IEntityComponentSource componentSource;
105 for (
int i = 0, count = entitySource.GetComponentCount(); i < count; i++)
107 componentSource = entitySource.GetComponent(i);
108 if (componentSource.GetClassName().ToType().IsInherited(SCR_PreviewEntityComponent))
111 if (!componentSource)
115 BaseContainerList entriesList = componentSource.GetObjectArray(
"m_aEntries");
117 while (entriesList && entriesList.Count() >
index)
119 if (!api.RemoveObjectArrayVariableMember(entitySource, {ContainerIdPathEntry(
"SCR_PreviewEntityComponent")},
"m_aEntries", 0))
123 array<ref SCR_BasePreviewEntry> entries = {};
125 for (
int i = 0, count = entries.Count(); i < count; i++)
127 if (api.CreateObjectArrayVariableMember(entitySource, {ContainerIdPathEntry(
"SCR_PreviewEntityComponent")},
"m_aEntries",
"SCR_BasePreviewEntry", i))
140 void GeneratePreviewPrefab(WorldEditorAPI api, IEntitySource entitySource, IEntityComponentSource componentSource = null)
143 if (!componentSource)
145 for (
int i = 0, count = entitySource.GetComponentCount(); i < count; i++)
147 componentSource = entitySource.GetComponent(i);
148 if (componentSource.GetClassName() ==
"SCR_PreviewEntityComponent")
153 ResourceName prefab, previewPrefab;
154 componentSource.Get(
"m_PreviewPrefab", previewPrefab);
156 prefab = SCR_BaseContainerTools.GetPrefabResourceName(entitySource);
167 string absolutePath, absolutePathPreview, ext;
168 Workbench.GetAbsolutePath(prefab.GetPath(), absolutePath,
false);
169 absolutePathPreview = FilePath.AppendExtension(FilePath.StripExtension(absolutePath, ext) +
FILE_SUFFIX, ext);
172 IEntitySource emptyEntitySource = api.CreateEntity(
"SCR_PrefabPreviewEntity",
string.Empty, 0, null, vector.Zero, vector.Zero);
173 api.SetVariableValue(emptyEntitySource, null,
"m_SourcePrefab", prefab);
174 api.CreateEntityTemplate(emptyEntitySource, absolutePathPreview);
175 api.DeleteEntity(emptyEntitySource);
178 ResourceManager resourceManager = Workbench.GetModule(ResourceManager);
179 MetaFile meta = resourceManager.GetMetaFile(absolutePathPreview);
180 previewPrefab = meta.GetResourceID();
181 api.SetVariableValue(entitySource, {
ContainerIdPathEntry(
"SCR_PreviewEntityComponent")},
"m_PreviewPrefab", previewPrefab);
185 IEntitySource previewSource = api.CreateEntity(previewPrefab,
"", 0, null, vector.Zero, vector.Zero);
186 SCR_PrefabPreviewEntity previewEntity = SCR_PrefabPreviewEntity.Cast(api.SourceToEntity(previewSource));
187 previewEntity.CreatePrefabFromSource(api, prefab);
188 api.DeleteEntity(previewSource);
198 GenericEntity genericOwner = GenericEntity.Cast(owner);
200 IEntitySource ownerSrc = api.EntityToSource(owner);
203 WBProgressDialog progress =
new WBProgressDialog(
"Processing...", Workbench.GetModule(WorldEditor));
205 api.BeginEntityAction();
206 api.BeginEditSequence(ownerSrc);
207 GeneratePreviewEntries(api, ownerSrc);
208 api.EndEditSequence(ownerSrc);
209 api.EndEntityAction();
215 GenericEntity genericOwner = GenericEntity.Cast(owner);
217 IEntitySource ownerSrc = api.EntityToSource(owner);
219 api.BeginEntityAction();
220 GeneratePreviewPrefab(api, ownerSrc);
221 api.EndEntityAction();
229 return {
new WB_UIMenuItem(
"Generate preview entries", 0),
new WB_UIMenuItem(
"Generate preview prefab", 1) };
SCR_EAIThreatSectorFlags flags
void ContainerIdPathEntry(string propertyName, int index=-1)
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_CharacterSoundComponentClass GetComponentData()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
ResourceName GetPreviewPrefab()
SCR_PreviewEntityComponentClass FILE_SUFFIX
int GetPreviewEntries(out notnull array< ref SCR_BasePreviewEntry > outEntries, SCR_BasePreviewEntry entry)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
enum EVehicleType IEntity
event void _WB_OnContextMenu(IEntity owner, int id)
User has chosen any of your menu item from editor's "Component" menu which you have recently provided...
event array< ref WB_UIMenuItem > _WB_GetContextMenuItems(IEntity owner)
An opportunity to append items into editor's "Component" context menu. Do not call editor API here!
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
int GetPreviewEntries(out notnull array< ref SCR_BasePreviewEntry > outEntries, SCR_BasePreviewEntry entry)
ResourceName GetPreviewPrefab()
ref array< ref SCR_BasePreviewEntry > m_aEntries
ResourceName m_PreviewPrefab
proto external GenericEntity GetOwner()
Get owner entity.
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