mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-17 17:34:34 +08:00
update conncetors
This commit is contained in:
parent
c865955e8b
commit
3f1c38a510
@ -6,6 +6,33 @@ using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public static class EcsConnect
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Connect(GameObject go, entlong entity, bool applyTemplates)
|
||||
{
|
||||
Connect(entity, go, applyTemplates);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Connect(entlong entity, GameObject go, bool applyTemplates)
|
||||
{
|
||||
if (go.TryGetComponent(out EcsEntityConnect connect) == false)
|
||||
{
|
||||
connect = go.AddComponent<EcsEntityConnect>();
|
||||
}
|
||||
connect.ConnectWith(entity, applyTemplates);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Connect(EcsEntityConnect connect, entlong entity, bool applyTemplates)
|
||||
{
|
||||
Connect(entity, connect, applyTemplates);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Connect(entlong entity, EcsEntityConnect connect, bool applyTemplates)
|
||||
{
|
||||
connect.ConnectWith(entity, applyTemplates);
|
||||
}
|
||||
}
|
||||
[DisallowMultipleComponent]
|
||||
public class EcsEntityConnect : MonoBehaviour
|
||||
{
|
||||
@ -37,7 +64,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _world; }
|
||||
}
|
||||
public bool IsConected
|
||||
public bool IsConnected
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _entity.IsAlive; }
|
||||
@ -59,22 +86,23 @@ namespace DCFApixels.DragonECS
|
||||
#region Connect
|
||||
public void ConnectWith(entlong entity, bool applyTemplates)
|
||||
{
|
||||
if (_entity.TryGetID(out int oldEntityID) && _world != null)
|
||||
{
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
a.unityGameObjects.TryDel(oldEntityID);
|
||||
}
|
||||
_world = null;
|
||||
Disconnect();
|
||||
|
||||
if (entity.TryUnpack(out int newEntityID, out EcsWorld world))
|
||||
{
|
||||
_entity = entity;
|
||||
_world = world;
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
if (a.unityGameObjects.Has(newEntityID) == false)
|
||||
if (a.unityGameObjects.Has(newEntityID))
|
||||
{
|
||||
a.unityGameObjects.Add(newEntityID) = new UnityGameObjectConnect(this);
|
||||
ref readonly var uconnect = ref a.unityGameObjects.Read(newEntityID);
|
||||
if (uconnect.IsConnected)
|
||||
{
|
||||
uconnect.connect.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
a.unityGameObjects.TryAddOrGet(newEntityID) = new UnityGameObjectConnect(this);
|
||||
if (applyTemplates)
|
||||
{
|
||||
ApplyTemplatesFor(world.id, newEntityID);
|
||||
@ -85,6 +113,15 @@ namespace DCFApixels.DragonECS
|
||||
_entity = entlong.NULL;
|
||||
}
|
||||
}
|
||||
public void Disconnect()
|
||||
{
|
||||
if (_entity.TryGetID(out int oldEntityID) && _world != null)
|
||||
{
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
a.unityGameObjects.TryDel(oldEntityID);
|
||||
}
|
||||
_world = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ApplyTemplates
|
||||
|
@ -109,7 +109,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
if (targets[i].IsConected == true)
|
||||
if (targets[i].IsConnected == true)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Multiple component editing is not available.", MessageType.Warning);
|
||||
return;
|
||||
|
@ -14,9 +14,19 @@ namespace DCFApixels.DragonECS
|
||||
public string Name
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => connect.name;
|
||||
get { return connect.name; }
|
||||
}
|
||||
public UnityGameObjectConnect(EcsEntityConnect connect)
|
||||
public bool IsUnidirectional
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return connect == null; }
|
||||
}
|
||||
public bool IsConnected
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return transform != null; }
|
||||
}
|
||||
internal UnityGameObjectConnect(EcsEntityConnect connect)
|
||||
{
|
||||
this.connect = connect;
|
||||
transform = connect.transform;
|
@ -2,9 +2,7 @@
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -181,7 +179,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
GUI.EndScrollView();
|
||||
|
||||
Rect r = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);
|
||||
if(_selectedPointMeta.process != null && _selectedPointMeta.system != null)
|
||||
if (_selectedPointMeta.process != null && _selectedPointMeta.system != null)
|
||||
{
|
||||
GUI.Label(r, $"{_selectedPointMeta.process.Name}-{_selectedPointMeta.system.Name}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user