Compare commits

...

4 Commits

Author SHA1 Message Date
DCFApixels
760c789acb Update RuntimeComponentsDrawer.cs 2025-05-09 23:41:33 +08:00
DCFApixels
09f7c6103d Update RuntimeComponentsDrawer.cs 2025-05-09 22:18:23 +08:00
DCFApixels
236eb3d2bb Update RuntimeComponentsDrawer.cs 2025-05-09 19:51:07 +08:00
DCFApixels
a7f269a0f2 update EntitySlotInfo 2025-05-09 19:45:01 +08:00
4 changed files with 43 additions and 25 deletions

View File

@ -1,4 +1,5 @@
#if UNITY_EDITOR
using DCFApixels.DragonECS.Core.Unchecked;
using DCFApixels.DragonECS.Unity.Internal;
using System.Reflection;
using UnityEditor;
@ -50,7 +51,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
SerializedProperty fulleProperty = property.FindPropertyRelative("_full");
EntitySlotInfo entity = new EntitySlotInfo(fulleProperty.longValue);
EcsWorld.TryGetWorld(entity.world, out EcsWorld world);
EcsWorld.TryGetWorld(entity.worldID, out EcsWorld world);
if (drawFoldout && isExpanded)
{

View File

@ -1,4 +1,5 @@
#if UNITY_EDITOR
using DCFApixels.DragonECS.Core.Unchecked;
using DCFApixels.DragonECS.Unity.Editors.X;
using DCFApixels.DragonECS.Unity.Internal;
using System.Collections.Generic;

View File

@ -1,5 +1,6 @@
#if UNITY_EDITOR
using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Core.Unchecked;
using DCFApixels.DragonECS.Unity.Internal;
using System;
using System.Collections.Generic;
@ -592,11 +593,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
public static void EntityField(Rect position, DragonGUIContent label, EntitySlotInfo entity)
{
bool isAlive = false;
if (EcsWorld.TryGetWorld(entity.world, out EcsWorld world))
if (EcsWorld.TryGetWorld(entity.worldID, out EcsWorld world))
{
isAlive = world.IsAlive(entity.id, entity.gen);
}
EntityField_Internal(position, label, entity.id == 0, isAlive ? EntityStatus.Alive : EntityStatus.NotAlive, entity.id, entity.gen, entity.world);
EntityField_Internal(position, label, entity.id == 0, isAlive ? EntityStatus.Alive : EntityStatus.NotAlive, entity.id, entity.gen, entity.worldID);
}
public static void EntityField(Rect position, SerializedProperty property)
{
@ -613,11 +614,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
else
{
bool isAlive = false;
if (EcsWorld.TryGetWorld(entity.world, out EcsWorld world))
if (EcsWorld.TryGetWorld(entity.worldID, out EcsWorld world))
{
isAlive = world.IsAlive(entity.id, entity.gen);
}
EntityField_Internal(position, label, entity.id == 0, isAlive ? EntityStatus.Alive : EntityStatus.NotAlive, entity.id, entity.gen, entity.world);
EntityField_Internal(position, label, entity.id == 0, isAlive ? EntityStatus.Alive : EntityStatus.NotAlive, entity.id, entity.gen, entity.worldID);
}
}

View File

@ -27,8 +27,9 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
//_runtimeComponentReflectionCaches.Clear();
}
private const int RuntimeComponentsMaxDepth = 2;
private const int RuntimeComponentsDepthRoot = -1;
private static RuntimeComponentsDrawer[] _drawers;
private static int _runtimeComponentsDepth = 2;
private static int _runtimeComponentsDepth = RuntimeComponentsDepthRoot;
static RuntimeComponentsDrawer()
{
_drawers = new RuntimeComponentsDrawer[RuntimeComponentsMaxDepth + 1];
@ -65,6 +66,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
public readonly bool IsUnityObjectType;
public readonly bool IsUnitySerializable;
public readonly bool IsCompositeType;
public readonly bool IsUnmanaged;
public readonly FieldInfoData[] Fields;
@ -89,7 +91,12 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
//type.IsPrimitive ||
//type == typeof(string) ||
//type.IsEnum ||
(!type.IsGenericType && type.IsSerializable && type.HasAttribute<System.SerializableAttribute>());
(!type.IsGenericType && type.HasAttribute<System.SerializableAttribute>() && type.IsArray == false);
IsCompositeType =
type.IsPrimitive == false &&
type.IsArray == false &&
type != typeof(string);
if (type == typeof(void)) { return; }
@ -162,9 +169,9 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
#region draw world component
public static void DrawWorldComponents(EcsWorld world)
{
if (_runtimeComponentsDepth == 0)
if (_runtimeComponentsDepth == RuntimeComponentsDepthRoot)
{
_drawers[_runtimeComponentsDepth].DrawWorldComponents_Internal(world);
_drawers[0].DrawWorldComponents_Internal(world);
}
}
private void DrawWorldComponents_Internal(EcsWorld world)
@ -242,16 +249,22 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
{
if (isRoot)
{
_runtimeComponentsDepth = 0;
_runtimeComponentsDepth = RuntimeComponentsDepthRoot;
}
else
{
_runtimeComponentsDepth++;
}
try
{
_drawers[_runtimeComponentsDepth].DrawRuntimeComponents(entityID, world, isWithFoldout);
}
finally
{
_runtimeComponentsDepth--;
if (_runtimeComponentsDepth < RuntimeComponentsDepthRoot)
{
_runtimeComponentsDepth = RuntimeComponentsDepthRoot;
}
}
}
private void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout)
{
@ -372,9 +385,12 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
bool changed = false;
if (cache.IsUnitySerializable == false)
if (cache.IsUnitySerializable == false && cache.IsCompositeType)
{
isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(isExpanded, label, EditorStyles.foldout);
var foldoutStyle = EditorStyles.foldout;
Rect rect = GUILayoutUtility.GetRect(label, foldoutStyle);
rect.xMin += EcsGUI.Indent;
isExpanded = EditorGUI.BeginFoldoutHeaderGroup(rect, isExpanded, label, foldoutStyle, null, null);
EditorGUILayout.EndFoldoutHeaderGroup();
if (isExpanded)
@ -394,8 +410,8 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
}
}
}
}
}
}
else
@ -430,22 +446,21 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
else
{
EditorGUI.BeginChangeCheck();
RefEditorWrapper wrapper = cache.GetWrapper(_runtimeComponentsDepth);
wrapper.data = data;
wrapper.SO.Update();
wrapper.IsExpanded = isExpanded;
try
{
if (fieldInfoData.IsPassToUnitySerialize)
if (cache.IsCompositeType && fieldInfoData.IsPassToUnitySerialize)
{
wrapper.SO.Update();
wrapper.IsExpanded = isExpanded;
EditorGUILayout.PropertyField(wrapper.Property, label, true);
}
else
{
EditorGUILayout.LabelField(label, " ");
//EcsGUI.
EditorGUILayout.LabelField(label);
}
}
catch (ArgumentException)