﻿// Copyright 2015 XLGAMES Inc.
//
// Distributed under the MIT License (See
// accompanying file "LICENSE" or the website
// http://www.opensource.org/licenses/mit-license.php)

using System;
using Sce.Atf.Adaptation;

namespace LevelEditorXLE.Extensions
{
    internal static class ExtensionsClass
    {
        internal static GUILayer.EditorSceneManager GetSceneManager(this Sce.Atf.Dom.DomNodeAdapter adapter)
        {
            var root = adapter.DomNode.GetRoot();
            System.Diagnostics.Debug.Assert(root != null);
            if (root == null) return null;
            var gameExt = root.As<Game.GameExtensions>();
            System.Diagnostics.Debug.Assert(gameExt != null);
            if (gameExt == null) return null;
            return gameExt.SceneManager;
        }
    }
}

﻿// Copyright 2015 XLGAMES Inc.
//
// Distributed under the MIT License (See
// accompanying file "LICENSE" or the website
// http://www.opensource.org/licenses/mit-license.php)

using System;
using Sce.Atf.Adaptation;

namespace LevelEditorXLE.Extensions
{
    internal static class ExtensionsClass
    {
        internal static GUILayer.EditorSceneManager GetSceneManager(this Sce.Atf.Dom.DomNodeAdapter adapter)
        {
            // Prefer to return the SceneManager object associated
            // with the root game document. If we can't find one, fall
            // back to the GlobalSceneManager
            var root = adapter.DomNode.GetRoot();
            if (root != null)
            {
                var gameExt = root.As<Game.GameExtensions>();
                if (gameExt != null)
                {
                    var man = gameExt.SceneManager;
                    if (man != null)
                        return man;
                }
            }
            return XLEBridgeUtils.Utils.GlobalSceneManager;
        }
    }
}

Fix for a crash that can occur while exporting from the level editor - falling back to the global scene manager if we can't find a scene manager attached to the dom node tree
Fix for a crash that can occur while exporting from the level editor
- falling back to the global scene manager if we can't find a scene manager attached to the dom node tree
