diff --git a/Runtime/MonoHelpers/ConvertToEntity.cs b/Runtime/MonoHelpers/ConvertToEntity.cs index c08738a..b251492 100644 --- a/Runtime/MonoHelpers/ConvertToEntity.cs +++ b/Runtime/MonoHelpers/ConvertToEntity.cs @@ -9,14 +9,17 @@ namespace Voody.UniLeo.Lite public enum ConvertMode { ConvertAndInject, - ConvertAndDestroy + ConvertAndDestroy, + ConvertAndSave } public class ConvertToEntity : MonoBehaviour { [SerializeField] private ConvertMode convertMode; // Conversion Mode of ECS [SerializeField] private String customWorld; // World Type of ECS - + private EcsPackedEntity packedEntity; + private EcsWorld spawnWorld; + private void Start() { var world = WorldHandler.GetMainWorld(); // Getting Main World from ECS @@ -39,5 +42,24 @@ public ConvertMode GetConvertMode() { return convertMode; } + + public int? TryGetEntity() + { + if (spawnWorld != null) + { + int entity; + if (packedEntity.Unpack(spawnWorld, out entity)) + { + return entity; + } + } + return null; + } + + public void Set(int entity, EcsWorld world) + { + spawnWorld = world; + packedEntity = EcsEntityExtensions.PackEntity(world, entity); + } } } \ No newline at end of file diff --git a/Runtime/World/Systems/WorldInitSystem.cs b/Runtime/World/Systems/WorldInitSystem.cs index ecd8a03..5b68080 100644 --- a/Runtime/World/Systems/WorldInitSystem.cs +++ b/Runtime/World/Systems/WorldInitSystem.cs @@ -82,6 +82,9 @@ private void AddEntity(GameObject gameObject, EcsSystems systems, String worldNa case ConvertMode.ConvertAndInject: GameObject.Destroy(convertComponent); break; + case ConvertMode.ConvertAndSave: + convertComponent.Set(entity, spawnWorld); + break; } } } diff --git a/package.json b/package.json index 235a265..932dcca 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "UniLeo-Lite", "description": "Unity Conversion Workflow for Leopotam ECS Lite. Easy convert GameObjects to Entity.", "unity": "2019.1", - "version": "1.0.1", + "version": "1.1.0", "keywords": [ "leoecs", "ecs",