Browse Source

Merge pull request #289 from FungusGames/stop-flowchart

Stop flowchart
master
Chris Gregan 9 years ago
parent
commit
a446aad38e
  1. 5
      Assets/Fungus/Camera/Scripts/Commands/FadeToView.cs
  2. 5
      Assets/Fungus/Camera/Scripts/Commands/MoveToView.cs
  3. 7
      Assets/Fungus/Flowchart/Scripts/Block.cs
  4. 17
      Assets/Fungus/Flowchart/Scripts/Command.cs
  5. 2
      Assets/Fungus/Flowchart/Scripts/Commands/Call.cs
  6. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Else.cs
  7. 4
      Assets/Fungus/Flowchart/Scripts/Commands/ElseIf.cs
  8. 6
      Assets/Fungus/Flowchart/Scripts/Commands/If.cs
  9. 4
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs
  10. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Stop.cs
  11. 56
      Assets/Fungus/Flowchart/Scripts/Commands/StopFlowchart.cs
  12. 12
      Assets/Fungus/Flowchart/Scripts/Commands/StopFlowchart.cs.meta
  13. 15
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  14. 11
      Assets/Fungus/Narrative/Scripts/Commands/Say.cs
  15. 23
      Assets/Fungus/UI/Scripts/Commands/Write.cs
  16. 5
      Assets/Fungus/UI/Scripts/Writer.cs
  17. 1278
      Assets/Tests/Scripting/Scripting.unity
  18. 14
      ProjectSettings/ProjectSettings.asset
  19. 2
      ProjectSettings/ProjectVersion.txt

5
Assets/Fungus/Camera/Scripts/Commands/FadeToView.cs

@ -66,6 +66,11 @@ namespace Fungus
} }
} }
public override void OnStopExecuting()
{
CameraController.GetInstance().StopAllCoroutines();
}
public override string GetSummary() public override string GetSummary()
{ {
if (targetView == null) if (targetView == null)

5
Assets/Fungus/Camera/Scripts/Commands/MoveToView.cs

@ -46,6 +46,11 @@ namespace Fungus
} }
} }
public override void OnStopExecuting()
{
CameraController.GetInstance().StopAllCoroutines();
}
public override string GetSummary() public override string GetSummary()
{ {
if (targetView == null) if (targetView == null)

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

@ -237,6 +237,13 @@ namespace Fungus
public virtual void Stop() public virtual void Stop()
{ {
// Tell the executing command to stop immediately
if (activeCommand != null)
{
activeCommand.isExecuting = false;
activeCommand.OnStopExecuting();
}
// This will cause the execution loop to break on the next iteration // This will cause the execution loop to break on the next iteration
jumpToCommandIndex = int.MaxValue; jumpToCommandIndex = int.MaxValue;
} }

17
Assets/Fungus/Flowchart/Scripts/Command.cs

@ -83,7 +83,11 @@ namespace Fungus
public virtual void Continue() public virtual void Continue()
{ {
Continue(commandIndex + 1); // This is a noop if the Block has already been stopped
if (isExecuting)
{
Continue(commandIndex + 1);
}
} }
public virtual void Continue(int nextCommandIndex) public virtual void Continue(int nextCommandIndex)
@ -95,7 +99,7 @@ namespace Fungus
} }
} }
public virtual void Stop() public virtual void StopParentBlock()
{ {
OnExit(); OnExit();
if (parentBlock != null) if (parentBlock != null)
@ -104,6 +108,15 @@ namespace Fungus
} }
} }
/**
* Called when the parent block has been requested to stop executing, and
* this command is the currently executing command.
* Use this callback to terminate any asynchronous operations and
* cleanup state so that the command is ready to execute again later on.
*/
public virtual void OnStopExecuting()
{}
/** /**
* Called when the new command is added to a block in the editor. * Called when the new command is added to a block in the editor.
*/ */

2
Assets/Fungus/Flowchart/Scripts/Commands/Call.cs

@ -75,7 +75,7 @@ namespace Fungus
if (callMode == CallMode.Stop) if (callMode == CallMode.Stop)
{ {
Stop(); StopParentBlock();
} }
else if (callMode == CallMode.Continue) else if (callMode == CallMode.Continue)
{ {

4
Assets/Fungus/Flowchart/Scripts/Commands/Else.cs

@ -20,7 +20,7 @@ namespace Fungus
// Stop if this is the last command in the list // Stop if this is the last command in the list
if (commandIndex >= parentBlock.commandList.Count - 1) if (commandIndex >= parentBlock.commandList.Count - 1)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -43,7 +43,7 @@ namespace Fungus
} }
// No End command found // No End command found
Stop(); StopParentBlock();
} }
public override bool OpenBlock() public override bool OpenBlock()

4
Assets/Fungus/Flowchart/Scripts/Commands/ElseIf.cs

@ -31,7 +31,7 @@ namespace Fungus
// Stop if this is the last command in the list // Stop if this is the last command in the list
if (commandIndex >= parentBlock.commandList.Count - 1) if (commandIndex >= parentBlock.commandList.Count - 1)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -54,7 +54,7 @@ namespace Fungus
} }
// No End command found // No End command found
Stop(); StopParentBlock();
} }
} }

6
Assets/Fungus/Flowchart/Scripts/Commands/If.cs

@ -97,7 +97,7 @@ namespace Fungus
// Last command in block // Last command in block
if (commandIndex >= parentBlock.commandList.Count) if (commandIndex >= parentBlock.commandList.Count)
{ {
Stop(); StopParentBlock();
return; return;
} }
@ -128,7 +128,7 @@ namespace Fungus
if (i >= parentBlock.commandList.Count - 1) if (i >= parentBlock.commandList.Count - 1)
{ {
// Last command in Block, so stop // Last command in Block, so stop
Stop(); StopParentBlock();
} }
else else
{ {
@ -147,7 +147,7 @@ namespace Fungus
} }
// No matching End command found, so just stop the block // No matching End command found, so just stop the block
Stop(); StopParentBlock();
} }
public override string GetSummary() public override string GetSummary()

4
Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs

@ -1,4 +1,4 @@
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
@ -120,7 +120,7 @@ namespace Fungus
} }
else if(callMode == Call.CallMode.Stop) else if(callMode == Call.CallMode.Stop)
{ {
Stop(); StopParentBlock();
} }
} }
} }

4
Assets/Fungus/Flowchart/Scripts/Commands/Stop.cs

@ -6,13 +6,13 @@ namespace Fungus
{ {
[CommandInfo("Flow", [CommandInfo("Flow",
"Stop", "Stop",
"Stop executing the current Flowchart.")] "Stop executing the Block that contains this command.")]
[AddComponentMenu("")] [AddComponentMenu("")]
public class Stop : Command public class Stop : Command
{ {
public override void OnEnter() public override void OnEnter()
{ {
Stop(); StopParentBlock();
} }
public override Color GetButtonColor() public override Color GetButtonColor()

56
Assets/Fungus/Flowchart/Scripts/Commands/StopFlowchart.cs

@ -0,0 +1,56 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Fungus
{
[CommandInfo("Flow",
"Stop Flowchart",
"Stops execution of all Blocks in a Flowchart")]
[AddComponentMenu("")]
public class StopFlowchart : Command
{
[Tooltip("Stop all executing Blocks in the Flowchart that contains this command")]
public bool stopParentFlowchart;
[Tooltip("Stop all executing Blocks in a list of target Flowcharts")]
public List<Flowchart> targetFlowcharts = new List<Flowchart>();
public override void OnEnter()
{
Flowchart flowchart = GetFlowchart();
if (stopParentFlowchart)
{
flowchart.StopAllBlocks();
}
foreach (Flowchart f in targetFlowcharts)
{
if (f == flowchart)
{
// Flowchart has already been stopped
continue;
}
f.StopAllBlocks();
}
}
public override bool IsReorderableArray(string propertyName)
{
if (propertyName == "targetFlowcharts")
{
return true;
}
return false;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
}
}

12
Assets/Fungus/Flowchart/Scripts/Commands/StopFlowchart.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ae67a23cb4aa74793b41258ae40bf321
timeCreated: 1442408419
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -422,6 +422,21 @@ namespace Fungus
return true; return true;
} }
/**
* Stop all executing Blocks in this Flowchart.
*/
public virtual void StopAllBlocks()
{
Block [] blocks = GetComponentsInChildren<Block>();
foreach (Block block in blocks)
{
if (block.IsExecuting())
{
block.Stop();
}
}
}
/** /**
* Returns a new variable key that is guaranteed not to clash with any existing variable in the list. * Returns a new variable key that is guaranteed not to clash with any existing variable in the list.
*/ */

11
Assets/Fungus/Narrative/Scripts/Commands/Say.cs

@ -120,6 +120,17 @@ namespace Fungus
executionCount = 0; executionCount = 0;
} }
public override void OnStopExecuting()
{
SayDialog sayDialog = SayDialog.GetSayDialog();
if (sayDialog == null)
{
return;
}
sayDialog.Stop();
}
// //
// ILocalizable implementation // ILocalizable implementation
// //

23
Assets/Fungus/UI/Scripts/Commands/Write.cs

@ -42,6 +42,17 @@ namespace Fungus
public ColorData setColor = new ColorData(Color.white); public ColorData setColor = new ColorData(Color.white);
protected Writer GetWriter()
{
Writer writer = textObject.GetComponent<Writer>();
if (writer == null)
{
writer = textObject.AddComponent<Writer>() as Writer;
}
return writer;
}
public override void OnEnter() public override void OnEnter()
{ {
if (textObject == null) if (textObject == null)
@ -50,7 +61,7 @@ namespace Fungus
return; return;
} }
Writer writer = FindWriter(textObject); Writer writer = GetWriter();
if (writer == null) if (writer == null)
{ {
Continue(); Continue();
@ -101,15 +112,9 @@ namespace Fungus
return new Color32(235, 191, 217, 255); return new Color32(235, 191, 217, 255);
} }
protected Writer FindWriter(GameObject textObject) public override void OnStopExecuting()
{ {
Writer writer = textObject.GetComponent<Writer>(); GetWriter().Stop();
if (writer == null)
{
writer = textObject.AddComponent<Writer>() as Writer;
}
return writer;
} }
// //

5
Assets/Fungus/UI/Scripts/Writer.cs

@ -269,7 +269,10 @@ namespace Fungus
public virtual void Stop() public virtual void Stop()
{ {
exitFlag = true; if (isWriting || isWaitingForInput)
{
exitFlag = true;
}
} }
public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete) public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete)

1278
Assets/Tests/Scripting/Scripting.unity

File diff suppressed because it is too large Load Diff

14
ProjectSettings/ProjectSettings.asset

@ -8,6 +8,7 @@ PlayerSettings:
defaultScreenOrientation: 2 defaultScreenOrientation: 2
targetDevice: 2 targetDevice: 2
targetResolution: 0 targetResolution: 0
useOnDemandResources: 0
accelerometerFrequency: 60 accelerometerFrequency: 60
companyName: Fungus companyName: Fungus
productName: Sherlock productName: Sherlock
@ -28,6 +29,7 @@ PlayerSettings:
androidShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1
iosAppInBackgroundBehavior: 0 iosAppInBackgroundBehavior: 0
displayResolutionDialog: 1 displayResolutionDialog: 1
iosAllowHTTPDownload: 1
allowedAutorotateToPortrait: 1 allowedAutorotateToPortrait: 1
allowedAutorotateToPortraitUpsideDown: 1 allowedAutorotateToPortraitUpsideDown: 1
allowedAutorotateToLandscapeRight: 1 allowedAutorotateToLandscapeRight: 1
@ -135,6 +137,15 @@ PlayerSettings:
iOSLaunchScreenFillPct: 1 iOSLaunchScreenFillPct: 1
iOSLaunchScreenSize: 100 iOSLaunchScreenSize: 100
iOSLaunchScreenCustomXibPath: iOSLaunchScreenCustomXibPath:
iOSLaunchScreeniPadType: 0
iOSLaunchScreeniPadImage: {fileID: 0}
iOSLaunchScreeniPadBackgroundColor:
serializedVersion: 2
rgba: 0
iOSLaunchScreeniPadFillPct: 100
iOSLaunchScreeniPadSize: 100
iOSLaunchScreeniPadCustomXibPath:
iOSDeviceRequirements: []
AndroidTargetDevice: 0 AndroidTargetDevice: 0
AndroidSplashScreenScale: 0 AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0} androidSplashScreen: {fileID: 0}
@ -231,6 +242,8 @@ PlayerSettings:
ps4SdkOverride: ps4SdkOverride:
ps4BGMPath: ps4BGMPath:
ps4ShareFilePath: ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4NPtitleDatPath: ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1 ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir: ps4RemotePlayKeyMappingDir:
@ -252,6 +265,7 @@ PlayerSettings:
ps4attribMoveSupport: 0 ps4attribMoveSupport: 0
ps4attrib3DSupport: 0 ps4attrib3DSupport: 0
ps4attribShareSupport: 0 ps4attribShareSupport: 0
ps4IncludedModules: []
monoEnv: monoEnv:
psp2Splashimage: {fileID: 0} psp2Splashimage: {fileID: 0}
psp2NPTrophyPackPath: psp2NPTrophyPackPath:

2
ProjectSettings/ProjectVersion.txt

@ -1,2 +1,2 @@
m_EditorVersion: 5.2.0f3 m_EditorVersion: 5.2.1f1
m_StandardAssetsVersion: 0 m_StandardAssetsVersion: 0

Loading…
Cancel
Save