Delete the composite constructor heuristic from the inspector
Operator ruling: the heuristic that rebuilt unkeyed structs through a guessed constructor is removed, not guarded. Gone: the Composite value kind, CultInspectorShape.Composer, CultInspectorModel.Compose and Composite, the composite-component flag on CultInspectorMember, the IMGUI composite rebuild path, and the README text about it. An unkeyed struct is now edited in place through its public fields. A struct holding state it cannot write in place (a public readonly field or a get-only auto-property) is Unsupported with a reason naming the member, until a drawer claims it. Computed get-only properties are not state and do not lock a struct. The composite-rejection test goes with the heuristic; the replacement test pins both lock rules and fails with either removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
2a46409017
commit
d03e376411
4 changed files with 53 additions and 117 deletions
|
|
@ -84,8 +84,6 @@ namespace GameCult.Unity.Caching.Editor
|
|||
case CultInspectorValueKind.Enum:
|
||||
var current = value as Enum ?? (Enum)Enum.ToObject(type, 0);
|
||||
return type.IsDefined(typeof(FlagsAttribute), false) ? EditorGUILayout.EnumFlagsField(label, current) : EditorGUILayout.EnumPopup(label, current);
|
||||
case CultInspectorValueKind.Composite:
|
||||
return DrawComposite(label, shape, value);
|
||||
case CultInspectorValueKind.RecordRef:
|
||||
return DrawRecordRef(label, type, value);
|
||||
case CultInspectorValueKind.List:
|
||||
|
|
@ -189,55 +187,6 @@ namespace GameCult.Unity.Caching.Editor
|
|||
}
|
||||
}
|
||||
|
||||
// Scalar components draw on one row; anything else folds out. A change composes a new value.
|
||||
private object DrawComposite(string label, CultInspectorShape shape, object value)
|
||||
{
|
||||
var path = _path;
|
||||
value = value ?? Model.CreateDefault(shape.Type);
|
||||
var components = shape.Members;
|
||||
var values = components.Select(component => component.GetValue(value)).ToArray();
|
||||
var changed = false;
|
||||
if (components.All(component => Model.ShapeOf(component.ValueType).Kind is CultInspectorValueKind.Float or CultInspectorValueKind.Integer or CultInspectorValueKind.Bool))
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel(label);
|
||||
var indent = EditorGUI.indentLevel;
|
||||
var labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUIUtility.labelWidth = 8 + 7 * components.Max(component => component.Name.Length);
|
||||
for (var i = 0; i < components.Count; i++)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var next = DrawDefault(components[i].Name, components[i].ValueType, values[i], null);
|
||||
if (!EditorGUI.EndChangeCheck()) continue;
|
||||
values[i] = next;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
EditorGUI.indentLevel = indent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Foldout(path, label)) return value;
|
||||
EditorGUI.indentLevel++;
|
||||
for (var i = 0; i < components.Count; i++)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var next = DrawValue(LabelOf(components[i]), components[i].ValueType, values[i], components[i].Member, path + "." + components[i].Name);
|
||||
if (!EditorGUI.EndChangeCheck()) continue;
|
||||
values[i] = next;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
return changed ? Model.Compose(shape, values) : value;
|
||||
}
|
||||
|
||||
private object DrawRecordRef(string label, Type type, object value)
|
||||
{
|
||||
var key = CultInspectorModel.RecordKey(value);
|
||||
|
|
|
|||
Loading…
Reference in a new issue