private void CreateNamedObjectElementRuntime(IElement elementSave, Layer layerProvidedByContainer, List<NamedObjectSave> namedObjectSaveList,
PositionedObjectList<ElementRuntime> listToPopulate, PositionedObject parentElementRuntime)
{
foreach (NamedObjectSave n in namedObjectSaveList)
{
Object newObject = null;
if (ShouldElementRuntimeBeCreatedForNos(n, elementSave))
{
Layer layerToPutOn = GetLayerForNos(layerProvidedByContainer, n);
switch (n.SourceType)
{
case SourceType.File:
newObject = LoadFileObject(n, elementSave, layerToPutOn, listToPopulate);
break;
case SourceType.Entity:
newObject = LoadEntityObject(n, layerToPutOn, listToPopulate);
break;
case SourceType.FlatRedBallType:
newObject = CreateFlatRedBallTypeNos(n, listToPopulate, layerToPutOn);
break;
}
}
if (newObject != null && newObject is PositionedObject)
{
PositionedObject attachTo;
float parentZToSet;
GetWhatToAttachToForNewNos(parentElementRuntime, n, newObject, out attachTo, out parentZToSet);
if (attachTo != null)
{
Vector3 oldPosition = attachTo.Position;
Matrix oldRotationMatrix = attachTo.RotationMatrix;
attachTo.Position = new Vector3();
attachTo.Z = parentZToSet;
attachTo.RotationMatrix = Matrix.Identity;
((PositionedObject)newObject).AttachTo(attachTo, true);
attachTo.Position = oldPosition;
attachTo.RotationMatrix = oldRotationMatrix;
}
}
}
}