From 7b7c33952ff101f9a70f03443da58b820a8fe94c Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 14 Apr 2015 09:44:47 +0100 Subject: [PATCH] Executing icon fade is now based on absolute time (no update required) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also moved handling of setting these timers to the FlowchartWindow class, except for one specific case that’s better handled from the Block class. --- .../Flowchart/Editor/CommandListAdaptor.cs | 8 ++++--- .../Flowchart/Editor/FlowchartWindow.cs | 22 +++++++++---------- Assets/Fungus/Flowchart/Scripts/Block.cs | 9 +++++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs index 7b8eda2e..f4898e24 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs @@ -362,7 +362,7 @@ namespace Fungus GUI.Label(commandLabelRect, commandName, commandLabelStyle); } - if (command.executingIconTimer > 0f) + if (command.executingIconTimer > Time.realtimeSinceStartup) { Rect iconRect = new Rect(commandLabelRect); iconRect.x += iconRect.width - commandLabelRect.width - 20; @@ -371,8 +371,10 @@ namespace Fungus Color storeColor = GUI.color; - GUI.color = new Color(1f, 1f, 1f, command.executingIconTimer / Block.executingIconFadeTime); - command.executingIconTimer = Mathf.Max(0, command.executingIconTimer - Time.deltaTime); + float alpha = (command.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; + alpha = Mathf.Clamp01(alpha); + + GUI.color = new Color(1f, 1f, 1f, alpha); GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle()); GUI.color = storeColor; diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs index ee867c8c..9e1aeb51 100755 --- a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs @@ -24,8 +24,6 @@ namespace Fungus protected static BlockInspector blockInspector; - public const float playIconFadeTime = 0.5f; - protected bool mouseOverVariables = false; protected int forceRepaintCount; @@ -318,34 +316,34 @@ namespace Fungus // Draw play icons beside all executing blocks if (Application.isPlaying) { - foreach (Block s in blocks) + foreach (Block b in blocks) { - if (s.IsExecuting()) + if (b.IsExecuting()) { - s.executingIconTimer = playIconFadeTime; + b.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; + b.activeCommand.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; forceRepaintCount = 6; } - if (s.executingIconTimer > 0f) + if (b.executingIconTimer > Time.realtimeSinceStartup) { - s.executingIconTimer = Mathf.Max(s.executingIconTimer - Time.deltaTime, 0f); - - Rect rect = new Rect(s.nodeRect); + Rect rect = new Rect(b.nodeRect); rect.x += flowchart.scrollPos.x - 37; rect.y += flowchart.scrollPos.y + 3; rect.width = 34; rect.height = 34; - if (!s.IsExecuting() && s.executingIconTimer < playIconFadeTime) + if (!b.IsExecuting()) { - float alpha = s.executingIconTimer / playIconFadeTime; + float alpha = (b.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; + alpha = Mathf.Clamp01(alpha); GUI.color = new Color(1f, 1f, 1f, alpha); } if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle())) { - SelectBlock(flowchart, s); + SelectBlock(flowchart, b); } GUI.color = Color.white; diff --git a/Assets/Fungus/Flowchart/Scripts/Block.cs b/Assets/Fungus/Flowchart/Scripts/Block.cs index f89d2053..481a740e 100644 --- a/Assets/Fungus/Flowchart/Scripts/Block.cs +++ b/Assets/Fungus/Flowchart/Scripts/Block.cs @@ -61,6 +61,9 @@ namespace Fungus protected int executionCount; + /** + * Duration of fade for executing icon displayed beside blocks & commands. + */ public const float executingIconFadeTime = 0.5f; /** @@ -203,7 +206,6 @@ namespace Fungus Command command = commandList[i]; activeCommand = command; - executingIconTimer = executingIconFadeTime; if (flowchart.gameObject.activeInHierarchy) { @@ -217,13 +219,14 @@ namespace Fungus } command.isExecuting = true; - command.executingIconTimer = executingIconFadeTime; + // This icon timer is managed by the FlowchartWindow class, but we also need to + // set it here in case a command starts and finishes execution before the next window update. + command.executingIconTimer = Time.realtimeSinceStartup + executingIconFadeTime; command.Execute(); // Wait until the executing command sets another command to jump to via Command.Continue() while (jumpToCommandIndex == -1) { - command.executingIconTimer = executingIconFadeTime; yield return null; }