refactoring

This commit is contained in:
Mikhail 2024-10-03 08:20:46 +08:00
parent e2286a877e
commit b25c752c7f

View File

@ -1079,9 +1079,11 @@ namespace DCFApixels.DragonECS.Unity.Editors
DrawRuntimeComponents(entityID, world, isWithFoldout); DrawRuntimeComponents(entityID, world, isWithFoldout);
} }
} }
[ThreadStatic]
private static List<IEcsPool> _componentPoolsBuffer;
public static void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout = true) public static void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout = true)
{ {
var componentTypeIDs = world.GetComponentTypeIDsFor(entityID);
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f))) using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f)))
{ {
@ -1100,26 +1102,27 @@ namespace DCFApixels.DragonECS.Unity.Editors
GUILayout.Box("", UnityEditorUtility.GetStyle(GUI.color, 0.16f), GUILayout.ExpandWidth(true)); GUILayout.Box("", UnityEditorUtility.GetStyle(GUI.color, 0.16f), GUILayout.ExpandWidth(true));
IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden); IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden);
if (_componentPoolsBuffer == null)
{
_componentPoolsBuffer = new List<IEcsPool>(64);
}
world.GetComponentPoolsFor(entityID, _componentPoolsBuffer);
int i = 0; int i = 0;
foreach (var componentTypeID in componentTypeIDs) int iMax = _componentPoolsBuffer.Count;
foreach (var componentPool in _componentPoolsBuffer)
{ {
var pool = world.FindPoolInstance(componentTypeID); DrawRuntimeComponent(entityID, componentPool, iMax, i++);
{
DrawRuntimeComponent(componentTypeIDs.Length, i++, entityID, pool);
} }
} }
} }
} }
} private static void DrawRuntimeComponent(int entityID, IEcsPool pool, int total, int index)
private static void DrawRuntimeComponent(int total, int index, int entityID, IEcsPool pool)
{ {
var meta = pool.ComponentType.ToMeta(); var meta = pool.ComponentType.ToMeta();
if (meta.IsHidden == false || IsShowHidden) if (meta.IsHidden == false || IsShowHidden)
{ {
object data = pool.GetRaw(entityID); object data = pool.GetRaw(entityID);
Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
Type componentType = pool.ComponentType; Type componentType = pool.ComponentType;
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType); ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
@ -1136,7 +1139,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
isExpanded = !isExpanded; isExpanded = !isExpanded;
} }
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(panelColor, EscEditorConsts.COMPONENT_DRAWER_ALPHA)); Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE).SetAlpha(EscEditorConsts.COMPONENT_DRAWER_ALPHA);
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(panelColor));
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
//Close button //Close button
@ -1192,7 +1196,8 @@ namespace DCFApixels.DragonECS.Unity.Editors
if (isExpanded) if (isExpanded)
{ {
EditorGUI.indentLevel++; using (UpIndentLevel())
{
foreach (var field in type.GetFields(fieldFlags)) foreach (var field in type.GetFields(fieldFlags))
{ {
GUIContent subLabel = UnityEditorUtility.GetLabel(UnityEditorUtility.TransformFieldName(field.Name)); GUIContent subLabel = UnityEditorUtility.GetLabel(UnityEditorUtility.TransformFieldName(field.Name));
@ -1203,7 +1208,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
changed = true; changed = true;
} }
} }
EditorGUI.indentLevel--; }
} }
} }
else else
@ -1226,6 +1231,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
{ {
uobj = go.GetComponent(fieldType); uobj = go.GetComponent(fieldType);
} }
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
outData = uobj; outData = uobj;