From baf64aaa98f80a1838850f65f7d7688a1c09d549 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Mon, 16 Sep 2019 20:02:37 +1000 Subject: [PATCH 1/2] FlowchartWindow force clears filteredBlocks during target Flowchart change - better handles switching scenes and to and from play mode - warns user when nulls are found --- .../Fungus/Scripts/Editor/FlowchartWindow.cs | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs index 6988869f..270496c6 100644 --- a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs @@ -336,6 +336,7 @@ namespace Fungus.EditorUtils if (flowchart == null) { blocks = new Block[0]; + filteredBlocks = new Block[0]; } else { @@ -347,6 +348,8 @@ namespace Fungus.EditorUtils protected virtual void OnInspectorUpdate() { + if (HandleFlowchartSelectionChange()) return; + // Ensure the Block Inspector is always showing the currently selected block var flowchart = GetFlowchart(); if (flowchart == null || AnyNullBLocks()) @@ -450,13 +453,22 @@ namespace Fungus.EditorUtils { filterStale = false; //reset all - foreach (var item in filteredBlocks) + for (int i = 0; filteredBlocks != null && i < filteredBlocks.Length; i++) + { + if(filteredBlocks[i] != null) + { + filteredBlocks[i].IsFiltered = false; + } + } + + var nullCount = filteredBlocks.Count(x => x == null); + if (nullCount > 0 && nullCount != filteredBlocks.Length) { - item.IsFiltered = false; + Debug.LogWarning("Null block found in filteredBlocks. May be a symptom of an underlying issue"); } //gather new - filteredBlocks = blocks.Where(block => block.BlockName.ToLower().Contains(searchString.ToLower())).ToArray(); + filteredBlocks = blocks.Where(block => block.BlockName.IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0).ToArray(); //update filteredness foreach (var item in filteredBlocks) @@ -573,9 +585,16 @@ namespace Fungus.EditorUtils { mouseDownSelectionState.AddRange(flowchart.SelectedBlocks); flowchart.ClearSelectedBlocks(); - foreach (var item in mouseDownSelectionState) + for (int i = 0; i < mouseDownSelectionState.Count; i++) { - item.IsControlSelected = true; + if (mouseDownSelectionState[i] != null) + { + mouseDownSelectionState[i].IsControlSelected = true; + } + else + { + Debug.LogWarning("Null block found in mouseDownSelectionState. May be a symptom of an underlying issue"); + } } } @@ -633,6 +652,17 @@ namespace Fungus.EditorUtils blockInspector = null; prevFlowchart = flowchart; executingBlocks.ClearAll(); + + //attempt to defilter previous, if due to scene change these will be null + // the regular filter updates will still occur within UpdateBlockCollection + for (int i = 0; i < filteredBlocks.Length; i++) + { + if (filteredBlocks[i] != null) + { + filteredBlocks[i].IsFiltered = false; + } + } + UpdateBlockCollection(); Repaint(); return true; From 89381e1a91df569741e8c7884d7cb4f2d61ab418 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Mon, 7 Oct 2019 12:27:27 +1000 Subject: [PATCH 2/2] Force FlowchartWindow and BlockInspector to be refreshed when moving between and playmodes in editor -and restore selected blocks from edit, to play, back to edit --- Assets/Fungus/Scripts/Components/Flowchart.cs | 13 +++++++++++- .../Fungus/Scripts/Editor/BlockInspector.cs | 6 ++++++ .../Fungus/Scripts/Editor/FlowchartWindow.cs | 21 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index 9dcb3b82..b4071dad 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -1186,7 +1186,18 @@ namespace Fungus var res = gameObject.GetComponents(); selectedBlocks = res.Where(x => x.IsSelected).ToList(); } - + + public void ReverseUpdateSelectedCache() + { + for (int i = 0; i < selectedBlocks.Count; i++) + { + if(selectedBlocks[i] != null) + { + selectedBlocks[i].IsSelected = true; + } + } + } + /// /// Reset the commands and variables in the Flowchart. /// diff --git a/Assets/Fungus/Scripts/Editor/BlockInspector.cs b/Assets/Fungus/Scripts/Editor/BlockInspector.cs index 1ef5a062..05b51806 100644 --- a/Assets/Fungus/Scripts/Editor/BlockInspector.cs +++ b/Assets/Fungus/Scripts/Editor/BlockInspector.cs @@ -93,6 +93,12 @@ namespace Fungus.EditorUtils return; } + //if there is no selection but we are drawing, fix that + if (flowchart.SelectedBlocks.Count == 0) + { + flowchart.AddSelectedBlock(block); + } + if (activeBlockEditor == null || !block.Equals(activeBlockEditor.target)) { diff --git a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs index 270496c6..c053cd9a 100644 --- a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs @@ -264,13 +264,30 @@ namespace Fungus.EditorUtils EditorApplication.update += OnEditorUpdate; Undo.undoRedoPerformed += Undo_ForceRepaint; + +#if UNITY_2017_4_OR_NEWER + EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; +#endif } protected virtual void OnDisable() { EditorApplication.update -= OnEditorUpdate; Undo.undoRedoPerformed -= Undo_ForceRepaint; +#if UNITY_2017_4_OR_NEWER + EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; +#endif + } + +#if UNITY_2017_4_OR_NEWER + private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) + { + //force null so it can refresh context on the other side of the context + flowchart = null; + prevFlowchart = null; + blockInspector = null; } +#endif protected void Undo_ForceRepaint() { @@ -664,6 +681,10 @@ namespace Fungus.EditorUtils } UpdateBlockCollection(); + + if(flowchart != null) + flowchart.ReverseUpdateSelectedCache();//becomes reverse restore selected cache + Repaint(); return true; }