Browse Source

Executing icon fade is now based on absolute time (no update required)

Also moved handling of setting these timers to the FlowchartWindow
class, except for one specific case that’s better handled from the
Block class.
master
chrisgregan 10 years ago
parent
commit
7b7c33952f
  1. 8
      Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs
  2. 22
      Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs
  3. 9
      Assets/Fungus/Flowchart/Scripts/Block.cs

8
Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs

@ -362,7 +362,7 @@ namespace Fungus
GUI.Label(commandLabelRect, commandName, commandLabelStyle); GUI.Label(commandLabelRect, commandName, commandLabelStyle);
} }
if (command.executingIconTimer > 0f) if (command.executingIconTimer > Time.realtimeSinceStartup)
{ {
Rect iconRect = new Rect(commandLabelRect); Rect iconRect = new Rect(commandLabelRect);
iconRect.x += iconRect.width - commandLabelRect.width - 20; iconRect.x += iconRect.width - commandLabelRect.width - 20;
@ -371,8 +371,10 @@ namespace Fungus
Color storeColor = GUI.color; Color storeColor = GUI.color;
GUI.color = new Color(1f, 1f, 1f, command.executingIconTimer / Block.executingIconFadeTime); float alpha = (command.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime;
command.executingIconTimer = Mathf.Max(0, command.executingIconTimer - Time.deltaTime); alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(1f, 1f, 1f, alpha);
GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle()); GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle());
GUI.color = storeColor; GUI.color = storeColor;

22
Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs

@ -24,8 +24,6 @@ namespace Fungus
protected static BlockInspector blockInspector; protected static BlockInspector blockInspector;
public const float playIconFadeTime = 0.5f;
protected bool mouseOverVariables = false; protected bool mouseOverVariables = false;
protected int forceRepaintCount; protected int forceRepaintCount;
@ -318,34 +316,34 @@ namespace Fungus
// Draw play icons beside all executing blocks // Draw play icons beside all executing blocks
if (Application.isPlaying) 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; forceRepaintCount = 6;
} }
if (s.executingIconTimer > 0f) if (b.executingIconTimer > Time.realtimeSinceStartup)
{ {
s.executingIconTimer = Mathf.Max(s.executingIconTimer - Time.deltaTime, 0f); Rect rect = new Rect(b.nodeRect);
Rect rect = new Rect(s.nodeRect);
rect.x += flowchart.scrollPos.x - 37; rect.x += flowchart.scrollPos.x - 37;
rect.y += flowchart.scrollPos.y + 3; rect.y += flowchart.scrollPos.y + 3;
rect.width = 34; rect.width = 34;
rect.height = 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); GUI.color = new Color(1f, 1f, 1f, alpha);
} }
if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle())) if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle()))
{ {
SelectBlock(flowchart, s); SelectBlock(flowchart, b);
} }
GUI.color = Color.white; GUI.color = Color.white;

9
Assets/Fungus/Flowchart/Scripts/Block.cs

@ -61,6 +61,9 @@ namespace Fungus
protected int executionCount; protected int executionCount;
/**
* Duration of fade for executing icon displayed beside blocks & commands.
*/
public const float executingIconFadeTime = 0.5f; public const float executingIconFadeTime = 0.5f;
/** /**
@ -203,7 +206,6 @@ namespace Fungus
Command command = commandList[i]; Command command = commandList[i];
activeCommand = command; activeCommand = command;
executingIconTimer = executingIconFadeTime;
if (flowchart.gameObject.activeInHierarchy) if (flowchart.gameObject.activeInHierarchy)
{ {
@ -217,13 +219,14 @@ namespace Fungus
} }
command.isExecuting = true; 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(); command.Execute();
// Wait until the executing command sets another command to jump to via Command.Continue() // Wait until the executing command sets another command to jump to via Command.Continue()
while (jumpToCommandIndex == -1) while (jumpToCommandIndex == -1)
{ {
command.executingIconTimer = executingIconFadeTime;
yield return null; yield return null;
} }

Loading…
Cancel
Save