mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
update connectors
This commit is contained in:
parent
7b31c7d0ba
commit
7b94683522
@ -61,6 +61,8 @@ namespace DCFApixels.DragonECS
|
||||
[SerializeField]
|
||||
private MonoEntityTemplate[] _monoTemplates;
|
||||
|
||||
private bool _isConnected = false;
|
||||
|
||||
#region Properties
|
||||
public entlong Entity
|
||||
{
|
||||
@ -98,34 +100,36 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
if (entity.TryUnpack(out int newEntityID, out EcsWorld world))
|
||||
{
|
||||
_isConnected = true;
|
||||
_entity = entity;
|
||||
_world = world;
|
||||
var unityGameObjects = _world.GetPool<UnityGameObjectConnect>();
|
||||
if (unityGameObjects.Has(newEntityID))
|
||||
var goConnects = world.GetPool<GameObjectConnect>();
|
||||
if (goConnects.Has(newEntityID))
|
||||
{
|
||||
ref readonly var uconnect = ref unityGameObjects.Read(newEntityID);
|
||||
if (uconnect.IsConnected)
|
||||
ref readonly var goConnect = ref goConnects.Read(newEntityID);
|
||||
if (goConnect.IsConnected)
|
||||
{
|
||||
uconnect.connect.Disconnect();
|
||||
goConnect.Connect.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
unityGameObjects.TryAddOrGet(newEntityID) = new UnityGameObjectConnect(this);
|
||||
goConnects.TryAddOrGet(newEntityID) = new GameObjectConnect(this);
|
||||
if (applyTemplates)
|
||||
{
|
||||
ApplyTemplatesFor(world.id, newEntityID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_entity = entlong.NULL;
|
||||
}
|
||||
}
|
||||
public void Disconnect()
|
||||
{
|
||||
if(_isConnected == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_isConnected = false;
|
||||
if (_entity.TryGetID(out int oldEntityID) && _world != null)
|
||||
{
|
||||
var unityGameObjects = _world.GetPool<UnityGameObjectConnect>();
|
||||
var unityGameObjects = _world.GetPool<GameObjectConnect>();
|
||||
unityGameObjects.TryDel(oldEntityID);
|
||||
}
|
||||
_world = null;
|
||||
|
@ -7,35 +7,29 @@ using UnityEditor;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[MetaColor(MetaColor.Cyan)]
|
||||
public readonly struct UnityGameObjectConnect : IEcsComponent, IEcsComponentLifecycle<UnityGameObjectConnect>
|
||||
public readonly struct GameObjectConnect : IEcsComponent, IEcsComponentLifecycle<GameObjectConnect>
|
||||
{
|
||||
public readonly EcsEntityConnect connect;
|
||||
public readonly Transform transform;
|
||||
public string Name
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return connect.name; }
|
||||
}
|
||||
public readonly EcsEntityConnect Connect;
|
||||
public bool IsConnected
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return connect != null; }
|
||||
get { return Connect != null; }
|
||||
}
|
||||
internal UnityGameObjectConnect(EcsEntityConnect connect)
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal GameObjectConnect(EcsEntityConnect connect)
|
||||
{
|
||||
this.connect = connect;
|
||||
transform = connect.transform;
|
||||
Connect = connect;
|
||||
}
|
||||
|
||||
void IEcsComponentLifecycle<UnityGameObjectConnect>.Enable(ref UnityGameObjectConnect component)
|
||||
void IEcsComponentLifecycle<GameObjectConnect>.Enable(ref GameObjectConnect component)
|
||||
{
|
||||
component = default;
|
||||
}
|
||||
void IEcsComponentLifecycle<UnityGameObjectConnect>.Disable(ref UnityGameObjectConnect component)
|
||||
void IEcsComponentLifecycle<GameObjectConnect>.Disable(ref GameObjectConnect component)
|
||||
{
|
||||
if (component.connect != null)
|
||||
if (component.Connect != null)
|
||||
{
|
||||
component.connect.Disconnect();
|
||||
component.Connect.Disconnect();
|
||||
}
|
||||
component = default;
|
||||
}
|
||||
@ -69,7 +63,7 @@ namespace DCFApixels.DragonECS
|
||||
Diamond_Red,
|
||||
Diamond_Purple
|
||||
}
|
||||
public static class GameObjectIconConsts
|
||||
internal static class GameObjectIconConsts
|
||||
{
|
||||
public const int RAW_LABEL_ICON_LAST = (int)GameObjectIcon.Label_Purple;
|
||||
}
|
Loading…
Reference in New Issue
Block a user