9 protected static const int TARGET_NONE = -1;
10 protected static const int TARGET_SLOT = -2;
13 protected ResourceName pf;
16 protected int pi = -1;
17 protected int ti = TARGET_NONE;
18 protected int tv = -1;
27 protected ref array<ref SCR_EditorAttributeStruct> at = {};
32 protected static SCR_CompositionSlotManagerComponent m_SlotManager;
33 protected static IEntity m_PlayerEntity;
46 set<SCR_EditableEntityComponent> children;
50 children =
new set<SCR_EditableEntityComponent>();
51 core.GetAllEntities(children,
true);
53 m_SlotManager = SCR_CompositionSlotManagerComponent.GetInstance();
56 array<int> entriesWithTarget = {};
59 SerializeEntity(child, -1, outEntries, attributeList, requiredFlags, entriesWithTarget,
false);
63 int entriesCount = outEntries.Count();
65 for (
int i = 0, count = entriesWithTarget.Count(); i < count; i++)
67 entry = outEntries[entriesWithTarget[i]];
68 for (
int e = 0; e < entriesCount; e++)
70 if (entry.m_Target == outEntries[e].m_Entity)
76 if (entry.ti == TARGET_NONE)
77 entry.m_Entity.Log(
"Error when serializing attach link!",
true, LogLevel.WARNING);
83 if (requiredFlags != 0 && !entity.HasEntityFlag(requiredFlags))
87 int targetValue = TARGET_NONE;
89 if (!entity.Serialize(target, targetValue, saveFlags))
96 entry.m_Entity = entity;
98 parentID = outEntries.Insert(entry);
100 entry.pf = entity.GetPrefab(
true);
103 entry.pf += saveFlags.ToString();
105 entry.sc = entity.GetOwner().GetScale();
107 entry.ef = entity.GetEntityFlags();
110 entity.GetOwner().GetWorldTransform(transform);
111 entry.px = transform[3][0];
112 entry.py = transform[3][1];
113 entry.pz = transform[3][2];
116 Math3D.MatrixToQuat(transform, quat);
122 entry.tv = targetValue;
125 entry.m_Target = target;
126 entriesWithTarget.Insert(parentID);
131 if (info && info.GetSlotPrefab() &&
m_SlotManager.IsInSlot(entity.GetOwner()))
132 entry.ti = TARGET_SLOT;
138 if (entry.hy || !canBeDirty)
140 for (
int c = 0, count = entity.GetChildrenCount(
true); c < count; c++)
142 SerializeEntity(entity.GetChild(c), parentID, outEntries, attributeList, requiredFlags, entriesWithTarget, entry.hy && canBeDirty);
151 static void DeserializeEntities(notnull array<ref SCR_EditableEntityStruct> entries,
SCR_EditorAttributeList attributeList =
null)
153 SCR_CompositionSlotManagerComponent slotManager = SCR_CompositionSlotManagerComponent.GetInstance();
156 map<int, SCR_EditableEntityComponent> entities =
new map<int, SCR_EditableEntityComponent>();
157 array<int> entriesWithTarget = {};
161 ResourceName prefab = entry.pf;
164 int guidIndex = prefab.LastIndexOf(
"}") + 1;
165 int prefabParamsCount = prefab.Length() - guidIndex;
166 if (prefabParamsCount > 0)
168 string prefabParams = prefab.Substring(guidIndex, prefabParamsCount);
169 saveFlags = prefabParams.ToInt();
170 prefab = prefab.Substring(0, guidIndex);
179 if (!entities.Find(entry.pi, parent))
181 Print(
string.Format(
"SCR_EditableEntityStruct: Error when spawning entity @\"%1\", parent with ID %2 not found!", entry.pf, entry.pi), LogLevel.WARNING);
190 EntitySpawnParams spawnParams =
new EntitySpawnParams();
197 Math3D.QuatToMatrix(quat, spawnParams.Transform);
198 spawnParams.Transform[3] = Vector(entry.px, entry.py, entry.pz);
199 spawnParams.TransformMode = ETransformMode.WORLD;
205 SCR_EditorLinkComponent.IgnoreSpawning(
true);
207 IEntity rawEntity =
GetGame().SpawnEntityPrefab(Resource.Load(prefab),
GetGame().GetWorld(), spawnParams);
211 entities.Insert(
id, entry.m_Entity);
213 rawEntity.SetScale(entry.sc);
214 entry.m_Entity.EOnEditorSessionLoad(parent);
215 entry.m_Entity.SetParentEntity(parent);
217 entry.m_Entity.SetHierarchyAsDirty();
219 entry.m_Entity.CopyEntityFlags(entry.ef);
223 if (entry.ti != TARGET_NONE)
225 if (entry.ti == TARGET_SLOT)
226 slotManager.SetOccupant(spawnParams.Transform[3], rawEntity);
228 entriesWithTarget.Insert(
id);
233 m_PlayerEntity = rawEntity;
239 entry.m_Entity.Destroy();
242 Print(
string.Format(
"SCR_EditableEntityStruct: Entity @\"%1\" spawned at %2 as a child of %3", entry.pf, spawnParams.Transform, parent), LogLevel.VERBOSE);
247 Print(
string.Format(
"SCR_EditableEntityStruct: Error when spawning entity @\"%1\" at %2, SCR_EditableEntityComponent not found!", entry.pf, spawnParams.Transform, parent), LogLevel.WARNING);
254 if (entriesWithTarget.Contains(
id))
255 entry.m_Entity.Deserialize(entries[entry.ti].m_Entity, entry.tv);
257 entry.m_Entity.Deserialize(
null, entry.tv);
260 SCR_EditorLinkComponent.IgnoreSpawning(
false);
263 protected static void RequestLocalPlayerSpawn(
int playerId)
266 if (respawnComponent)
270 respawnComponent.RequestSpawn(spawnData);
277 gameMode.GetOnPlayerRegistered().Insert(RequestLocalPlayerSpawn);
284 static void ClearEntities(notnull array<ref SCR_EditableEntityStruct> entries)
286 for (
int i = 0, count = entries.Count(); i < count; i++)
289 entries[i].m_Entity.Delete();
297 static void LogEntities(notnull array<ref SCR_EditableEntityStruct> entries,
SCR_EditorAttributeList attributeList =
null)
299 Print(
" SCR_EditableEntityStruct: " + entries.Count());
312 angles = Math3D.QuatToAngles(quat);
315 ResourceName prefab = entry.pf;
318 int guidIndex = prefab.LastIndexOf(
"}") + 1;
319 int prefabParamsCount = prefab.Length() - guidIndex;
320 if (prefabParamsCount > 0)
322 string prefabParams = prefab.Substring(guidIndex, prefabParamsCount);
323 saveFlags = prefabParams.ToInt();
326 resource = Resource.Load(entry.pf);
327 resourceName = resource.GetResource().GetResourceName();
336 string result =
" " +
id +
": " + entry.pi;
337 result +=
" | " + FilePath.StripPath(resourceName);
338 result +=
" | pos: " + Vector(entry.px, entry.py, entry.pz);
339 result +=
" | ang: " + angles;
340 result +=
" | scl: " + entry.sc;
342 result +=
" | drt: " + entry.hy;
344 if (entry.ti == TARGET_NONE)
345 result +=
" | tgt: N/A";
347 result +=
" | tgt: " + entry.ti;
349 result +=
" (#" + entry.tv +
")";