public void Destroy()
{
if (this.DirectObjectReference == SpriteManager.Camera)
{
SpriteManager.Camera.Detach();
}
mReferencedFileRuntimeList.Destroy();
for (int i = mContainedElements.Count - 1; i > -1; i--)
{
ElementRuntime e = mContainedElements[i];
e.Destroy();
}
for (int i = mElementsInList.Count - 1; i > -1; i--)
{
ElementRuntime e = mElementsInList[i];
e.Destroy();
}
if (mDirectObjectReference != null)
{
Type directReferenceType = mDirectObjectReference.GetType();
if (directReferenceType == typeof(AxisAlignedRectangle))
{
ShapeManager.Remove((AxisAlignedRectangle)mDirectObjectReference);
}
else if (directReferenceType == typeof(Circle))
{
ShapeManager.Remove((Circle)mDirectObjectReference);
}
else if (directReferenceType == typeof(Layer))
{
SpriteManager.RemoveLayer((Layer)mDirectObjectReference);
}
else if (directReferenceType == typeof(Line))
{
ShapeManager.Remove((Line)mDirectObjectReference);
}
else if (directReferenceType == typeof(Polygon))
{
ShapeManager.Remove((Polygon)mDirectObjectReference);
}
else if (directReferenceType == typeof(Sphere))
{
ShapeManager.Remove((Sphere)mDirectObjectReference);
}
else if(directReferenceType == typeof(SplineList))
{
var splineList = ((SplineList)mDirectObjectReference);
splineList.RemoveFromManagers();
}
else if (directReferenceType == typeof(Spline))
{
var spline = ((Spline)mDirectObjectReference);
spline.Visible = false;
}
else if (directReferenceType == typeof(Sprite))
{
SpriteManager.RemoveSprite((Sprite)mDirectObjectReference);
}
else if (directReferenceType == typeof(SpriteFrame))
{
SpriteManager.RemoveSpriteFrame((SpriteFrame)mDirectObjectReference);
}
else if (directReferenceType == typeof(Text))
{
TextManager.RemoveText((Text)mDirectObjectReference);
}
else if (directReferenceType == typeof(ShapeCollection))
{
((ShapeCollection)mDirectObjectReference).RemoveFromManagers();
}
else if (directReferenceType == typeof(Scene))
{
((Scene)mDirectObjectReference).RemoveFromManagers();
}
else if (directReferenceType == typeof(Emitter))
{
SpriteManager.RemoveEmitter((Emitter)mDirectObjectReference);
}
else if (directReferenceType == typeof(Camera))
{
Camera camera = (Camera)mDirectObjectReference;
if (camera == SpriteManager.Camera)
{
// do nothing
}
else
{
SpriteManager.Cameras.Remove((Camera)mDirectObjectReference);
}
}
else if (directReferenceType == typeof(SpriteGrid))
{
SpriteGrid spriteGrid = (SpriteGrid)mDirectObjectReference;
spriteGrid.Destroy();
}
else
{
throw new NotImplementedException("GlueView is not properly able to remove object of type " + mDirectObjectReference.GetType());
}
}
SpriteManager.RemovePositionedObject(this);
FlatRedBallServices.Unload(ContentManagerName);
mContainedElements.Clear();
}