From 9ae79b830739f234f3f968d858c88524773eb8a2 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 20 Jan 2021 11:13:09 +0100 Subject: [PATCH] Add IFunctionDependantNode for Visject nodes --- Source/Editor/Surface/Archetypes/Function.cs | 52 ++++++++++++++++++- .../Editor/Surface/IFunctionDependantNode.cs | 31 +++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 Source/Editor/Surface/IFunctionDependantNode.cs diff --git a/Source/Editor/Surface/Archetypes/Function.cs b/Source/Editor/Surface/Archetypes/Function.cs index 7c4963072..b7584a2b8 100644 --- a/Source/Editor/Surface/Archetypes/Function.cs +++ b/Source/Editor/Surface/Archetypes/Function.cs @@ -1387,6 +1387,9 @@ namespace FlaxEditor.Surface.Archetypes } } + /// + /// The cached signature. This might not be loaded if called from other not initialization (eg. node initialized before this function node). Then use GetSignature method. + /// internal Signature _signature; /// @@ -1395,6 +1398,13 @@ namespace FlaxEditor.Surface.Archetypes { } + public void GetSignature(out Signature signature) + { + if (_signature.Node == null) + LoadSignature(); + signature = _signature; + } + private void SaveSignature() { using (var stream = new MemoryStream()) @@ -1568,6 +1578,13 @@ namespace FlaxEditor.Surface.Archetypes // Update node interface UpdateUI(); + + // Send event + for (int i = 0; i < Surface.Nodes.Count; i++) + { + if (Surface.Nodes[i] is IFunctionsDependantNode node) + node.OnFunctionEdited(this); + } }; editor.Show(this, Vector2.Zero); } @@ -1622,6 +1639,13 @@ namespace FlaxEditor.Surface.Archetypes base.OnLoaded(); LoadSignature(); + + // Send event + for (int i = 0; i < Surface.Nodes.Count; i++) + { + if (Surface.Nodes[i] is IFunctionsDependantNode node) + node.OnFunctionCreated(this); + } } /// @@ -1639,6 +1663,26 @@ namespace FlaxEditor.Surface.Archetypes // Start editing OnEditSignature(); + + // Send event + for (int i = 0; i < Surface.Nodes.Count; i++) + { + if (Surface.Nodes[i] is IFunctionsDependantNode node) + node.OnFunctionCreated(this); + } + } + + /// + public override void OnDeleted() + { + // Send event + for (int i = 0; i < Surface.Nodes.Count; i++) + { + if (Surface.Nodes[i] is IFunctionsDependantNode node) + node.OnFunctionDeleted(this); + } + + base.OnDeleted(); } /// @@ -1647,6 +1691,13 @@ namespace FlaxEditor.Surface.Archetypes base.OnValuesChanged(); LoadSignature(); + + // Send event + for (int i = 0; i < Surface.Nodes.Count; i++) + { + if (Surface.Nodes[i] is IFunctionsDependantNode node) + node.OnFunctionEdited(this); + } } /// @@ -1752,7 +1803,6 @@ namespace FlaxEditor.Surface.Archetypes { private bool _isTypesChangedEventRegistered; - /// public SetFieldNode(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch) : base(id, context, nodeArch, groupArch) { diff --git a/Source/Editor/Surface/IFunctionDependantNode.cs b/Source/Editor/Surface/IFunctionDependantNode.cs new file mode 100644 index 000000000..e66c10e92 --- /dev/null +++ b/Source/Editor/Surface/IFunctionDependantNode.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +using FlaxEngine; + +namespace FlaxEditor.Surface +{ + /// + /// Interface for surface nodes that depend on surface function nodes collection. + /// + [HideInEditor] + public interface IFunctionsDependantNode + { + /// + /// On function created. + /// + /// The function node. + void OnFunctionCreated(SurfaceNode node); + + /// + /// On function signature changed (new name or parameters change). + /// + /// The function node. + void OnFunctionEdited(SurfaceNode node); + + /// + /// On function removed. + /// + /// The function node. + void OnFunctionDeleted(SurfaceNode node); + } +}