Пример #1
0
        /// <summary>
        /// Explicitly removes node from hierarchy and disposes of children and components
        /// </summary>
        public virtual void Destroy()
        {
            // Destroying node hierarchy is flattened and not recursive
            // for performance considerations

            if (Destroyed)
            {
                return;
            }

            Destroyed = true;

            UnsubscribeFromAllEvents();

            // Remove from hierarchy
            Remove();

            // list of nodes/components to dispose
            var disposeList = new List <RefCounted>();

            // IMPORTANT: Care must be taken to clear these vectors
            // otherwise, references will be held until the Vector is GC'd
            // and the child nodes/components/resources will not be immediately disposed

            var nodes      = new Vector <Node>();
            var components = new Vector <Component>();

            // Get node components and add to dispose list
            GetComponents(components);
            disposeList.AddRange(components);
            components.Clear();

            // get all children of node and add their components to the dispose list
            GetChildren(nodes, true);
            foreach (var node in nodes)
            {
                node.Destroyed = true;
                node.GetComponents(components);
                disposeList.AddRange(components);
                components.Clear();
            }

            // add nodes to the back of the list
            disposeList.AddRange(nodes);

            nodes.Clear();

            // Add ourself to the dispose list
            disposeList.Add(this);

            // dispose of list
            RefCountedCache.Dispose(disposeList);
        }
Пример #2
0
 public void GetComponents <T>(Vector <T> dest, bool recursive = false) where T : Component
 {
     dest.Clear();
     GetComponents(ComponentVector, typeof(T).Name, recursive);
     for (int i = 0; i < ComponentVector.Size; i++)
     {
         if (ComponentVector[i] != null)
         {
             dest.Push((T)ComponentVector[i]);
         }
     }
     ComponentVector.Clear();
 }
Пример #3
0
 public void GetDerivedCSComponents <T>(Vector <T> dest, bool recursive = false) where T : CSComponent
 {
     dest.Clear();
     GetComponents(ComponentVector, nameof(CSComponent), recursive);
     for (int i = 0; i < ComponentVector.Size; ++i)
     {
         T t = ComponentVector[i] as T;
         if (t != null)
         {
             dest.Push(t);
         }
     }
     ComponentVector.Clear();
 }
Пример #4
0
 public void GetCSComponents <T>(Vector <T> dest, bool recursive = false) where T : CSComponent
 {
     dest.Clear();
     GetComponents(ComponentVector, nameof(CSComponent), recursive);
     for (int i = 0; i < ComponentVector.Size; i++)
     {
         Component component = ComponentVector[i];
         if (component != null &&
             component.GetType() == typeof(T))
         {
             dest.Push((T)component);
         }
     }
     ComponentVector.Clear();
 }