mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
update EcsEntityConnect add GetConnectByInstanceID
This commit is contained in:
parent
87f70d9927
commit
784b743b2a
@ -4,6 +4,7 @@ using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
#region UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
#endregion
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
@ -52,6 +53,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
|
||||
[SelectionBase]
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu(EcsConsts.FRAMEWORK_NAME + "/" + nameof(EcsEntityConnect), 30)]
|
||||
public class EcsEntityConnect : MonoBehaviour
|
||||
@ -59,6 +61,8 @@ namespace DCFApixels.DragonECS
|
||||
private entlong _entity;
|
||||
private EcsWorld _world;
|
||||
|
||||
private static SparseArray<EcsEntityConnect> _connectedEntities = new SparseArray<EcsEntityConnect>();
|
||||
|
||||
[SerializeField]
|
||||
private bool _deleteEntiityWithDestroy = false;
|
||||
[SerializeField]
|
||||
@ -108,6 +112,7 @@ namespace DCFApixels.DragonECS
|
||||
_isConnectInvoked = true;
|
||||
_entity = entity;
|
||||
_world = world;
|
||||
_connectedEntities.Add(GetInstanceID(), this);
|
||||
var goConnects = world.GetPool<GameObjectConnect>();
|
||||
if (goConnects.Has(newEntityID))
|
||||
{
|
||||
@ -136,6 +141,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
var unityGameObjects = _world.GetPool<GameObjectConnect>();
|
||||
unityGameObjects.TryDel(oldEntityID);
|
||||
_connectedEntities.Remove(GetInstanceID());
|
||||
}
|
||||
_world = null;
|
||||
_entity = entlong.NULL;
|
||||
@ -161,10 +167,35 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
entlong ent = _entity;
|
||||
Disconnect();
|
||||
if (_deleteEntiityWithDestroy && ent.TryUnpack(out int id, out EcsWorld world))
|
||||
|
||||
|
||||
if (_deleteEntiityWithDestroy == false)
|
||||
{
|
||||
world.DelEntity(id);
|
||||
return;
|
||||
}
|
||||
ent.UnpackUnchecked(out int e, out short gen, out short worldID);
|
||||
var world = EcsWorld.GetWorld(worldID);
|
||||
if (world != null && world.IsAlive(e, gen))
|
||||
{
|
||||
world.DelEntity(e);
|
||||
}
|
||||
|
||||
|
||||
//if (_deleteEntiityWithDestroy && ent.TryUnpack(out int id, out EcsWorld world))
|
||||
//{
|
||||
// world.DelEntity(id);
|
||||
//}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
public static EcsEntityConnect GetConnectByInstanceID(int instanceID)
|
||||
{
|
||||
return _connectedEntities[instanceID];
|
||||
}
|
||||
public static bool TryGetConnectByInstanceID(int instanceID, out EcsEntityConnect conncet)
|
||||
{
|
||||
return _connectedEntities.TryGetValue(instanceID, out conncet);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if(property.propertyType == SerializedPropertyType.ManagedReference == false)
|
||||
if (property.propertyType == SerializedPropertyType.ManagedReference == false)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, label);
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int index = componentsProp.arraySize;
|
||||
componentsProp.InsertArrayElementAtIndex(index);
|
||||
componentsProp.GetArrayElementAtIndex(index).managedReferenceValue = ((IComponentTemplate)obj).Clone();
|
||||
@ -107,7 +108,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
DrawComponentData(componentsProp.GetArrayElementAtIndex(i), componentsProp.arraySize, i);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
private void DrawTop(ITemplateInternal target)
|
||||
|
Loading…
Reference in New Issue
Block a user