mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
update connect
This commit is contained in:
parent
c8a199d412
commit
c865955e8b
@ -7,21 +7,19 @@ using UnityEditor;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[MetaColor(MetaColor.Cyan)]
|
||||
public readonly struct UnityGameObject : IEcsComponent
|
||||
public readonly struct UnityGameObjectConnect : IEcsComponent
|
||||
{
|
||||
public readonly GameObject gameObject;
|
||||
public readonly EcsEntityConnect connect;
|
||||
public readonly Transform transform;
|
||||
|
||||
public string Name
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => gameObject.name;
|
||||
get => connect.name;
|
||||
}
|
||||
|
||||
public UnityGameObject(GameObject gameObject)
|
||||
public UnityGameObjectConnect(EcsEntityConnect connect)
|
||||
{
|
||||
this.gameObject = gameObject;
|
||||
transform = gameObject.transform;
|
||||
this.connect = connect;
|
||||
transform = connect.transform;
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +62,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
entlong result = self.NewEntityLong();
|
||||
GameObject newGameObject = new GameObject(name);
|
||||
newGameObject.AddComponent<EcsEntityConnect>().ConnectWith(result);
|
||||
newGameObject.AddComponent<EcsEntityConnect>().ConnectWith(result, false);
|
||||
#if UNITY_EDITOR
|
||||
if (icon != GameObjectIcon.NONE)
|
||||
{
|
@ -58,8 +58,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
private void InitConnect(EcsEntityConnect connect, EcsWorld world)
|
||||
{
|
||||
connect.ConnectWith(world.NewEntityLong());
|
||||
connect.ApplyTemplates();
|
||||
connect.ConnectWith(world.NewEntityLong(), true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -11,10 +11,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
private sealed class Aspect : EcsAspect
|
||||
{
|
||||
public EcsPool<UnityGameObject> unityGameObjects;
|
||||
public EcsPool<UnityGameObjectConnect> unityGameObjects;
|
||||
protected override void Init(Builder b)
|
||||
{
|
||||
unityGameObjects = b.Include<UnityGameObject>();
|
||||
unityGameObjects = b.Include<UnityGameObjectConnect>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,12 +35,12 @@ namespace DCFApixels.DragonECS
|
||||
public EcsWorld World
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _world;
|
||||
get { return _world; }
|
||||
}
|
||||
public bool IsConected
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _entity.IsAlive;
|
||||
get { return _entity.IsAlive; }
|
||||
}
|
||||
public IEnumerable<ScriptableEntityTemplate> ScriptableTemplates
|
||||
{
|
||||
@ -57,7 +57,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Connect
|
||||
public void ConnectWith(entlong entity, bool applyTemplates = false)
|
||||
public void ConnectWith(entlong entity, bool applyTemplates)
|
||||
{
|
||||
if (_entity.TryGetID(out int oldEntityID) && _world != null)
|
||||
{
|
||||
@ -66,18 +66,18 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
_world = null;
|
||||
|
||||
if (entity.TryGetID(out int newEntityID))
|
||||
if (entity.TryUnpack(out int newEntityID, out EcsWorld world))
|
||||
{
|
||||
_entity = entity;
|
||||
_world = _entity.World;
|
||||
_world = world;
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
if (!a.unityGameObjects.Has(newEntityID))
|
||||
if (a.unityGameObjects.Has(newEntityID) == false)
|
||||
{
|
||||
a.unityGameObjects.Add(newEntityID) = new UnityGameObject(gameObject);
|
||||
a.unityGameObjects.Add(newEntityID) = new UnityGameObjectConnect(this);
|
||||
}
|
||||
if (applyTemplates)
|
||||
{
|
||||
ApplyTemplates();
|
||||
ApplyTemplatesFor(world.id, newEntityID);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -88,19 +88,15 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region ApplyTemplates
|
||||
public void ApplyTemplates()
|
||||
{
|
||||
ApplyTemplatesFor(_entity.ID);
|
||||
}
|
||||
public void ApplyTemplatesFor(int entityID)
|
||||
public void ApplyTemplatesFor(short worldID, int entityID)
|
||||
{
|
||||
foreach (var template in _scriptableTemplates)
|
||||
{
|
||||
template.Apply(_world.id, entityID);
|
||||
template.Apply(worldID, entityID);
|
||||
}
|
||||
foreach (var template in _monoTemplates)
|
||||
{
|
||||
template.Apply(_world.id, entityID);
|
||||
template.Apply(worldID, entityID);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -123,7 +119,7 @@ namespace DCFApixels.DragonECS
|
||||
[ContextMenu("Unlink Entity")]
|
||||
internal void UnlinkEntity_Editor()
|
||||
{
|
||||
ConnectWith(entlong.NULL);
|
||||
ConnectWith(entlong.NULL, false);
|
||||
}
|
||||
[ContextMenu("Delete Entity")]
|
||||
internal void DeleteEntity_Editor()
|
||||
|
Loading…
Reference in New Issue
Block a user