Esempio n. 1
0
        /// <summary>
        /// Ends the level and releases all resources held by the level and all it's parts.
        /// </summary>
        public new void Dispose()
        {
            IsEnding            = true;
            Scene.UpdateEnabled = false;
            try {
                Ending?.Invoke();
            }
            catch (Exception e) {
                Urho.IO.Log.Write(LogLevel.Warning,
                                  $"There was an unexpected exception during the invocation of {nameof(Ending)}: {e.Message}");
            }

            List <IDisposable> toDispose = new List <IDisposable>();

            toDispose.AddRange(entities.Values);
            toDispose.AddRange(players.Values);


            foreach (var thing in toDispose)
            {
                thing?.Dispose();
            }

            //Everything that is loaded anywhere else but the constructor may not be loaded at the time of disposing
            PackageManager.ActivePackage.ClearCaches();
            ToolManager?.Dispose();
            Input?.Dispose();
            cameraController?.Dispose();
            Camera?.Dispose();
            Input = null;
            map?.Dispose();
            Minimap?.Dispose();
            octree?.Dispose();

            //Have to get the reference before i remove the level from the scene by RemoveAllChildren on the scene
            Scene scene = Scene;

            scene.RemoveAllChildren();
            scene.RemoveAllComponents();
            scene.Remove();
            scene.Dispose();
            LevelNode?.Dispose();

            base.Dispose();
            CurrentLevel = null;
            GC.Collect();
        }