This commit is contained in:
Mikhail 2024-03-28 23:24:39 +08:00
parent d704fa2418
commit 73916a4f8d
10 changed files with 66 additions and 22 deletions

View File

@ -130,7 +130,7 @@ namespace DCFApixels.DragonECS
return;
}
_isConnectInvoked = false;
if (_entity.TryGetID(out int oldEntityID) && _world != null)
if (_world.IsNullOrDetroyed() == false && _entity.TryGetID(out int oldEntityID))
{
var unityGameObjects = _world.GetPool<GameObjectConnect>();
unityGameObjects.TryDel(oldEntityID);

View File

@ -1,5 +1,7 @@
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
@ -87,7 +89,7 @@ namespace DCFApixels.DragonECS
{
if (_world == null || _world.IsDestroyed)
{
_world = BuildWorld();
Set(BuildWorld());
OnWorldCreated(_world);
}
return _world;

View File

@ -40,9 +40,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
private void DrawEntityInfo(EcsEntityConnect[] targets)
{
bool isConnected = Target.Entity.TryUnpack(out int id, out short gen, out EcsWorld world);
bool isConnected = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
EcsGUI.EntityStatus status = IsMultipleTargets ? EcsGUI.EntityStatus.Undefined : isConnected ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive;
EcsGUI.Layout.EntityBar(status, id, gen, world.id);
EcsGUI.Layout.EntityBar(status, id, gen, worldID);
}
private void DrawTemplates()
@ -116,9 +116,12 @@ namespace DCFApixels.DragonECS.Unity.Editors
}
}
}
if (Target.Entity.TryUnpack(out int entityID, out EcsWorld world))
if (Target.Entity.TryUnpackForUnityEditor(out int entityID, out short gen, out short worldID, out EcsWorld world))
{
EcsGUI.Layout.DrawRuntimeComponents(entityID, world);
if (world.IsNullOrDetroyed() == false)
{
EcsGUI.Layout.DrawRuntimeComponents(entityID, world);
}
}
}
}

View File

@ -12,16 +12,24 @@ namespace DCFApixels.DragonECS.Unity.Editors
public override void OnInspectorGUI()
{
if (Target.IsEmpty)
EcsWorld world = Target.GetCurrentWorldRaw();
if (world == null)
{
var style = UnityEditorUtility.GetStyle(new Color32(255, 0, 75, 100));
GUILayout.Box("Is Empty", style, GUILayout.ExpandWidth(true));
}
else
{
var style = UnityEditorUtility.GetStyle(new Color32(75, 255, 0, 100));
EcsWorld world = Target.GetRaw();
GUILayout.Box($"{world.GetMeta().Name} ( {world.id} )", style, GUILayout.ExpandWidth(true));
if (world.IsDestroyed)
{
var style = UnityEditorUtility.GetStyle(new Color32(255, 75, 0, 100));
GUILayout.Box($"{world.GetMeta().Name} ( {world.id} ) Destroyed", style, GUILayout.ExpandWidth(true));
}
else
{
var style = UnityEditorUtility.GetStyle(new Color32(75, 255, 0, 100));
GUILayout.Box($"{world.GetMeta().Name} ( {world.id} )", style, GUILayout.ExpandWidth(true));
}
}
EcsGUI.Layout.DrawWorldBaseInfo(Target.GetCurrentWorldRaw());
@ -30,9 +38,9 @@ namespace DCFApixels.DragonECS.Unity.Editors
GUILayout.Space(10);
if (GUILayout.Button("Destroy"))
if (GUILayout.Button("Destroy & Clear"))
{
var w = Target.GetRaw();
var w = Target.GetCurrentWorldRaw();
if (w != null && w.IsDestroyed == false)
{
w.Destroy();

View File

@ -11,8 +11,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
public override void OnInspectorGUI()
{
bool isAlive = Target.Entity.TryUnpack(out int id, out short gen, out EcsWorld world);
EcsGUI.Layout.EntityBar(isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, id, gen, world.id);
bool isAlive = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world);
EcsGUI.Layout.EntityBar(isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, id, gen, worldID);
EcsGUI.Layout.DrawRuntimeComponents(Target.Entity, false);
}
}

View File

@ -41,18 +41,26 @@ namespace DCFApixels.DragonECS.Unity.Internal
}
public void Init()
{
if (_world == null)
{
return;
}
TypeMeta meta = _world.GetMeta();
_monitor = new GameObject($"{UnityEditorUtility.TransformToUpperName(meta.Name)} ( {_world.id} )").AddComponent<WorldMonitor>();
UnityEngine.Object.DontDestroyOnLoad(_monitor);
_monitor.Set(_world);
_monitor.gameObject.SetActive(false);
_entityMonitorsPoolRoot = new GameObject("__POOL").transform;
_entityMonitorsPoolRoot = new GameObject("__pool__").transform;
_entityMonitorsPoolRoot.SetParent(_monitor.transform);
foreach (var e in _world.Entities)
if (_world.IsNullOrDetroyed() == false)
{
InitNewEntity(e, false);
foreach (var e in _world.Entities)
{
InitNewEntity(e, false);
}
}
}
@ -65,8 +73,8 @@ namespace DCFApixels.DragonECS.Unity.Internal
{
if (Application.isPlaying)
{
UnityEngine.Object.Destroy(_monitor);
UnityEngine.Object.Destroy(_entityMonitorsPoolRoot);
UnityEngine.Object.Destroy(_monitor.gameObject);
UnityEngine.Object.Destroy(_entityMonitorsPoolRoot.gameObject);
}
_monitor = null;
_entityMonitorsPoolRoot = null;

View File

@ -29,7 +29,7 @@ namespace DCFApixels.DragonECS
bool hasTag = string.IsNullOrEmpty(tag) == false;
if (hasTag)
{
log = $".[{tag}] {v}";
log = $"[{tag}] {v}";
string taglower = tag.ToLower();
if (taglower.Contains("warning"))
{

View File

@ -293,7 +293,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
{
public static void DrawWorldBaseInfo(EcsWorld world)
{
bool isNull = world == null || world.id == 0;
bool isNull = world == null || world.IsDestroyed || world.id == 0;
int entitesCount = isNull ? 0 : world.Count;
int capacity = isNull ? 0 : world.Capacity;
int leakedEntitesCount = isNull ? 0 : world.CountLeakedEntitesDebug();
@ -321,7 +321,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
}
public static void DrawRuntimeComponents(entlong entity, bool isWithFoldout = true)
{
if (entity.TryUnpack(out int entityID, out EcsWorld world))
if (entity.TryUnpackForUnityEditor(out int entityID, out _, out _, out EcsWorld world))
{
DrawRuntimeComponents(entityID, world, isWithFoldout);
}

View File

@ -0,0 +1,12 @@
namespace DCFApixels.DragonECS.Unity.Internal
{
internal static class EntLongExtentions
{
public static bool TryUnpackForUnityEditor(this entlong self, out int id, out short gen, out short worldID, out EcsWorld world)
{
self.UnpackUnchecked(out id, out gen, out worldID);
world = EcsWorld.GetWorld(worldID);
return world.IsNullOrDetroyed() == false && self.IsAlive;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aac4ee165dbc67241a5291d47a9da9fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: