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