Example #1
0
        } // DisposeManagedResources

        #endregion

        #region Initialize

        /// <summary>
        /// Creates the scene content manager and loads the user content.
        /// </summary>
        internal void Initialize()
        {
            AssetContentManager = new AssetContentManager {
                Name = (GetType().Name + " Content Manager")
            };
            AssetContentManager.CurrentContentManager = AssetContentManager;
            GameObjectContentManager = new GameObjectContentManager {
                Name = (GetType().Name + " Content Manager")
            };
            GameObjectContentManager.CurrentContentManager = GameObjectContentManager;
            LoadContent();
            ContentLoaded = true;
            // A collection of all generations could be a good idea at this point.
            // Besides the used managed memory indicates rational values when this is executed here.
            GarbageCollector.CollectGarbage();
        } // Initialize
Example #2
0
        } // DisposeManagedResources

        #endregion

        #region Unload

        /// <summary>
        /// Disposes all data that was loaded by this ContentManager.
        /// </summary>
        public void Unload()
        {
            // Dispose assets
            List <GameObject> gameObjectsTemporalList = new List <GameObject>(); // An auxiliary list is needed because the original will be modified for each asset.

            gameObjectsTemporalList.AddRange(GameObjects);
            foreach (GameObject gameObject in gameObjectsTemporalList)
            {
                gameObject.ContentManager = null;
                gameObject.Dispose();
            }
            gameObjectsTemporalList.Clear();
            // A collection of all generations could be a good idea at this point.
            // Besides the used managed memory indicates rational values when this is executed here.
            GarbageCollector.CollectGarbage();
        } // Unload
Example #3
0
        } // GameObjectContentManager

        #endregion

        #region Dispose

        /// <summary>
        /// Dispose managed resources.
        /// </summary>
        protected override void DisposeManagedResources()
        {
            ContentManagers.Remove(this);
            areContentManagersSorted = false;
            // Dispose assets
            List <GameObject> gameObjectsTemporalList = new List <GameObject>(); // An auxiliary list is needed because the original will be modified for each asset.

            gameObjectsTemporalList.AddRange(GameObjects);
            foreach (GameObject gameObject in gameObjectsTemporalList)
            {
                gameObject.Dispose();
            }
            gameObjectsTemporalList.Clear();
            // A collection of all generations could be a good idea at this point.
            // Besides the used managed memory indicates rational values when this is executed here.
            GarbageCollector.CollectGarbage();
        } // DisposeManagedResources
        } // DisposeManagedResources

        #endregion

        #region Unload

        /// <summary>
        /// Disposes all data that was loaded by this ContentManager.
        /// </summary>
        public void Unload()
        {
            if (systemContentManager == this)
            {
                throw new InvalidOperationException("Content Manager: System Content Manager can not be unloaded.");
            }
            XnaContentManager.Unload();
            // Dispose assets
            List <Asset> assetsTemporalList = new List <Asset>(); // An auxiliary list is needed because the original will be modified for each asset.

            assetsTemporalList.AddRange(Assets);
            foreach (Asset asset in assetsTemporalList)
            {
                asset.ContentManager = null;
                asset.Dispose();
            }
            assetsTemporalList.Clear();
            // A collection of all generations could be a good idea at this point.
            // Besides the used managed memory indicates rational values when this is executed here.
            GarbageCollector.CollectGarbage();
        } // Unload