diff --git a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/EditorWindowValues.cs b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/EditorWindowValues.cs index 9bb2b860..48818c70 100644 --- a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/EditorWindowValues.cs +++ b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/EditorWindowValues.cs @@ -1,5 +1,6 @@ using System; using UnityEngine.UIElements; +using Object = UnityEngine.Object; namespace CrashKonijn.Goap.Editor { @@ -8,8 +9,9 @@ public class EditorWindowValues public int Zoom { get; set; } = 100; public VisualElement RootElement { get; set; } public DragDrawer DragDrawer { get; set; } - public UnityEngine.Object SelectedObject { get; set; } - + public Object SelectedObject { get; set; } + public bool ShowConfig { get; set; } + public void UpdateZoom(int zoom) { if (zoom > 0) @@ -17,16 +19,17 @@ public void UpdateZoom(int zoom) this.Zoom = Math.Min(100, this.Zoom + zoom); return; } - + this.Zoom = Math.Max(50, this.Zoom + zoom); } public delegate void UpdateEvent(); + public event UpdateEvent OnUpdate; - + public void Update() { this.OnUpdate?.Invoke(); } } -} \ No newline at end of file +} diff --git a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/GraphViewerEditorWindow.cs b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/GraphViewerEditorWindow.cs index 586da556..e2570647 100644 --- a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/GraphViewerEditorWindow.cs +++ b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/GraphViewerEditorWindow.cs @@ -26,6 +26,8 @@ private static void ShowWindow() private void OnPlayModeChange(PlayModeStateChange obj) { + this.values.ShowConfig = obj != PlayModeStateChange.EnteredPlayMode; + this.OnSelectionChange(); } diff --git a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/NodeElement.cs b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/NodeElement.cs index 90a90848..1fe2a5ee 100644 --- a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/NodeElement.cs +++ b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/NodeElement.cs @@ -114,20 +114,20 @@ public NodeElement(INode graphNode, VisualElement bezierRoot, EditorWindowValues if (graphNode.Action is IGoapAction goapAction) { this.TargetCircle.SetColor(this.GetCircleColor(goapAction, null)); - this.Target.text = $"Target: {goapAction.Config.Target?.GetType().GetGenericTypeName()}"; + this.Target.text = this.Target.text = this.GetTargetText(values, null, goapAction); this.Cost.text = $"Cost: {goapAction.Config.BaseCost}"; } + } - this.Effects = new VisualElement(); - this.Effects.AddToClassList("effects"); - this.Effects.Add(new Label("Effects")); - this.Node.Add(this.Effects); + this.Effects = new VisualElement(); + this.Effects.AddToClassList("effects"); + this.Effects.Add(new Label("Effects")); + this.Node.Add(this.Effects); - foreach (var effect in graphNode.Effects) - { - var effectElement = new EffectElement(effect); - this.Effects.Add(effectElement); - } + foreach (var effect in graphNode.Effects) + { + var effectElement = new EffectElement(effect); + this.Effects.Add(effectElement); } this.schedule.Execute(() => @@ -144,21 +144,34 @@ public NodeElement(INode graphNode, VisualElement bezierRoot, EditorWindowValues if (!provider.isActiveAndEnabled) return; - this.UpdateClasses(graphNode, provider); + this.UpdateClasses(values, graphNode, provider); this.Cost.text = $"Cost: {graphNode.GetCost(provider):0.00}"; if (graphNode.Action is IGoapAction action) { this.TargetCircle.SetColor(this.GetCircleColor(action, provider)); - var target = provider.WorldData.GetTarget(action); - var targetText = target != null ? target.Position.ToString() : "null"; - - this.Target.text = $"Target: {targetText}"; + this.Target.text = this.GetTargetText(values, provider, action); } }).Every(33); } + private string GetTargetText(EditorWindowValues values, IMonoGoapActionProvider provider, IGoapAction action) + { + var targetConfig = action.Config.Target?.GetType().GetGenericTypeName(); + + if (!Application.isPlaying || provider == null) + return $"Target: {targetConfig}"; + + var target = provider.WorldData.GetTarget(action); + var targetText = target != null ? target.Position.ToString() : "null"; + + if (values.ShowConfig) + return $"Target: {targetText} ({targetConfig})"; + + return $"Target: {targetText}"; + } + private Color GetCircleColor(IGoapAction goapAction, IMonoGoapActionProvider provider) { if (!Application.isPlaying) @@ -173,11 +186,17 @@ private Color GetCircleColor(IGoapAction goapAction, IMonoGoapActionProvider pro return Color.green; } - private void UpdateClasses(INode graphNode, IMonoGoapActionProvider provider) + private void UpdateClasses(EditorWindowValues values, INode graphNode, IMonoGoapActionProvider provider) { this.Node.RemoveFromClassList("active"); this.Node.RemoveFromClassList("disabled"); this.Node.RemoveFromClassList("path"); + this.Node.RemoveFromClassList("hide-effects"); + + if (!values.ShowConfig) + { + this.Node.AddToClassList("hide-effects"); + } if (provider.CurrentPlan?.Goal == this.GraphNode.Action) { diff --git a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/ToolbarElement.cs b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/ToolbarElement.cs index 4ddae133..195bddcc 100644 --- a/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/ToolbarElement.cs +++ b/Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/ToolbarElement.cs @@ -13,9 +13,9 @@ public ToolbarElement(EditorWindowValues values) Selection.activeObject = values.SelectedObject; }) { - text = values.SelectedObject.name + text = values.SelectedObject.name, }); - + this.Add(new ToolbarButton(() => { var elementsWithClass = values.RootElement.Query(className: "node").ToList(); @@ -26,9 +26,9 @@ public ToolbarElement(EditorWindowValues values) } }) { - text = "collapse" + text = "collapse", }); - + this.Add(new ToolbarButton(() => { var elementsWithClass = values.RootElement.Query(className: "node").ToList(); @@ -39,26 +39,38 @@ public ToolbarElement(EditorWindowValues values) } }) { - text = "open" + text = "open", }); - + + ToolbarButton configToggle = null; + configToggle = new ToolbarButton(() => + { + values.ShowConfig = !values.ShowConfig; + configToggle.text = values.ShowConfig ? "Config (true)" : "Config (false)"; + }) + { + text = "toggle config", + }; + + this.Add(configToggle); + var spacer = new VisualElement(); spacer.style.flexGrow = 1; // This makes the spacer flexible, filling available space this.Add(spacer); - + this.Add(new ToolbarButton(() => { values.UpdateZoom(10); }) { - text = "+" + text = "+", }); this.Add(new ToolbarButton(() => { values.UpdateZoom(-10); }) { - text = "-" + text = "-", }); this.Add(new ToolbarButton(() => { @@ -66,8 +78,8 @@ public ToolbarElement(EditorWindowValues values) values.DragDrawer.Reset(); }) { - text = "reset" + text = "reset", }); } } -} \ No newline at end of file +} diff --git a/Package/Editor/CrashKonijn.Goap.Editor/Styles/GraphViewer.uss b/Package/Editor/CrashKonijn.Goap.Editor/Styles/GraphViewer.uss index b486e760..a5107dd3 100644 --- a/Package/Editor/CrashKonijn.Goap.Editor/Styles/GraphViewer.uss +++ b/Package/Editor/CrashKonijn.Goap.Editor/Styles/GraphViewer.uss @@ -26,7 +26,11 @@ border-width: 2px; } -.node.collapsed .effects { +.node.hide-effects .effects { + display: none; +} + +.node.collapsed .effects{ /*min-height: 40px;*/ max-height: 0; margin: 0;