diff --git a/src/Assets/EcsRx.Examples/AutoRegisterSystems/Application.cs b/src/Assets/EcsRx.Examples/AutoRegisterSystems/Application.cs index 086bbbe8..29980b41 100644 --- a/src/Assets/EcsRx.Examples/AutoRegisterSystems/Application.cs +++ b/src/Assets/EcsRx.Examples/AutoRegisterSystems/Application.cs @@ -8,6 +8,9 @@ public class Application : EcsRxApplicationBehaviour { protected override void ApplicationStarting() { + // You could optionally use instead of the scene based approach + // this.BindAllSystemsWithinApplicationScope(); + this.RegisterAllBoundSystems(); } @@ -15,7 +18,7 @@ protected override void ApplicationStarted() { var defaultPool = CollectionManager.GetCollection(); var entity = defaultPool.CreateEntity(); - entity.AddComponent(new ViewComponent()); + entity.AddComponents(new ViewComponent()); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx.Examples/AutoRegisterSystems/Systems/RandomMovementSystem.cs b/src/Assets/EcsRx.Examples/AutoRegisterSystems/Systems/RandomMovementSystem.cs index 86bd0ae6..3ad63693 100644 --- a/src/Assets/EcsRx.Examples/AutoRegisterSystems/Systems/RandomMovementSystem.cs +++ b/src/Assets/EcsRx.Examples/AutoRegisterSystems/Systems/RandomMovementSystem.cs @@ -1,5 +1,6 @@ using System; using EcsRx.Entities; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/AutoRegisterSystems/auto-register-systems-scene.unity b/src/Assets/EcsRx.Examples/AutoRegisterSystems/auto-register-systems-scene.unity index cf2e18c5..291b2c3f 100644 Binary files a/src/Assets/EcsRx.Examples/AutoRegisterSystems/auto-register-systems-scene.unity and b/src/Assets/EcsRx.Examples/AutoRegisterSystems/auto-register-systems-scene.unity differ diff --git a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/CameraFollowSystem.cs b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/CameraFollowSystem.cs index 6de90e75..270e3188 100644 --- a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/CameraFollowSystem.cs +++ b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/CameraFollowSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.CustomGameObjectHandling.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/PlayerControlSystem.cs b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/PlayerControlSystem.cs index 74d6b971..04e8dc45 100644 --- a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/PlayerControlSystem.cs +++ b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/Systems/PlayerControlSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.CustomGameObjectHandling.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/UnityApplication.cs b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/UnityApplication.cs index dea14c60..ac19d7bd 100644 --- a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/UnityApplication.cs +++ b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/UnityApplication.cs @@ -1,32 +1,21 @@ using EcsRx.Examples.CustomGameObjectHandling.Components; using EcsRx.Examples.CustomGameObjectHandling.Systems; using EcsRx.Unity; +using EcsRx.Unity.Extensions; using Zenject; namespace EcsRx.Examples.CustomGameObjectHandling { public class UnityApplication : EcsRxApplicationBehaviour - { - [Inject] - public CustomViewSetupSystem CustomViewSetupSystem { get; private set; } - - [Inject] - public PlayerControlSystem PlayerControlSystem { get; private set; } - - [Inject] - public CameraFollowSystem CameraFollowSystem { get; private set; } - + { protected override void ApplicationStarted() { - SystemExecutor.AddSystem(CustomViewSetupSystem); - SystemExecutor.AddSystem(PlayerControlSystem); - SystemExecutor.AddSystem(CameraFollowSystem); + this.BindAllSystemsWithinApplicationScope(); + this.RegisterAllBoundSystems(); var defaultPool = CollectionManager.GetCollection(); var viewEntity = defaultPool.CreateEntity(); - viewEntity.AddComponent(new CustomViewComponent()); - viewEntity.AddComponent(new PlayerControlledComponent()); - viewEntity.AddComponent(new CameraFollowsComponent()); + viewEntity.AddComponents(new CustomViewComponent(), new PlayerControlledComponent(), new CameraFollowsComponent()); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/custom-game-object-handling.unity b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/custom-game-object-handling.unity index 54810a48..e08bf883 100644 Binary files a/src/Assets/EcsRx.Examples/CustomGameObjectHandling/custom-game-object-handling.unity and b/src/Assets/EcsRx.Examples/CustomGameObjectHandling/custom-game-object-handling.unity differ diff --git a/src/Assets/EcsRx.Examples/GameObjectBinding/UnityApplication.cs b/src/Assets/EcsRx.Examples/GameObjectBinding/UnityApplication.cs index 0177cc79..6cb5871d 100644 --- a/src/Assets/EcsRx.Examples/GameObjectBinding/UnityApplication.cs +++ b/src/Assets/EcsRx.Examples/GameObjectBinding/UnityApplication.cs @@ -1,4 +1,5 @@ using EcsRx.Examples.GameObjectBinding.Components; +using EcsRx.Extensions; using EcsRx.Unity; using EcsRx.Unity.Extensions; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/CubeViewResolver.cs b/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/CubeViewResolver.cs index fc40a846..39db5829 100644 --- a/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/CubeViewResolver.cs +++ b/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/CubeViewResolver.cs @@ -14,7 +14,7 @@ public class CubeViewResolver : PrefabViewResolverSystem { public override IGroup Group => base.Group.WithComponent(); - protected override GameObject PrefabTemplate => GameObject.CreatePrimitive(PrimitiveType.Cube); + protected override GameObject PrefabTemplate { get; } = Resources.Load("Cube"); public CubeViewResolver(IEntityCollectionManager collectionManager, IEventSystem eventSystem, IInstantiator instantiator) : base(collectionManager, eventSystem, instantiator) diff --git a/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/SphereViewResolver.cs b/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/SphereViewResolver.cs index 8bc1f29e..c26376f1 100644 --- a/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/SphereViewResolver.cs +++ b/src/Assets/EcsRx.Examples/GameObjectBinding/ViewResolvers/SphereViewResolver.cs @@ -13,7 +13,7 @@ namespace EcsRx.Examples.GameObjectBinding.ViewResolvers public class SphereViewResolver : PrefabViewResolverSystem { public override IGroup Group => base.Group.WithComponent(); - protected override GameObject PrefabTemplate => GameObject.CreatePrimitive(PrimitiveType.Sphere); + protected override GameObject PrefabTemplate { get; } = Resources.Load("Sphere"); public SphereViewResolver(IEntityCollectionManager collectionManager, IEventSystem eventSystem, IInstantiator instantiator) : base(collectionManager, eventSystem, instantiator) { diff --git a/src/Assets/EcsRx.Examples/GameObjectLinking/Systems/CameraFollowSystem.cs b/src/Assets/EcsRx.Examples/GameObjectLinking/Systems/CameraFollowSystem.cs index c28f38fd..b51f1566 100644 --- a/src/Assets/EcsRx.Examples/GameObjectLinking/Systems/CameraFollowSystem.cs +++ b/src/Assets/EcsRx.Examples/GameObjectLinking/Systems/CameraFollowSystem.cs @@ -1,4 +1,5 @@ using EcsRx.Entities; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Systems; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/Systems/RandomMovementSystem.cs b/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/Systems/RandomMovementSystem.cs index f4bd32d1..20a9475e 100644 --- a/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/Systems/RandomMovementSystem.cs +++ b/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/Systems/RandomMovementSystem.cs @@ -1,5 +1,6 @@ using System; using EcsRx.Entities; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/UnityApplication.cs b/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/UnityApplication.cs index ccb8f646..719fca9f 100644 --- a/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/UnityApplication.cs +++ b/src/Assets/EcsRx.Examples/ManuallyRegisterSystems/UnityApplication.cs @@ -18,7 +18,7 @@ protected override void ApplicationStarted() var defaultPool = CollectionManager.GetCollection(); var entity = defaultPool.CreateEntity(); - entity.AddComponent(new ViewComponent()); + entity.AddComponents(new ViewComponent()); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx.Examples/PluginExample/UnityApplication.cs b/src/Assets/EcsRx.Examples/PluginExample/UnityApplication.cs index 7bc2916d..41b5b5d9 100644 --- a/src/Assets/EcsRx.Examples/PluginExample/UnityApplication.cs +++ b/src/Assets/EcsRx.Examples/PluginExample/UnityApplication.cs @@ -1,4 +1,5 @@ using EcsRx.Examples.PluginExample.HelloWorldPlugin.components; +using EcsRx.Extensions; using EcsRx.Unity; using EcsRx.Unity.Extensions; diff --git a/src/Assets/EcsRx.Examples/PooledViews/Systems/SelfDestructionSystem.cs b/src/Assets/EcsRx.Examples/PooledViews/Systems/SelfDestructionSystem.cs index 81e1d3e5..cb905f70 100644 --- a/src/Assets/EcsRx.Examples/PooledViews/Systems/SelfDestructionSystem.cs +++ b/src/Assets/EcsRx.Examples/PooledViews/Systems/SelfDestructionSystem.cs @@ -2,6 +2,7 @@ using EcsRx.Collections; using EcsRx.Entities; using EcsRx.Examples.PooledViews.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Systems; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/PooledViews/Systems/SpawnSystem.cs b/src/Assets/EcsRx.Examples/PooledViews/Systems/SpawnSystem.cs index 155143e3..57384022 100644 --- a/src/Assets/EcsRx.Examples/PooledViews/Systems/SpawnSystem.cs +++ b/src/Assets/EcsRx.Examples/PooledViews/Systems/SpawnSystem.cs @@ -3,6 +3,7 @@ using EcsRx.Entities; using EcsRx.Examples.PooledViews.Blueprints; using EcsRx.Examples.PooledViews.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Systems; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/PooledViews/ViewResolvers/SelfDestructionViewResolver.cs b/src/Assets/EcsRx.Examples/PooledViews/ViewResolvers/SelfDestructionViewResolver.cs index 1fdc2bd0..b2ed08c2 100644 --- a/src/Assets/EcsRx.Examples/PooledViews/ViewResolvers/SelfDestructionViewResolver.cs +++ b/src/Assets/EcsRx.Examples/PooledViews/ViewResolvers/SelfDestructionViewResolver.cs @@ -2,6 +2,7 @@ using EcsRx.Entities; using EcsRx.Events; using EcsRx.Examples.PooledViews.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Unity.Systems; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/RandomReactions/Systems/ColorChangingSystem.cs b/src/Assets/EcsRx.Examples/RandomReactions/Systems/ColorChangingSystem.cs index c5dd720d..58a32c06 100644 --- a/src/Assets/EcsRx.Examples/RandomReactions/Systems/ColorChangingSystem.cs +++ b/src/Assets/EcsRx.Examples/RandomReactions/Systems/ColorChangingSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.RandomReactions.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/RandomReactions/Systems/CubeColourChangerSystem.cs b/src/Assets/EcsRx.Examples/RandomReactions/Systems/CubeColourChangerSystem.cs index 1a3dabb5..21e71e38 100644 --- a/src/Assets/EcsRx.Examples/RandomReactions/Systems/CubeColourChangerSystem.cs +++ b/src/Assets/EcsRx.Examples/RandomReactions/Systems/CubeColourChangerSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.RandomReactions.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Systems; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/SceneFirstSetup/Application.cs b/src/Assets/EcsRx.Examples/SceneFirstSetup/Application.cs index eb56ae03..7c2f27fc 100644 --- a/src/Assets/EcsRx.Examples/SceneFirstSetup/Application.cs +++ b/src/Assets/EcsRx.Examples/SceneFirstSetup/Application.cs @@ -1,4 +1,5 @@ using EcsRx.Examples.SceneFirstSetup.Components; +using EcsRx.Extensions; using EcsRx.Unity; using EcsRx.Unity.Extensions; using EcsRx.Views.Components; diff --git a/src/Assets/EcsRx.Examples/SimpleMovement/Systems/CameraFollowSystem.cs b/src/Assets/EcsRx.Examples/SimpleMovement/Systems/CameraFollowSystem.cs index e19935aa..433bbb0f 100644 --- a/src/Assets/EcsRx.Examples/SimpleMovement/Systems/CameraFollowSystem.cs +++ b/src/Assets/EcsRx.Examples/SimpleMovement/Systems/CameraFollowSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.SimpleMovement.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/SimpleMovement/Systems/PlayerControlSystem.cs b/src/Assets/EcsRx.Examples/SimpleMovement/Systems/PlayerControlSystem.cs index 0d7ea46a..34006d66 100644 --- a/src/Assets/EcsRx.Examples/SimpleMovement/Systems/PlayerControlSystem.cs +++ b/src/Assets/EcsRx.Examples/SimpleMovement/Systems/PlayerControlSystem.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Entities; using EcsRx.Examples.SimpleMovement.Components; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Groups.Observable; using EcsRx.Systems; diff --git a/src/Assets/EcsRx.Examples/SimpleMovement/UnityApplication.cs b/src/Assets/EcsRx.Examples/SimpleMovement/UnityApplication.cs index 14ac6c22..68366a3f 100644 --- a/src/Assets/EcsRx.Examples/SimpleMovement/UnityApplication.cs +++ b/src/Assets/EcsRx.Examples/SimpleMovement/UnityApplication.cs @@ -18,9 +18,8 @@ protected override void ApplicationStarted() { var defaultPool = CollectionManager.GetCollection(); var viewEntity = defaultPool.CreateEntity(); - viewEntity.AddComponent(new ViewComponent()); - viewEntity.AddComponent(new PlayerControlledComponent()); - viewEntity.AddComponent(new CameraFollowsComponent()); + viewEntity.AddComponents(new ViewComponent(), + new PlayerControlledComponent(), new CameraFollowsComponent()); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx.Examples/UsingBlueprints/Blueprints/PlayerBlueprint.cs b/src/Assets/EcsRx.Examples/UsingBlueprints/Blueprints/PlayerBlueprint.cs index b7540b14..336ff1c5 100644 --- a/src/Assets/EcsRx.Examples/UsingBlueprints/Blueprints/PlayerBlueprint.cs +++ b/src/Assets/EcsRx.Examples/UsingBlueprints/Blueprints/PlayerBlueprint.cs @@ -1,6 +1,7 @@ using EcsRx.Blueprints; using EcsRx.Entities; using EcsRx.Examples.UsingBlueprints.Components; +using EcsRx.Extensions; namespace EcsRx.Examples.UsingBlueprints.Blueprints { @@ -17,8 +18,8 @@ public PlayerBlueprint(string name, float defaultHealth = 100.0f) public void Apply(IEntity entity) { - entity.AddComponent(new HasName { Name = Name }); - entity.AddComponent(new WithHealthComponent { CurrentHealth = DefaultHealth, MaxHealth = DefaultHealth}); + entity.AddComponents(new HasName { Name = Name }, + new WithHealthComponent { CurrentHealth = DefaultHealth, MaxHealth = DefaultHealth}); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx.Examples/UsingBlueprints/Systems/PlayerReportingSystem.cs b/src/Assets/EcsRx.Examples/UsingBlueprints/Systems/PlayerReportingSystem.cs index 0742392f..2818a9c1 100644 --- a/src/Assets/EcsRx.Examples/UsingBlueprints/Systems/PlayerReportingSystem.cs +++ b/src/Assets/EcsRx.Examples/UsingBlueprints/Systems/PlayerReportingSystem.cs @@ -1,6 +1,7 @@ using EcsRx.Entities; using EcsRx.Examples.UsingBlueprints.Components; using EcsRx.Examples.UsingBlueprints.Groups; +using EcsRx.Extensions; using EcsRx.Groups; using EcsRx.Systems; using UnityEngine; diff --git a/src/Assets/EcsRx/EcsRx.Infrastructure.dll b/src/Assets/EcsRx/EcsRx.Infrastructure.dll index b9da44b6..fb251499 100644 Binary files a/src/Assets/EcsRx/EcsRx.Infrastructure.dll and b/src/Assets/EcsRx/EcsRx.Infrastructure.dll differ diff --git a/src/Assets/EcsRx/EcsRx.Infrastructure.pdb b/src/Assets/EcsRx/EcsRx.Infrastructure.pdb index 2efa3a1a..ae354238 100644 Binary files a/src/Assets/EcsRx/EcsRx.Infrastructure.pdb and b/src/Assets/EcsRx/EcsRx.Infrastructure.pdb differ diff --git a/src/Assets/EcsRx/EcsRx.Views.dll b/src/Assets/EcsRx/EcsRx.Views.dll index cfd46f26..71ca1acf 100644 Binary files a/src/Assets/EcsRx/EcsRx.Views.dll and b/src/Assets/EcsRx/EcsRx.Views.dll differ diff --git a/src/Assets/EcsRx/EcsRx.Views.pdb b/src/Assets/EcsRx/EcsRx.Views.pdb index c64d36a7..294075fa 100644 Binary files a/src/Assets/EcsRx/EcsRx.Views.pdb and b/src/Assets/EcsRx/EcsRx.Views.pdb differ diff --git a/src/Assets/EcsRx/EcsRx.dll b/src/Assets/EcsRx/EcsRx.dll index 2fab035d..80327abf 100644 Binary files a/src/Assets/EcsRx/EcsRx.dll and b/src/Assets/EcsRx/EcsRx.dll differ diff --git a/src/Assets/EcsRx/EcsRx.pdb b/src/Assets/EcsRx/EcsRx.pdb index 4a88ea7f..5fd33b1d 100644 Binary files a/src/Assets/EcsRx/EcsRx.pdb and b/src/Assets/EcsRx/EcsRx.pdb differ diff --git a/src/Assets/EcsRx/Unity/Dependencies/ZenjectDependencyContainer.cs b/src/Assets/EcsRx/Unity/Dependencies/ZenjectDependencyContainer.cs index 4724bfbd..d30a08a3 100644 --- a/src/Assets/EcsRx/Unity/Dependencies/ZenjectDependencyContainer.cs +++ b/src/Assets/EcsRx/Unity/Dependencies/ZenjectDependencyContainer.cs @@ -11,6 +11,11 @@ public class ZenjectDependencyContainer : IDependencyContainer public ZenjectDependencyContainer(DiContainer container) { _container = container; } + public void LoadModule(IDependencyModule module) + { + module.Setup(this); + } + public object NativeContainer => _container; public void Bind(BindingConfiguration configuration = null) where TTo : TFrom @@ -59,13 +64,18 @@ public T Resolve(string name = null) return _container.ResolveId(name); } + public void Unbind() + { + _container.Unbind(); + } + public IEnumerable ResolveAll() { return _container.ResolveAll(); } public void LoadModule() where T : IDependencyModule, new() { var module = new T(); - module.Setup(this); + LoadModule(module); } } } \ No newline at end of file diff --git a/src/Assets/EcsRx/Unity/Editor/EntityViewInspector.cs b/src/Assets/EcsRx/Unity/Editor/EntityViewInspector.cs index 65509990..6ce882c6 100644 --- a/src/Assets/EcsRx/Unity/Editor/EntityViewInspector.cs +++ b/src/Assets/EcsRx/Unity/Editor/EntityViewInspector.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using EcsRx.Components; +using EcsRx.Extensions; using EcsRx.Unity.Extensions; using EcsRx.Unity.MonoBehaviours; using EcsRx.Unity.UIAspects; @@ -91,11 +92,13 @@ private void ComponentListings() EditorGUILayout.EndVertical(); - for (var i = 0; i < componentsToRemove.Count(); i++) + var componentArray = new Type[componentsToRemove.Count]; + for (var i = 0; i < componentsToRemove.Count; i++) { var component = _entityView.Entity.Components.ElementAt(i); - _entityView.Entity.RemoveComponent(component); + componentArray[i] = component.GetType(); } + _entityView.Entity.RemoveComponents(componentArray); } public static Type GetTypeWithAssembly(string typeName) @@ -125,7 +128,7 @@ private void ComponentSelectionSection() if (index >= 0) { var component = (IComponent)Activator.CreateInstance(availableTypes[index]); - _entityView.Entity.AddComponent(component); + _entityView.Entity.AddComponents(component); } }); } diff --git a/src/Assets/EcsRx/Unity/Extensions/GameObjectExtensions.cs b/src/Assets/EcsRx/Unity/Extensions/GameObjectExtensions.cs index 639977bf..961634fc 100644 --- a/src/Assets/EcsRx/Unity/Extensions/GameObjectExtensions.cs +++ b/src/Assets/EcsRx/Unity/Extensions/GameObjectExtensions.cs @@ -1,6 +1,7 @@ using System; using EcsRx.Collections; using EcsRx.Entities; +using EcsRx.Extensions; using EcsRx.Unity.MonoBehaviours; using EcsRx.Views.Components; using UnityEngine; diff --git a/src/Assets/EcsRx/Unity/Extensions/IEntityExtensions.cs b/src/Assets/EcsRx/Unity/Extensions/IEntityExtensions.cs index 25b26ea5..458d6425 100644 --- a/src/Assets/EcsRx/Unity/Extensions/IEntityExtensions.cs +++ b/src/Assets/EcsRx/Unity/Extensions/IEntityExtensions.cs @@ -1,5 +1,6 @@ using System; using EcsRx.Entities; +using EcsRx.Extensions; using EcsRx.Views.Components; using UnityEngine; @@ -7,7 +8,7 @@ namespace EcsRx.Unity.Extensions { public static class IEntityExtensions { - public static T GetComponent(this IEntity entity) where T : MonoBehaviour + public static T GetUnityComponent(this IEntity entity) where T : MonoBehaviour { if(!entity.HasComponent()) { return null; } @@ -21,7 +22,7 @@ public static T GetComponent(this IEntity entity) where T : MonoBehaviour return castView.GetComponent(); } - public static T AddComponent(this IEntity entity) where T : MonoBehaviour + public static T AddUnityComponent(this IEntity entity) where T : MonoBehaviour { if (!entity.HasComponent()) { throw new Exception("Entity has no ViewComponent, ensure a valid ViewComponent is applied with an active View"); } diff --git a/src/Assets/EcsRx/Unity/MonoBehaviours/RegisterAsEntity.cs b/src/Assets/EcsRx/Unity/MonoBehaviours/RegisterAsEntity.cs index e5f39ec9..058f18ae 100644 --- a/src/Assets/EcsRx/Unity/MonoBehaviours/RegisterAsEntity.cs +++ b/src/Assets/EcsRx/Unity/MonoBehaviours/RegisterAsEntity.cs @@ -11,6 +11,7 @@ namespace EcsRx.Unity.MonoBehaviours { + // TODO: Zenject inject issue timing public class RegisterAsEntity : MonoBehaviour { [Inject] @@ -40,7 +41,7 @@ public void RegisterEntity() { collectionToUse = CollectionManager.GetCollection(CollectionName); } var createdEntity = collectionToUse.CreateEntity(); - createdEntity.AddComponent(new ViewComponent { View = gameObject }); + createdEntity.AddComponents(new ViewComponent { View = gameObject }); SetupEntityBinding(createdEntity, collectionToUse); SetupEntityComponents(createdEntity); @@ -56,7 +57,8 @@ private void SetupEntityBinding(IEntity entity, IEntityCollection entityCollecti private void SetupEntityComponents(IEntity entity) { - for (var i = 0; i < Components.Count(); i++) + var componentsToRegister = new IComponent[Components.Count]; + for (var i = 0; i < Components.Count; i++) { var typeName = Components[i]; var type = Type.GetType(typeName); @@ -65,12 +67,12 @@ private void SetupEntityComponents(IEntity entity) var component = (IComponent)Activator.CreateInstance(type); var componentProperties = JSON.Parse(ComponentEditorState[i]); component.DeserializeComponent(componentProperties); - - entity.AddComponent(component); + componentsToRegister[i] = component; } + entity.AddComponents(componentsToRegister); } - public IEntityCollection GetPool() + public IEntityCollection GetCollection() { return CollectionManager.GetCollection(CollectionName); }