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