Created
December 4, 2013 02:43
-
-
Save wilfrem/7781464 to your computer and use it in GitHub Desktop.
俺のシーン管理システムが火を噴くぜ!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using RailloadCity.Core.CityScenes; | |
using RailloadCity.Core.Infrastructures.DependencyInjections; | |
using RailloadCity.Core.InputDevices; | |
using RailloadCity.Core.Storages; | |
using RailloadCity.Core.Surfaces; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Reflection; | |
namespace RailloadCity.Core.Infrastructures.Scenes | |
{ | |
/// <summary> | |
/// シーン処理を実施する | |
/// </summary> | |
public abstract class SceneManagerBase | |
{ | |
SceneCodes nextScene; | |
Dictionary<SceneCodes, Type> scenes = new Dictionary<SceneCodes, Type>(); | |
SceneBase scene = null; | |
string childContainerKey = null; | |
protected readonly IContainer Container; | |
public SceneManagerBase(IContainer container, SceneCodes startScene) | |
{ | |
nextScene = startScene; | |
this.Container = container; | |
SetupContainer(); | |
} | |
private void SetupContainer() | |
{ | |
Container.RegisterAsSingleton<InputManagerCore>(); | |
Container.RegisterAsSingleton<SurfaceInputRouter>(); | |
Container.RegisterAsSingleton<ConnectionManager>(); | |
Container.RegisterAsSingleton<SurfaceInputTester>(); | |
Container.RegisterAsSingleton<SurfaceSizes>(); | |
} | |
public void RegisterScene<T>(SceneCodes code) | |
where T : SceneBase | |
{ | |
scenes[code] = typeof(T); | |
} | |
public void JumpNextScene(SceneCodes code) | |
{ | |
nextScene = code; | |
} | |
public void Update() | |
{ | |
if (nextScene != SceneCodes.None) | |
{ | |
if (scene != null) | |
{ | |
scene.SceneEnd(); | |
} | |
scene = CreateNextScene(); | |
nextScene = SceneCodes.None; | |
} | |
if (scene != null) | |
{ | |
scene.Update(); | |
} | |
} | |
SceneBase CreateNextScene() | |
{ | |
if (childContainerKey != null) | |
{ | |
Container.DeleteChiledContainer(childContainerKey); | |
} | |
childContainerKey = nextScene.ToString(); | |
var nextSceneType = scenes[nextScene]; | |
var scene = Activator.CreateInstance(nextSceneType, Container.CreateChildContainer(childContainerKey)) as SceneBase; | |
scene.RegisterContainer(); | |
scene.Initialize(); | |
return scene; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment