Skip to content

Commit

Permalink
[v0.2.0] Cleaning; AuthoringAspect improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed May 30, 2024
1 parent b96595d commit 42a3b75
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 19 deletions.
3 changes: 0 additions & 3 deletions Runtime/Attributes.meta

This file was deleted.

33 changes: 32 additions & 1 deletion Runtime/Components/AuthoringAspect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Depra.Ecs.Hybrid.Internal;
using Depra.Ecs.Worlds;
using UnityEngine;
using static Depra.Ecs.Hybrid.Module;
Expand All @@ -12,8 +13,15 @@ namespace Depra.Ecs.Hybrid.Components
[AddComponentMenu(MENU_PATH + nameof(AuthoringAspect), DEFAULT_ORDER)]
public sealed class AuthoringAspect : MonoBehaviour, IAuthoring
{
[Tooltip("GameObjects with IAuthoring components to be baked.")]
[SerializeField] private GameObject _scope;

[Tooltip("What to do with the scope after baking.\n" +
"None - do nothing,\n" +
"Destroy Object - destroy this component and the scope,\n" +
"Destroy Component - destroy this components and all IAuthoring components on the scope.")]
[SerializeField] private DestructionMode _destructionMode;

public IEnumerable<IAuthoring> Scoped => _scope
? _scope.GetComponents<IAuthoring>()
: Array.Empty<IAuthoring>();
Expand All @@ -31,7 +39,30 @@ void IBaker.Bake(IAuthoring authoring, World world)
foreach (var component in _aspect.Scoped)
{
component.CreateBaker().Bake(authoring, world);
Destroy((Component) component);
if (_aspect._destructionMode == DestructionMode.DESTROY_COMPONENT)
{
Destroy((Component) component);
}
}

FinalizeConversion();
}

private void FinalizeConversion()
{
switch (_aspect._destructionMode)
{
case DestructionMode.NONE:
break;
case DestructionMode.DESTROY_OBJECT:
Destroy(_aspect);
Destroy(_aspect._scope);
break;
case DestructionMode.DESTROY_COMPONENT:
Destroy(_aspect);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Entities/AuthoringEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Linq;
using Depra.Ecs.Entities;
using Depra.Ecs.Hybrid.Components;
using Depra.Ecs.QoL.Components;
using Depra.Ecs.Hybrid.Internal;
using Depra.Ecs.QoL.Entities;
using Depra.Ecs.QoL.Worlds;
using Depra.Ecs.Unity;
Expand All @@ -33,7 +33,7 @@ private void OnEnable()
}

var world = UnityWorlds.Instance.Default;
world.Pools.Get<BakingEntityRef>().Allocate(world.CreateEntity()).Value = gameObject;
world.Pool<BakingEntityRef>().Allocate(world.CreateEntity()).Value = gameObject;
}

public IEnumerable<IAuthoring> Nested => GetComponents<IAuthoring>()
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Internal.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace Depra.Ecs.Hybrid.Entities
namespace Depra.Ecs.Hybrid.Internal
{
internal enum DestructionMode
{
Expand Down
File renamed without changes.
21 changes: 12 additions & 9 deletions Runtime/Systems/ContinuousBakingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using Depra.Ecs.Components;
using Depra.Ecs.Entities;
using Depra.Ecs.Hybrid.Entities;
using Depra.Ecs.QoL.Components;
using Depra.Ecs.QoL.Entities;
using Depra.Ecs.QoL.Worlds;
using Depra.Ecs.Systems;
using Depra.Ecs.Worlds;
#if ENABLE_IL2CPP
Expand All @@ -26,19 +26,22 @@ public sealed class ContinuousBakingSystem : IPreInitializationSystem, IExecutio
void IPreInitializationSystem.PreInitialize(IWorldGroup worlds)
{
var world = worlds.Default;
_bakingEntities = world.Pools.Get<BakingEntityRef>();
_bakingEntities = world.Pool<BakingEntityRef>();
_entities = new EntityQuery(typeof(BakingEntityRef)).Initialize(world);
}

void IExecutionSystem.Execute(float frameTime) => _entities.ForEach(entity =>
void IExecutionSystem.Execute(float frameTime)
{
var bakingObject = _bakingEntities[entity].Value;
if (bakingObject && bakingObject.TryGetComponent(out IAuthoringEntity authoring))
foreach (var entity in _entities)
{
authoring.CreateBaker().Bake(authoring, _bakingEntities.World);
}
var bakingObject = _bakingEntities[entity].Value;
if (bakingObject && bakingObject.TryGetComponent(out IAuthoringEntity authoring))
{
authoring.CreateBaker().Bake(authoring, _bakingEntities.World);
}

_bakingEntities.World.DeleteEntity(entity);
});
_bakingEntities.World.DeleteEntity(entity);
}
}
}
}
2 changes: 1 addition & 1 deletion Runtime/Worlds/RuntimeSceneBakeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Depra.Ecs.Hybrid.Worlds
{
public readonly struct RuntimeSceneBakeModule : IModule
public sealed class RuntimeSceneBakeModule : IModule
{
IEnumerable<IModule> IModule.Modules => Array.Empty<IModule>();

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "com.depra.ecs.hybrid",
"version": "0.1.11",
"version": "0.2.0",
"displayName": "Depra.Ecs.Hybrid",
"description": "Unity Conversion Workflow for Depra.Ecs. Easy convert GameObjects to Entity.",
"unity": "2022.3",
"license": "Apache-2.0",
"dependencies": {
"com.depra.ecs.unity": "0.2.6",
"com.depra.ecs.unity": "0.2.7",
"com.depra.serialize-reference.extensions": "0.0.14"
},
"keywords": [
Expand Down

0 comments on commit 42a3b75

Please sign in to comment.