koirat
01-03-2011 18:54:47
I was kind of startled when I realized that destroying overlay do not destroy it's OverlayElement-s.
I have made this functions to help me with the process, if there is any better way please tell me.
I have made this functions to help me with the process, if there is any better way please tell me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre;
namespace GameEngine
{
public static class OverlayUtils
{
public static List<OverlayElement> GetAllOverlayElements(Overlay overlay)
{
List<OverlayElement> collection = new List<OverlayElement>();
Overlay.Overlay2DElementsIterator iter = overlay.Get2DElementsIterator();
while (iter.MoveNext())
{
OverlayContainer oc = iter.Current as OverlayContainer;
if (oc != null)
GetAllOverlayElements(oc, collection);
collection.Add(iter.Current);
}
return collection;
}
public static void GetAllOverlayElements(OverlayContainer current, List<OverlayElement> collection)
{
OverlayContainer.ChildIterator iter = current.GetChildIterator();
while (iter.MoveNext())
{
OverlayContainer oc = iter.Current as OverlayContainer;
if (oc != null)
GetAllOverlayElements(oc, collection);
collection.Add(iter.Current);
}
}
public static void DestroyOverlay(Overlay overlay)
{
List<OverlayElement> elements = GetAllOverlayElements(overlay);
for (int i = 0; i < elements.Count; i++)
OverlayManager.Singleton.DestroyOverlayElement(elements[i]);
OverlayManager.Singleton.Destroy(overlay);
}
}
}