Skip to content

Commit

Permalink
fixed UseMemo and debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
Niikelion committed Dec 26, 2024
1 parent 6b49b8b commit 8e4656a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Editor/Debugging/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ IComponent WithContent(CompositionContext.InspectedNode[] r) =>

IComponent WithoutContent() => Text("No panel selected");
}

private static IComponent StatePanel() => WithState(() =>
{
var node = Remember<CompositionContext.InspectedNode>(null);
Expand Down Expand Up @@ -165,15 +165,20 @@ IComponent FullPanel([NotNull] CompositionContext.InspectedNode n)
);
}

IComponent Value(IMutableValue value, int i) =>
Row(Text($"{i}:"), ValueInspector(value)).Id(i+1);
IComponent Value(IMutableValue value, int i)
{
return Row(Text($"{i}:"), ValueInspector(value)).Id(i + 1);
}

IComponent Context(KeyValuePair<Type, object> context, int i) =>
Row(Text($"{context.Key.FullName}:"), ValueInspector(context.Value)).Id(i+1);
});

private static IComponent ValueInspector(object value) => WithState(() =>
{
var property = RememberF(() =>
//TODO: https://docs.unity3d.com/6000.0/Documentation/Manual/UIE-runtime-binding-define-data-source.html
//TODO: use above guide to show editor for custom types without creating ScriptableObject instance
var property = UseMemo(() =>
{
var instance = CreateInstance<GenericProperty>();

Expand All @@ -182,17 +187,17 @@ private static IComponent ValueInspector(object value) => WithState(() =>
var serializedObject = new SerializedObject(instance);

return serializedObject.FindProperty("property");
});
}, value);

ComponentState.OnDestroy(() =>
{
if (Thread.CurrentThread != mainThread)
return;

DestroyImmediate(property.Value.serializedObject.targetObject);
DestroyImmediate(property.serializedObject.targetObject);
});

return Property(property.Value);
return Property(property);
});

private static IComponent RenderNode(CompositionContext.InspectedNode node, int level = 0) => WithState(() =>
Expand Down
3 changes: 3 additions & 0 deletions Runtime/ComponentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ public static T UseMemo<T>(CompositionContext.FactoryDelegate<T> factory, params
var oldResult = RememberRefF(factory);

if (oldVars.Value.Length != vars.Length || !oldVars.Value.Zip(vars, Equals).All(v => v))
{
oldResult.Value = factory();
oldVars.Value = vars;
}

return oldResult.Value;
}
Expand Down

0 comments on commit 8e4656a

Please sign in to comment.