From 8e4656a879c9b85308290da912c098d0f7da6d56 Mon Sep 17 00:00:00 2001 From: Niikelion Date: Thu, 26 Dec 2024 23:14:01 +0100 Subject: [PATCH] fixed UseMemo and debugger --- Editor/Debugging/Debugger.cs | 19 ++++++++++++------- Runtime/ComponentState.cs | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Editor/Debugging/Debugger.cs b/Editor/Debugging/Debugger.cs index a940eda..adb714d 100644 --- a/Editor/Debugging/Debugger.cs +++ b/Editor/Debugging/Debugger.cs @@ -132,7 +132,7 @@ IComponent WithContent(CompositionContext.InspectedNode[] r) => IComponent WithoutContent() => Text("No panel selected"); } - + private static IComponent StatePanel() => WithState(() => { var node = Remember(null); @@ -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 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(); @@ -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(() => diff --git a/Runtime/ComponentState.cs b/Runtime/ComponentState.cs index 241a8dc..30f31fb 100644 --- a/Runtime/ComponentState.cs +++ b/Runtime/ComponentState.cs @@ -111,7 +111,10 @@ public static T UseMemo(CompositionContext.FactoryDelegate 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; }