Skip to content

Commit

Permalink
Updated to use latest EcsRx paradigms
Browse files Browse the repository at this point in the history
Now adhering to the new lifecycle in ecsrx 2.* versions
  • Loading branch information
grofit committed Sep 26, 2018
1 parent f116f6d commit 6910d7c
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 82 deletions.
7 changes: 0 additions & 7 deletions src/Assets/EcsRx.Examples/AutoRegisterSystems/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ namespace EcsRx.Examples.AutoRegisterSystems
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
// You could optionally use instead of the scene based approach
// this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace EcsRx.Examples.CustomGameObjectHandling
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/GameObjectBinding/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace EcsRx.Examples.GameObjectBinding
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var entityCollection = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/GameObjectLinking/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace EcsRx.Examples.GameObjectLinking
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/ManualSystems/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace EcsRx.Examples.ManualSystems
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted() { }
}
}
12 changes: 7 additions & 5 deletions src/Assets/EcsRx.Examples/ManuallyRegisterSystems/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ namespace EcsRx.Examples.ManuallyRegisterSystems
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
protected override void StartSystems()
{
// This one we are manually binding and registering at same time
this.BindAndRegisterSystem<DefaultViewResolver>();
// This one we are manually binding and starting at the same time
this.BindAndStartSystem<DefaultViewResolver>();

// This one we are manually registering from the installer which has already bound it
this.RegisterSystem<RandomMovementSystem>();
// This one we are manually starting from the installer which has already bound it
this.StartSystem<RandomMovementSystem>();
}

protected override void ApplicationStarted()
{


var defaultPool = EntityCollectionManager.GetCollection();

var entity = defaultPool.CreateEntity();
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/EcsRx.Examples/PluginExample/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace EcsRx.Examples.PluginExample
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
protected override void LoadPlugins()
{
RegisterPlugin(new HelloWorldPlugin.HelloWorldPlugin());
}
Expand Down
9 changes: 1 addition & 8 deletions src/Assets/EcsRx.Examples/PooledViews/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ namespace EcsRx.Examples.PooledViews
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
}

protected override void ApplicationStarted()
{
this.RegisterAllBoundSystems();
}
{}
}
}
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/RandomReactions/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ public class Application : EcsRxApplicationBehaviour
{
private readonly int _cubeCount = 5000;

protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var collection = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/SceneFirstSetup/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace EcsRx.Examples.SceneFirstSetup
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/SimpleMovement/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace EcsRx.Examples.SimpleMovement
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
6 changes: 0 additions & 6 deletions src/Assets/EcsRx.Examples/UsingBlueprints/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace EcsRx.Examples.UsingBlueprints
{
public class Application : EcsRxApplicationBehaviour
{
protected override void ApplicationStarting()
{
this.BindAllSystemsWithinApplicationScope();
this.RegisterAllBoundSystems();
}

protected override void ApplicationStarted()
{
var defaultPool = EntityCollectionManager.GetCollection();
Expand Down
Binary file modified src/Assets/EcsRx/EcsRx.Infrastructure.dll
Binary file not shown.
61 changes: 48 additions & 13 deletions src/Assets/EcsRx/Zenject/EcsRxApplicationBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class EcsRxApplicationBehaviour : MonoBehaviour, IEcsRxApplicati

private SceneContext _sceneContext;

protected abstract void ApplicationStarted();

private void Awake()
{
var sceneContexts = FindObjectsOfType<SceneContext>();
Expand All @@ -49,31 +51,64 @@ protected void OnZenjectReady()

public virtual void StartApplication()
{
RegisterModules();
_sceneContext.Container.Inject(this);

ApplicationStarting();
RegisterAllPluginDependencies();
SetupAllPluginSystems();
LoadModules();
LoadPlugins();
SetupPlugins();
ResolveApplicationDependencies();
BindSystems();
StartPluginSystems();
StartSystems();
ApplicationStarted();
}

/// <summary>
/// Load any plugins that your application needs
/// </summary>
/// <remarks>It is recommended you just call RegisterPlugin method in here for each plugin you need</remarks>
protected virtual void LoadPlugins(){}

protected virtual void RegisterModules()
/// <summary>
/// Load any modules that your application needs
/// </summary>
/// <remarks>
/// If you wish to use the default setup call through to base, if you wish to stop the default framework
/// modules loading then do not call base and register your own internal framework module.
/// </remarks>
protected virtual void LoadModules()
{
Container.LoadModule<FrameworkModule>();

}

/// <summary>
/// Resolve any dependencies the application needs
/// </summary>
/// <remarks>By default it will setup SystemExecutor, EventSystem, EntityCollectionManager</remarks>
protected virtual void ResolveApplicationDependencies()
{
SystemExecutor = Container.Resolve<ISystemExecutor>();
EventSystem = Container.Resolve<IEventSystem>();
EntityCollectionManager = Container.Resolve<IEntityCollectionManager>();
_sceneContext.Container.Inject(this);
}

/// <summary>
/// Bind any systems that the application will need
/// </summary>
/// <remarks>By default will auto bind any systems within application scope</remarks>
protected virtual void BindSystems()
{ this.BindAllSystemsWithinApplicationScope(); }

protected virtual void ApplicationStarting() { }
protected abstract void ApplicationStarted();

protected virtual void RegisterAllPluginDependencies()
/// <summary>
/// Start any systems that the application will need
/// </summary>
/// <remarks>By default it will auto start any systems which have been bound</remarks>
protected virtual void StartSystems()
{ this.StartAllBoundSystems(); }

protected virtual void SetupPlugins()
{ _plugins.ForEachRun(x => x.SetupDependencies(Container)); }

protected virtual void SetupAllPluginSystems()
protected virtual void StartPluginSystems()
{
_plugins.SelectMany(x => x.GetSystemsForRegistration(Container))
.ForEachRun(x => SystemExecutor.AddSystem(x));
Expand Down

0 comments on commit 6910d7c

Please sign in to comment.