From 17cd4cde4efb90aaa908284085eb9fd9b2431cd7 Mon Sep 17 00:00:00 2001 From: desktop-maesty/steve Date: Sun, 20 May 2018 21:13:27 +1000 Subject: [PATCH] Try Catch around VarListLayout so we can eat the error that occurs when moving from play back to edit --- .../Fungus/Scripts/Editor/FlowchartWindow.cs | 12 +++++--- .../Scripts/Editor/VariableListAdaptor.cs | 30 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs index fcd84cc3..1006ffa7 100644 --- a/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Scripts/Editor/FlowchartWindow.cs @@ -347,7 +347,7 @@ namespace Fungus.EditorUtils GUILayout.Label("No Flowchart scene object selected"); return; } - + //target has changed, so clear the blockinspector if (flowchart != prevFlowchart) { @@ -514,10 +514,14 @@ namespace Fungus.EditorUtils if (variableListAdaptor != null) { - if (variableListAdaptor.TargetFlowchart == null) - variableListAdaptor = null; - else + if (variableListAdaptor.TargetFlowchart != null) + { variableListAdaptor.DrawVarList(0); + } + else + { + variableListAdaptor = null; + } } if(EditorGUI.EndChangeCheck()) diff --git a/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs b/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs index 0471fd53..8af7048c 100644 --- a/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs @@ -42,7 +42,7 @@ namespace Fungus.EditorUtils else return this[index].objectReferenceValue as Variable; } - + public VariableListAdaptor(SerializedProperty arrayProperty, Flowchart _targetFlowchart) { if (arrayProperty == null) @@ -138,19 +138,29 @@ namespace Fungus.EditorUtils public void DrawVarList(int w) { - _arrayProperty.serializedObject.Update(); - this.widthOfList = (w == 0 ? VariableListAdaptor.DefaultWidth : w) - ScrollSpacer; - - if(GUILayout.Button("Variables")) + //we want to eat the throw that occurs when switching back to editor from play + try { - _arrayProperty.isExpanded = !_arrayProperty.isExpanded; - } + if (_arrayProperty == null || _arrayProperty.serializedObject == null) + return; + + _arrayProperty.serializedObject.Update(); + this.widthOfList = (w == 0 ? VariableListAdaptor.DefaultWidth : w) - ScrollSpacer; + + if (GUILayout.Button("Variables")) + { + _arrayProperty.isExpanded = !_arrayProperty.isExpanded; + } - if (_arrayProperty.isExpanded) + if (_arrayProperty.isExpanded) + { + list.DoLayoutList(); + } + _arrayProperty.serializedObject.ApplyModifiedProperties(); + } + catch (Exception) { - list.DoLayoutList(); } - _arrayProperty.serializedObject.ApplyModifiedProperties(); } public void DrawItem(Rect position, int index, bool selected, bool focused)