Skip to content

Commit

Permalink
Merge pull request #7 from voody2506/develop
Browse files Browse the repository at this point in the history
New Conversion Method
  • Loading branch information
voody2506 authored Nov 9, 2021
2 parents 891b1f0 + 50b1496 commit 24feae7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
26 changes: 24 additions & 2 deletions Runtime/MonoHelpers/ConvertToEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/World/Systems/WorldInitSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 24feae7

Please sign in to comment.