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);
int i = 0; if (_componentPoolsBuffer == null)
foreach (var componentTypeID in componentTypeIDs)
{ {
var pool = world.FindPoolInstance(componentTypeID); _componentPoolsBuffer = new List<IEcsPool>(64);
{ }
DrawRuntimeComponent(componentTypeIDs.Length, i++, entityID, pool); world.GetComponentPoolsFor(entityID, _componentPoolsBuffer);
} int i = 0;
int iMax = _componentPoolsBuffer.Count;
foreach (var componentPool in _componentPoolsBuffer)
{
DrawRuntimeComponent(entityID, componentPool, iMax, i++);
} }
} }
} }
} }
private static void DrawRuntimeComponent(int total, int index, int entityID, IEcsPool pool) private static void DrawRuntimeComponent(int entityID, IEcsPool pool, int total, int index)
{ {
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,18 +1196,19 @@ namespace DCFApixels.DragonECS.Unity.Editors
if (isExpanded) if (isExpanded)
{ {
EditorGUI.indentLevel++; using (UpIndentLevel())
foreach (var field in type.GetFields(fieldFlags))
{ {
GUIContent subLabel = UnityEditorUtility.GetLabel(UnityEditorUtility.TransformFieldName(field.Name)); foreach (var field in type.GetFields(fieldFlags))
if (DrawRuntimeData(field.FieldType, subLabel, expandMatrix, field.GetValue(data), out object fieldData))
{ {
field.SetValue(data, fieldData); GUIContent subLabel = UnityEditorUtility.GetLabel(UnityEditorUtility.TransformFieldName(field.Name));
outData = data; if (DrawRuntimeData(field.FieldType, subLabel, expandMatrix, field.GetValue(data), out object fieldData))
changed = true; {
field.SetValue(data, fieldData);
outData = data;
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;