Browse Source

Refactored many classes to use protected serialisable fields, with public property accessors where required.

master
Christopher 9 years ago
parent
commit
83c12c7e76
  1. 8
      Assets/Fungus/Animation/Scripts/Commands/PlayAnimState.cs
  2. 4
      Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs
  3. 6
      Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs
  4. 6
      Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs
  5. 6
      Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs
  6. 4
      Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs
  7. 4
      Assets/Fungus/Audio/Editor/ControlAudioEditor.cs
  8. 14
      Assets/Fungus/Audio/Scripts/Commands/ControlAudio.cs
  9. 8
      Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs
  10. 6
      Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs
  11. 6
      Assets/Fungus/Audio/Scripts/Commands/PlayUsfxrSound.cs
  12. 6
      Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs
  13. 6
      Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs
  14. 6
      Assets/Fungus/Camera/Editor/ViewEditor.cs
  15. 22
      Assets/Fungus/Camera/Scripts/CameraController.cs
  16. 20
      Assets/Fungus/Camera/Scripts/Commands/FadeScreen.cs
  17. 26
      Assets/Fungus/Camera/Scripts/Commands/FadeToView.cs
  18. 2
      Assets/Fungus/Camera/Scripts/Commands/Fullscreen.cs
  19. 16
      Assets/Fungus/Camera/Scripts/Commands/MoveToView.cs
  20. 6
      Assets/Fungus/Camera/Scripts/Commands/ShakeCamera.cs
  21. 10
      Assets/Fungus/Camera/Scripts/Commands/StartSwipe.cs
  22. 4
      Assets/Fungus/Flowchart/Editor/AssetModProcessor.cs
  23. 138
      Assets/Fungus/Flowchart/Editor/BlockEditor.cs
  24. 18
      Assets/Fungus/Flowchart/Editor/BlockInspector.cs
  25. 9
      Assets/Fungus/Flowchart/Editor/CommandEditor.cs
  26. 50
      Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs
  27. 28
      Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs
  28. 6
      Assets/Fungus/Flowchart/Editor/FlowchartMenuItems.cs
  29. 205
      Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs
  30. 36
      Assets/Fungus/Flowchart/Editor/InvokeMethodEditor.cs
  31. 4
      Assets/Fungus/Flowchart/Editor/LabelEditor.cs
  32. 2
      Assets/Fungus/Flowchart/Editor/SetVariableEditor.cs
  33. 8
      Assets/Fungus/Flowchart/Editor/VariableEditor.cs
  34. 18
      Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs
  35. 89
      Assets/Fungus/Flowchart/Scripts/Block.cs
  36. 39
      Assets/Fungus/Flowchart/Scripts/Command.cs
  37. 16
      Assets/Fungus/Flowchart/Scripts/Commands/Break.cs
  38. 18
      Assets/Fungus/Flowchart/Scripts/Commands/Call.cs
  39. 6
      Assets/Fungus/Flowchart/Scripts/Commands/CallMethod.cs
  40. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Comment.cs
  41. 2
      Assets/Fungus/Flowchart/Scripts/Commands/Condition.cs
  42. 4
      Assets/Fungus/Flowchart/Scripts/Commands/DebugLog.cs
  43. 2
      Assets/Fungus/Flowchart/Scripts/Commands/DeleteSaveKey.cs
  44. 2
      Assets/Fungus/Flowchart/Scripts/Commands/Destroy.cs
  45. 12
      Assets/Fungus/Flowchart/Scripts/Commands/Else.cs
  46. 12
      Assets/Fungus/Flowchart/Scripts/Commands/ElseIf.cs
  47. 9
      Assets/Fungus/Flowchart/Scripts/Commands/End.cs
  48. 26
      Assets/Fungus/Flowchart/Scripts/Commands/If.cs
  49. 30
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeEvent.cs
  50. 26
      Assets/Fungus/Flowchart/Scripts/Commands/InvokeMethod.cs
  51. 10
      Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs
  52. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Label.cs
  53. 4
      Assets/Fungus/Flowchart/Scripts/Commands/LoadScene.cs
  54. 4
      Assets/Fungus/Flowchart/Scripts/Commands/LoadVariable.cs
  55. 2
      Assets/Fungus/Flowchart/Scripts/Commands/OpenURL.cs
  56. 8
      Assets/Fungus/Flowchart/Scripts/Commands/RandomFloat.cs
  57. 8
      Assets/Fungus/Flowchart/Scripts/Commands/RandomInteger.cs
  58. 6
      Assets/Fungus/Flowchart/Scripts/Commands/ReadTextFile.cs
  59. 4
      Assets/Fungus/Flowchart/Scripts/Commands/Reset.cs
  60. 4
      Assets/Fungus/Flowchart/Scripts/Commands/SaveVariable.cs
  61. 4
      Assets/Fungus/Flowchart/Scripts/Commands/SendMessage.cs
  62. 4
      Assets/Fungus/Flowchart/Scripts/Commands/SetActive.cs
  63. 2
      Assets/Fungus/Flowchart/Scripts/Commands/SetSaveProfile.cs
  64. 16
      Assets/Fungus/Flowchart/Scripts/Commands/SetVariable.cs
  65. 8
      Assets/Fungus/Flowchart/Scripts/Commands/SpawnObject.cs
  66. 4
      Assets/Fungus/Flowchart/Scripts/Commands/StopBlock.cs
  67. 4
      Assets/Fungus/Flowchart/Scripts/Commands/StopFlowchart.cs
  68. 2
      Assets/Fungus/Flowchart/Scripts/Commands/Wait.cs
  69. 10
      Assets/Fungus/Flowchart/Scripts/Commands/While.cs
  70. 10
      Assets/Fungus/Flowchart/Scripts/EventHandler.cs
  71. 4
      Assets/Fungus/Flowchart/Scripts/EventHandlers/KeyPressed.cs
  72. 2
      Assets/Fungus/Flowchart/Scripts/EventHandlers/MessageReceived.cs
  73. 146
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  74. 4
      Assets/Fungus/Flowchart/Scripts/FungusState.cs
  75. 4
      Assets/Fungus/Flowchart/Scripts/Node.cs
  76. 8
      Assets/Fungus/Flowchart/Scripts/Variable.cs
  77. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs
  78. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/AudioSourceVariable.cs
  79. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/BooleanVariable.cs
  80. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/ColorVariable.cs
  81. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/FloatVariable.cs
  82. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/GameObjectVariable.cs
  83. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/IntegerVariable.cs
  84. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/MaterialVariable.cs
  85. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/ObjectVariable.cs
  86. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/SpriteVariable.cs
  87. 4
      Assets/Fungus/Flowchart/Scripts/VariableTypes/StringVariable.cs
  88. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/TextureVariable.cs
  89. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/TransformVariable.cs
  90. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/Vector2Variable.cs
  91. 2
      Assets/Fungus/Flowchart/Scripts/VariableTypes/Vector3Variable.cs
  92. 8
      Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs
  93. 2
      Assets/Fungus/Narrative/Scripts/Commands/Menu.cs
  94. 2
      Assets/Fungus/Narrative/Scripts/Commands/MenuTimer.cs
  95. 2
      Assets/Fungus/Narrative/Scripts/Localization.cs
  96. 2
      Assets/Fungus/Narrative/Scripts/MenuDialog.cs
  97. 8
      Assets/Fungus/Sprite/Scripts/Clickable2D.cs
  98. 8
      Assets/Fungus/Sprite/Scripts/Commands/FadeSprite.cs
  99. 6
      Assets/Fungus/Sprite/Scripts/Commands/SetClickable2D.cs
  100. 6
      Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs
  101. Some files were not shown because too many files have changed in this diff Show More

8
Assets/Fungus/Animation/Scripts/Commands/PlayAnimState.cs

@ -16,16 +16,16 @@ namespace Fungus
public class PlayAnimState : Command public class PlayAnimState : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData animator = new AnimatorData(); [SerializeField] protected AnimatorData animator = new AnimatorData();
[Tooltip("Name of the state you want to play")] [Tooltip("Name of the state you want to play")]
public StringData stateName = new StringData(); [SerializeField] protected StringData stateName = new StringData();
[Tooltip("Layer to play animation on")] [Tooltip("Layer to play animation on")]
public IntegerData layer = new IntegerData(-1); [SerializeField] protected IntegerData layer = new IntegerData(-1);
[Tooltip("Start time of animation")] [Tooltip("Start time of animation")]
public FloatData time = new FloatData(0f); [SerializeField] protected FloatData time = new FloatData(0f);
public override void OnEnter() public override void OnEnter()
{ {

4
Assets/Fungus/Animation/Scripts/Commands/ResetAnimTrigger.cs

@ -18,10 +18,10 @@ namespace Fungus
public class ResetAnimTrigger : Command public class ResetAnimTrigger : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData _animator; [SerializeField] protected AnimatorData _animator;
[Tooltip("Name of the trigger Animator parameter that will be reset")] [Tooltip("Name of the trigger Animator parameter that will be reset")]
public StringData _parameterName; [SerializeField] protected StringData _parameterName;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Animation/Scripts/Commands/SetAnimBool.cs

@ -18,13 +18,13 @@ namespace Fungus
public class SetAnimBool : Command public class SetAnimBool : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData _animator; [SerializeField] protected AnimatorData _animator;
[Tooltip("Name of the boolean Animator parameter that will have its value changed")] [Tooltip("Name of the boolean Animator parameter that will have its value changed")]
public StringData _parameterName; [SerializeField] protected StringData _parameterName;
[Tooltip("The boolean value to set the parameter to")] [Tooltip("The boolean value to set the parameter to")]
public BooleanData value; [SerializeField] protected BooleanData value;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Animation/Scripts/Commands/SetAnimFloat.cs

@ -18,13 +18,13 @@ namespace Fungus
public class SetAnimFloat : Command public class SetAnimFloat : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData _animator; [SerializeField] protected AnimatorData _animator;
[Tooltip("Name of the float Animator parameter that will have its value changed")] [Tooltip("Name of the float Animator parameter that will have its value changed")]
public StringData _parameterName; [SerializeField] protected StringData _parameterName;
[Tooltip("The float value to set the parameter to")] [Tooltip("The float value to set the parameter to")]
public FloatData value; [SerializeField] protected FloatData value;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Animation/Scripts/Commands/SetAnimInteger.cs

@ -18,13 +18,13 @@ namespace Fungus
public class SetAnimInteger : Command public class SetAnimInteger : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData _animator; [SerializeField] protected AnimatorData _animator;
[Tooltip("Name of the integer Animator parameter that will have its value changed")] [Tooltip("Name of the integer Animator parameter that will have its value changed")]
public StringData _parameterName; [SerializeField] protected StringData _parameterName;
[Tooltip("The integer value to set the parameter to")] [Tooltip("The integer value to set the parameter to")]
public IntegerData value; [SerializeField] protected IntegerData value;
public override void OnEnter() public override void OnEnter()
{ {

4
Assets/Fungus/Animation/Scripts/Commands/SetAnimTrigger.cs

@ -18,10 +18,10 @@ namespace Fungus
public class SetAnimTrigger : Command public class SetAnimTrigger : Command
{ {
[Tooltip("Reference to an Animator component in a game object")] [Tooltip("Reference to an Animator component in a game object")]
public AnimatorData _animator; [SerializeField] protected AnimatorData _animator;
[Tooltip("Name of the trigger Animator parameter that will have its value changed")] [Tooltip("Name of the trigger Animator parameter that will have its value changed")]
public StringData _parameterName; [SerializeField] protected StringData _parameterName;
public override void OnEnter() public override void OnEnter()
{ {

4
Assets/Fungus/Audio/Editor/ControlAudioEditor.cs

@ -49,11 +49,11 @@ namespace Fungus
EditorGUILayout.PropertyField(controlProp); EditorGUILayout.PropertyField(controlProp);
EditorGUILayout.PropertyField(audioSourceProp); EditorGUILayout.PropertyField(audioSourceProp);
string fadeLabel = "Fade Out Duration"; string fadeLabel = "Fade Out Duration";
if (t.control != ControlAudio.controlType.StopLoop && t.control != ControlAudio.controlType.PauseLoop) if (t.Control != ControlAudio.controlType.StopLoop && t.Control != ControlAudio.controlType.PauseLoop)
{ {
fadeLabel = "Fade In Duration"; fadeLabel = "Fade In Duration";
string volumeLabel = "End Volume"; string volumeLabel = "End Volume";
if (t.control == ControlAudio.controlType.ChangeVolume) if (t.Control == ControlAudio.controlType.ChangeVolume)
{ {
fadeLabel = "Fade Duration"; fadeLabel = "Fade Duration";
volumeLabel = "New Volume"; volumeLabel = "New Volume";

14
Assets/Fungus/Audio/Scripts/Commands/ControlAudio.cs

@ -25,24 +25,26 @@ namespace Fungus
} }
[Tooltip("What to do to audio")] [Tooltip("What to do to audio")]
public controlType control; [SerializeField] protected controlType control;
public controlType Control { get { return control; } }
[Tooltip("Audio clip to play")] [Tooltip("Audio clip to play")]
public AudioSourceData _audioSource; [SerializeField] protected AudioSourceData _audioSource;
[Range(0,1)] [Range(0,1)]
[Tooltip("Start audio at this volume")] [Tooltip("Start audio at this volume")]
public float startVolume = 1; [SerializeField] protected float startVolume = 1;
[Range(0,1)] [Range(0,1)]
[Tooltip("End audio at this volume")] [Tooltip("End audio at this volume")]
public float endVolume = 1; [SerializeField] protected float endVolume = 1;
[Tooltip("Time to fade between current volume level and target volume level.")] [Tooltip("Time to fade between current volume level and target volume level.")]
public float fadeDuration; [SerializeField] protected float fadeDuration;
[Tooltip("Wait until this command has finished before executing the next command.")] [Tooltip("Wait until this command has finished before executing the next command.")]
public bool waitUntilFinished = false; [SerializeField] protected bool waitUntilFinished = false;
public override void OnEnter() public override void OnEnter()
{ {

8
Assets/Fungus/Audio/Scripts/Commands/PlayMusic.cs

@ -15,16 +15,16 @@ namespace Fungus
public class PlayMusic : Command public class PlayMusic : Command
{ {
[Tooltip("Music sound clip to play")] [Tooltip("Music sound clip to play")]
public AudioClip musicClip; [SerializeField] protected AudioClip musicClip;
[Tooltip("Time to begin playing in seconds. If the audio file is compressed, the time index may be inaccurate.")] [Tooltip("Time to begin playing in seconds. If the audio file is compressed, the time index may be inaccurate.")]
public float atTime; [SerializeField] protected float atTime;
[Tooltip("The music will start playing again at end.")] [Tooltip("The music will start playing again at end.")]
public bool loop = true; [SerializeField] protected bool loop = true;
[Tooltip("Length of time to fade out previous playing music.")] [Tooltip("Length of time to fade out previous playing music.")]
public float fadeDuration = 1f; [SerializeField] protected float fadeDuration = 1f;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Audio/Scripts/Commands/PlaySound.cs

@ -15,14 +15,14 @@ namespace Fungus
public class PlaySound : Command public class PlaySound : Command
{ {
[Tooltip("Sound effect clip to play")] [Tooltip("Sound effect clip to play")]
public AudioClip soundClip; [SerializeField] protected AudioClip soundClip;
[Range(0,1)] [Range(0,1)]
[Tooltip("Volume level of the sound effect")] [Tooltip("Volume level of the sound effect")]
public float volume = 1; [SerializeField] protected float volume = 1;
[Tooltip("Wait until the sound has finished playing before continuing execution.")] [Tooltip("Wait until the sound has finished playing before continuing execution.")]
public bool waitUntilFinished; [SerializeField] protected bool waitUntilFinished;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Audio/Scripts/Commands/PlayUsfxrSound.cs

@ -18,13 +18,13 @@
protected SfxrSynth _synth = new SfxrSynth(); protected SfxrSynth _synth = new SfxrSynth();
[Tooltip("Transform to use for positional audio")] [Tooltip("Transform to use for positional audio")]
public Transform ParentTransform = null; [SerializeField] protected Transform ParentTransform = null;
[Tooltip("Settings string which describes the audio")] [Tooltip("Settings string which describes the audio")]
public StringDataMulti _SettingsString = new StringDataMulti(""); [SerializeField] protected StringDataMulti _SettingsString = new StringDataMulti("");
[Tooltip("Time to wait before executing the next command")] [Tooltip("Time to wait before executing the next command")]
public float waitDuration = 0; [SerializeField] protected float waitDuration = 0;
//Call this if the settings have changed //Call this if the settings have changed
protected void UpdateCache() { protected void UpdateCache() {

6
Assets/Fungus/Audio/Scripts/Commands/SetAudioPitch.cs

@ -16,14 +16,14 @@ namespace Fungus
{ {
[Range(0,1)] [Range(0,1)]
[Tooltip("Global pitch level for audio played using the Play Music and Play Sound commands")] [Tooltip("Global pitch level for audio played using the Play Music and Play Sound commands")]
public float pitch = 1; [SerializeField] protected float pitch = 1;
[Range(0,30)] [Range(0,30)]
[Tooltip("Time to fade between current pitch level and target pitch level.")] [Tooltip("Time to fade between current pitch level and target pitch level.")]
public float fadeDuration; [SerializeField] protected float fadeDuration;
[Tooltip("Wait until the pitch change has finished before executing next command")] [Tooltip("Wait until the pitch change has finished before executing next command")]
public bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Audio/Scripts/Commands/SetAudioVolume.cs

@ -16,14 +16,14 @@ namespace Fungus
{ {
[Range(0,1)] [Range(0,1)]
[Tooltip("Global volume level for audio played using Play Music and Play Sound")] [Tooltip("Global volume level for audio played using Play Music and Play Sound")]
public float volume = 1f; [SerializeField] protected float volume = 1f;
[Range(0,30)] [Range(0,30)]
[Tooltip("Time to fade between current volume level and target volume level.")] [Tooltip("Time to fade between current volume level and target volume level.")]
public float fadeDuration = 1f; [SerializeField] protected float fadeDuration = 1f;
[Tooltip("Wait until the volume fade has completed before continuing.")] [Tooltip("Wait until the volume fade has completed before continuing.")]
public bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
public override void OnEnter() public override void OnEnter()
{ {

6
Assets/Fungus/Camera/Editor/ViewEditor.cs

@ -176,11 +176,11 @@ namespace Fungus
Flowchart flowchart = FlowchartWindow.GetFlowchart(); Flowchart flowchart = FlowchartWindow.GetFlowchart();
if (flowchart != null) if (flowchart != null)
{ {
foreach (Command command in flowchart.selectedCommands) foreach (Command command in flowchart.SelectedCommands)
{ {
MoveToView moveToViewCommand = command as MoveToView; MoveToView moveToViewCommand = command as MoveToView;
if (moveToViewCommand != null && if (moveToViewCommand != null &&
moveToViewCommand.targetView == view) moveToViewCommand.TargetView == view)
{ {
highlight = true; highlight = true;
} }
@ -188,7 +188,7 @@ namespace Fungus
{ {
FadeToView fadeToViewCommand = command as FadeToView; FadeToView fadeToViewCommand = command as FadeToView;
if (fadeToViewCommand != null && if (fadeToViewCommand != null &&
fadeToViewCommand.targetView == view) fadeToViewCommand.TargetView == view)
{ {
highlight = true; highlight = true;
} }

22
Assets/Fungus/Camera/Scripts/CameraController.cs

@ -20,41 +20,39 @@ namespace Fungus
/** /**
* Full screen texture used for screen fade effect. * Full screen texture used for screen fade effect.
*/ */
public Texture2D screenFadeTexture; [SerializeField] protected Texture2D screenFadeTexture;
public Texture2D ScreenFadeTexture { set { screenFadeTexture = value; } }
/** /**
* Icon to display when swipe pan mode is active. * Icon to display when swipe pan mode is active.
*/ */
public Texture2D swipePanIcon; [SerializeField] protected Texture2D swipePanIcon;
/** /**
* Position of continue and swipe icons in normalized screen space coords. * Position of continue and swipe icons in normalized screen space coords.
* (0,0) = top left, (1,1) = bottom right * (0,0) = top left, (1,1) = bottom right
*/ */
public Vector2 swipeIconPosition = new Vector2(1,0); [SerializeField] protected Vector2 swipeIconPosition = new Vector2(1,0);
/** /**
* Set the camera z coordinate to a fixed value every frame. * Set the camera z coordinate to a fixed value every frame.
*/ */
public bool setCameraZ = true; [SerializeField] protected bool setCameraZ = true;
/** /**
* Fixed Z coordinate of main camera. * Fixed Z coordinate of main camera.
*/ */
public float cameraZ = -10f; [SerializeField] protected float cameraZ = -10f;
[HideInInspector] [SerializeField] protected Camera swipeCamera;
public bool waiting;
protected float fadeAlpha = 0f; protected float fadeAlpha = 0f;
// Swipe panning control // Swipe panning control
[HideInInspector] protected bool swipePanActive;
public bool swipePanActive;
public Camera swipeCamera;
[HideInInspector] protected float swipeSpeedMultiplier = 1f;
public float swipeSpeedMultiplier = 1f;
protected View swipePanViewA; protected View swipePanViewA;
protected View swipePanViewB; protected View swipePanViewB;
protected Vector3 previousMousePos; protected Vector3 previousMousePos;

20
Assets/Fungus/Camera/Scripts/Commands/FadeScreen.cs

@ -17,42 +17,36 @@ namespace Fungus
public class FadeScreen : Command public class FadeScreen : Command
{ {
[Tooltip("Time for fade effect to complete")] [Tooltip("Time for fade effect to complete")]
public float duration = 1f; [SerializeField] protected float duration = 1f;
[Tooltip("Current target alpha transparency value. The fade gradually adjusts the alpha to approach this target value.")] [Tooltip("Current target alpha transparency value. The fade gradually adjusts the alpha to approach this target value.")]
public float targetAlpha = 1f; [SerializeField] protected float targetAlpha = 1f;
[Tooltip("Wait until the fade has finished before executing next command")] [Tooltip("Wait until the fade has finished before executing next command")]
public bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
[Tooltip("Color to render fullscreen fade texture with when screen is obscured.")] [Tooltip("Color to render fullscreen fade texture with when screen is obscured.")]
public Color fadeColor = Color.black; [SerializeField] protected Color fadeColor = Color.black;
[Tooltip("Optional texture to use when rendering the fullscreen fade effect.")] [Tooltip("Optional texture to use when rendering the fullscreen fade effect.")]
public Texture2D fadeTexture; [SerializeField] protected Texture2D fadeTexture;
public override void OnEnter() public override void OnEnter()
{ {
CameraController cameraController = CameraController.GetInstance(); CameraController cameraController = CameraController.GetInstance();
if (waitUntilFinished)
{
cameraController.waiting = true;
}
if (fadeTexture) if (fadeTexture)
{ {
cameraController.screenFadeTexture = fadeTexture; cameraController.ScreenFadeTexture = fadeTexture;
} }
else else
{ {
cameraController.screenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32);
} }
cameraController.Fade(targetAlpha, duration, delegate { cameraController.Fade(targetAlpha, duration, delegate {
if (waitUntilFinished) if (waitUntilFinished)
{ {
cameraController.waiting = false;
Continue(); Continue();
} }
}); });

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

@ -16,25 +16,27 @@ namespace Fungus
public class FadeToView : Command public class FadeToView : Command
{ {
[Tooltip("Time for fade effect to complete")] [Tooltip("Time for fade effect to complete")]
public float duration = 1f; [SerializeField] protected float duration = 1f;
[Tooltip("Fade from fully visible to opaque at start of fade")] [Tooltip("Fade from fully visible to opaque at start of fade")]
public bool fadeOut = true; [SerializeField] protected bool fadeOut = true;
[Tooltip("View to transition to when Fade is complete")] [Tooltip("View to transition to when Fade is complete")]
public View targetView; [SerializeField] protected View targetView;
public View TargetView { get { return targetView; } }
[Tooltip("Wait until the fade has finished before executing next command")] [Tooltip("Wait until the fade has finished before executing next command")]
public bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
[Tooltip("Color to render fullscreen fade texture with when screen is obscured.")] [Tooltip("Color to render fullscreen fade texture with when screen is obscured.")]
public Color fadeColor = Color.black; [SerializeField] protected Color fadeColor = Color.black;
[Tooltip("Optional texture to use when rendering the fullscreen fade effect.")] [Tooltip("Optional texture to use when rendering the fullscreen fade effect.")]
public Texture2D fadeTexture; [SerializeField] protected Texture2D fadeTexture;
[Tooltip("Camera to use for the fade. Will use main camera if set to none.")] [Tooltip("Camera to use for the fade. Will use main camera if set to none.")]
public Camera targetCamera; [SerializeField] protected Camera targetCamera;
protected virtual void AcquireCamera() protected virtual void AcquireCamera()
{ {
@ -67,24 +69,18 @@ namespace Fungus
CameraController cameraController = CameraController.GetInstance(); CameraController cameraController = CameraController.GetInstance();
if (waitUntilFinished)
{
cameraController.waiting = true;
}
if (fadeTexture) if (fadeTexture)
{ {
cameraController.screenFadeTexture = fadeTexture; cameraController.ScreenFadeTexture = fadeTexture;
} }
else else
{ {
cameraController.screenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32);
} }
cameraController.FadeToView(targetCamera, targetView, duration, fadeOut, delegate { cameraController.FadeToView(targetCamera, targetView, duration, fadeOut, delegate {
if (waitUntilFinished) if (waitUntilFinished)
{ {
cameraController.waiting = false;
Continue(); Continue();
} }
}); });

2
Assets/Fungus/Camera/Scripts/Commands/Fullscreen.cs

@ -22,7 +22,7 @@ namespace Fungus
Windowed Windowed
} }
public FullscreenMode fullscreenMode; [SerializeField] protected FullscreenMode fullscreenMode;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -16,16 +16,18 @@ namespace Fungus
public class MoveToView : Command public class MoveToView : Command
{ {
[Tooltip("Time for move effect to complete")] [Tooltip("Time for move effect to complete")]
public float duration = 1; [SerializeField] protected float duration = 1;
[Tooltip("View to transition to when move is complete")] [Tooltip("View to transition to when move is complete")]
public Fungus.View targetView; [SerializeField] protected View targetView;
public View TargetView { get { return targetView; } }
[Tooltip("Wait until the fade has finished before executing next command")] [Tooltip("Wait until the fade has finished before executing next command")]
public bool waitUntilFinished = true; [SerializeField] protected bool waitUntilFinished = true;
[Tooltip("Camera to use for the pan. Will use main camera if set to none.")] [Tooltip("Camera to use for the pan. Will use main camera if set to none.")]
public Camera targetCamera; [SerializeField] protected Camera targetCamera;
protected virtual void AcquireCamera() protected virtual void AcquireCamera()
{ {
@ -58,11 +60,6 @@ namespace Fungus
CameraController cameraController = CameraController.GetInstance(); CameraController cameraController = CameraController.GetInstance();
if (waitUntilFinished)
{
cameraController.waiting = true;
}
Vector3 targetPosition = targetView.transform.position; Vector3 targetPosition = targetView.transform.position;
Quaternion targetRotation = targetView.transform.rotation; Quaternion targetRotation = targetView.transform.rotation;
float targetSize = targetView.viewSize; float targetSize = targetView.viewSize;
@ -70,7 +67,6 @@ namespace Fungus
cameraController.PanToPosition(targetCamera, targetPosition, targetRotation, targetSize, duration, delegate { cameraController.PanToPosition(targetCamera, targetPosition, targetRotation, targetSize, duration, delegate {
if (waitUntilFinished) if (waitUntilFinished)
{ {
cameraController.waiting = false;
Continue(); Continue();
} }
}); });

6
Assets/Fungus/Camera/Scripts/Commands/ShakeCamera.cs

@ -16,13 +16,13 @@ namespace Fungus
public class ShakeCamera : Command public class ShakeCamera : Command
{ {
[Tooltip("Time for camera shake effect to complete")] [Tooltip("Time for camera shake effect to complete")]
public float duration = 0.5f; [SerializeField] protected float duration = 0.5f;
[Tooltip("Magnitude of shake effect in x & y axes")] [Tooltip("Magnitude of shake effect in x & y axes")]
public Vector2 amount = new Vector2(1, 1); [SerializeField] protected Vector2 amount = new Vector2(1, 1);
[Tooltip("Wait until the shake effect has finished before executing next command")] [Tooltip("Wait until the shake effect has finished before executing next command")]
public bool waitUntilFinished; [SerializeField] protected bool waitUntilFinished;
public override void OnEnter() public override void OnEnter()
{ {

10
Assets/Fungus/Camera/Scripts/Commands/StartSwipe.cs

@ -16,19 +16,19 @@ namespace Fungus
public class StartSwipe : Command public class StartSwipe : Command
{ {
[Tooltip("Defines one extreme of the scrollable area that the player can pan around")] [Tooltip("Defines one extreme of the scrollable area that the player can pan around")]
public View viewA; [SerializeField] protected View viewA;
[Tooltip("Defines one extreme of the scrollable area that the player can pan around")] [Tooltip("Defines one extreme of the scrollable area that the player can pan around")]
public View viewB; [SerializeField] protected View viewB;
[Tooltip("Time to move the camera to a valid starting position between the two views")] [Tooltip("Time to move the camera to a valid starting position between the two views")]
public float duration = 0.5f; [SerializeField] protected float duration = 0.5f;
[Tooltip("Multiplier factor for speed of swipe pan")] [Tooltip("Multiplier factor for speed of swipe pan")]
public float speedMultiplier = 1f; [SerializeField] protected float speedMultiplier = 1f;
[Tooltip("Camera to use for the pan. Will use main camera if set to none.")] [Tooltip("Camera to use for the pan. Will use main camera if set to none.")]
public Camera targetCamera; [SerializeField] protected Camera targetCamera;
public virtual void Start() public virtual void Start()
{ {

4
Assets/Fungus/Flowchart/Editor/AssetModProcessor.cs

@ -38,9 +38,9 @@ namespace Fungus
Flowchart[] flowcharts = UnityEngine.Object.FindObjectsOfType<Flowchart>(); Flowchart[] flowcharts = UnityEngine.Object.FindObjectsOfType<Flowchart>();
foreach (Flowchart f in flowcharts) foreach (Flowchart f in flowcharts)
{ {
if (!f.saveSelection) if (!f.SaveSelection)
{ {
f.selectedBlock = null; f.SelectedBlock = null;
f.ClearSelectedCommands(); f.ClearSelectedCommands();
} }
} }

138
Assets/Fungus/Flowchart/Editor/BlockEditor.cs

@ -64,7 +64,7 @@ namespace Fungus
// Ensure block name is unique for this Flowchart // Ensure block name is unique for this Flowchart
Block block = target as Block; Block block = target as Block;
string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block); string uniqueName = flowchart.GetUniqueBlockKey(blockNameProperty.stringValue, block);
if (uniqueName != block.blockName) if (uniqueName != block.BlockName)
{ {
blockNameProperty.stringValue = uniqueName; blockNameProperty.stringValue = uniqueName;
} }
@ -96,7 +96,7 @@ namespace Fungus
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); SerializedProperty commandListProperty = serializedObject.FindProperty("commandList");
if (block == flowchart.selectedBlock) if (block == flowchart.SelectedBlock)
{ {
SerializedProperty descriptionProp = serializedObject.FindProperty("description"); SerializedProperty descriptionProp = serializedObject.FindProperty("description");
EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.PropertyField(descriptionProp);
@ -106,22 +106,22 @@ namespace Fungus
block.UpdateIndentLevels(); block.UpdateIndentLevels();
// Make sure each command has a reference to its parent block // Make sure each command has a reference to its parent block
foreach (Command command in block.commandList) foreach (Command command in block.CommandList)
{ {
if (command == null) // Will be deleted from the list later on if (command == null) // Will be deleted from the list later on
{ {
continue; continue;
} }
command.parentBlock = block; command.ParentBlock = block;
} }
ReorderableListGUI.Title("Commands"); ReorderableListGUI.Title("Commands");
CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0);
adaptor.nodeRect = block.nodeRect; adaptor.nodeRect = block._NodeRect;
ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu; ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu;
if (block.commandList.Count == 0) if (block.CommandList.Count == 0)
{ {
EditorGUILayout.HelpBox("Press the + button below to add a command to the list.", MessageType.Info); EditorGUILayout.HelpBox("Press the + button below to add a command to the list.", MessageType.Info);
} }
@ -146,7 +146,7 @@ namespace Fungus
// Copy keyboard shortcut // Copy keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Copy") if (e.type == EventType.ValidateCommand && e.commandName == "Copy")
{ {
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
e.Use(); e.Use();
} }
@ -161,7 +161,7 @@ namespace Fungus
// Cut keyboard shortcut // Cut keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Cut") if (e.type == EventType.ValidateCommand && e.commandName == "Cut")
{ {
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
e.Use(); e.Use();
} }
@ -192,7 +192,7 @@ namespace Fungus
// Duplicate keyboard shortcut // Duplicate keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Duplicate") if (e.type == EventType.ValidateCommand && e.commandName == "Duplicate")
{ {
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
e.Use(); e.Use();
} }
@ -208,7 +208,7 @@ namespace Fungus
// Delete keyboard shortcut // Delete keyboard shortcut
if (e.type == EventType.ValidateCommand && e.commandName == "Delete") if (e.type == EventType.ValidateCommand && e.commandName == "Delete")
{ {
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
e.Use(); e.Use();
} }
@ -311,9 +311,9 @@ namespace Fungus
Block block = target as Block; Block block = target as Block;
System.Type currentType = null; System.Type currentType = null;
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
currentType = block.eventHandler.GetType(); currentType = block._EventHandler.GetType();
} }
string currentHandlerName = "<None>"; string currentHandlerName = "<None>";
@ -372,9 +372,9 @@ namespace Fungus
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
EventHandlerEditor eventHandlerEditor = Editor.CreateEditor(block.eventHandler) as EventHandlerEditor; EventHandlerEditor eventHandlerEditor = Editor.CreateEditor(block._EventHandler) as EventHandlerEditor;
if (eventHandlerEditor != null) if (eventHandlerEditor != null)
{ {
eventHandlerEditor.DrawInspectorGUI(); eventHandlerEditor.DrawInspectorGUI();
@ -395,16 +395,16 @@ namespace Fungus
Undo.RecordObject(block, "Set Event Handler"); Undo.RecordObject(block, "Set Event Handler");
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
Undo.DestroyObjectImmediate(block.eventHandler); Undo.DestroyObjectImmediate(block._EventHandler);
} }
if (selectedType != null) if (selectedType != null)
{ {
EventHandler newHandler = Undo.AddComponent(block.gameObject, selectedType) as EventHandler; EventHandler newHandler = Undo.AddComponent(block.gameObject, selectedType) as EventHandler;
newHandler.parentBlock = block; newHandler.ParentBlock = block;
block.eventHandler = newHandler; block._EventHandler = newHandler;
} }
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
@ -428,7 +428,7 @@ namespace Fungus
Block[] blocks = flowchart.GetComponents<Block>(); Block[] blocks = flowchart.GetComponents<Block>();
for (int i = 0; i < blocks.Length; ++i) for (int i = 0; i < blocks.Length; ++i)
{ {
blockNames.Add(new GUIContent(blocks[i].blockName)); blockNames.Add(new GUIContent(blocks[i].BlockName));
if (block == blocks[i]) if (block == blocks[i])
{ {
@ -641,16 +641,16 @@ namespace Fungus
// Use index of last selected command in list, or end of list if nothing selected. // Use index of last selected command in list, or end of list if nothing selected.
int index = -1; int index = -1;
foreach (Command command in flowchart.selectedCommands) foreach (Command command in flowchart.SelectedCommands)
{ {
if (command.commandIndex + 1 > index) if (command.CommandIndex + 1 > index)
{ {
index = command.commandIndex + 1; index = command.CommandIndex + 1;
} }
} }
if (index == -1) if (index == -1)
{ {
index = block.commandList.Count; index = block.CommandList.Count;
} }
GenericMenu commandMenu = new GenericMenu(); GenericMenu commandMenu = new GenericMenu();
@ -738,20 +738,20 @@ namespace Fungus
Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command; Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;
block.GetFlowchart().AddSelectedCommand(newCommand); block.GetFlowchart().AddSelectedCommand(newCommand);
newCommand.parentBlock = block; newCommand.ParentBlock = block;
newCommand.itemId = flowchart.NextItemId(); newCommand.ItemId = flowchart.NextItemId();
// Let command know it has just been added to the block // Let command know it has just been added to the block
newCommand.OnCommandAdded(block); newCommand.OnCommandAdded(block);
Undo.RecordObject(block, "Set command type"); Undo.RecordObject(block, "Set command type");
if (commandOperation.index < block.commandList.Count - 1) if (commandOperation.index < block.CommandList.Count - 1)
{ {
block.commandList.Insert(commandOperation.index, newCommand); block.CommandList.Insert(commandOperation.index, newCommand);
} }
else else
{ {
block.commandList.Add(newCommand); block.CommandList.Add(newCommand);
} }
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
@ -774,12 +774,12 @@ namespace Fungus
bool showPaste = false; bool showPaste = false;
bool showPlay = false; bool showPlay = false;
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
showCut = true; showCut = true;
showCopy = true; showCopy = true;
showDelete = true; showDelete = true;
if (flowchart.selectedCommands.Count == 1 && Application.isPlaying) if (flowchart.SelectedCommands.Count == 1 && Application.isPlaying)
{ {
showPlay = true; showPlay = true;
} }
@ -852,14 +852,14 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
flowchart.selectedBlock == null) flowchart.SelectedBlock == null)
{ {
return; return;
} }
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
Undo.RecordObject(flowchart, "Select All"); Undo.RecordObject(flowchart, "Select All");
foreach (Command command in flowchart.selectedBlock.commandList) foreach (Command command in flowchart.SelectedBlock.CommandList)
{ {
flowchart.AddSelectedCommand(command); flowchart.AddSelectedCommand(command);
} }
@ -873,7 +873,7 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
flowchart.selectedBlock == null) flowchart.SelectedBlock == null)
{ {
return; return;
} }
@ -896,7 +896,7 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
flowchart.selectedBlock == null) flowchart.SelectedBlock == null)
{ {
return; return;
} }
@ -905,9 +905,9 @@ namespace Fungus
commandCopyBuffer.Clear(); commandCopyBuffer.Clear();
// Scan through all commands in execution order to see if each needs to be copied // Scan through all commands in execution order to see if each needs to be copied
foreach (Command command in flowchart.selectedBlock.commandList) foreach (Command command in flowchart.SelectedBlock.CommandList)
{ {
if (flowchart.selectedCommands.Contains(command)) if (flowchart.SelectedCommands.Contains(command))
{ {
System.Type type = command.GetType(); System.Type type = command.GetType();
Command newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command; Command newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command;
@ -926,7 +926,7 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
flowchart.selectedBlock == null) flowchart.SelectedBlock == null)
{ {
return; return;
} }
@ -934,14 +934,14 @@ namespace Fungus
CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance();
// Find where to paste commands in block (either at end or after last selected command) // Find where to paste commands in block (either at end or after last selected command)
int pasteIndex = flowchart.selectedBlock.commandList.Count; int pasteIndex = flowchart.SelectedBlock.CommandList.Count;
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
for (int i = 0; i < flowchart.selectedBlock.commandList.Count; ++i) for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; ++i)
{ {
Command command = flowchart.selectedBlock.commandList[i]; Command command = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (command == selectedCommand) if (command == selectedCommand)
{ {
@ -963,8 +963,8 @@ namespace Fungus
Command pastedCommand = commands.Last<Command>(); Command pastedCommand = commands.Last<Command>();
if (pastedCommand != null) if (pastedCommand != null)
{ {
pastedCommand.itemId = flowchart.NextItemId(); pastedCommand.ItemId = flowchart.NextItemId();
flowchart.selectedBlock.commandList.Insert(pasteIndex++, pastedCommand); flowchart.SelectedBlock.CommandList.Insert(pasteIndex++, pastedCommand);
} }
} }
@ -985,15 +985,15 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
if (flowchart == null || if (flowchart == null ||
flowchart.selectedBlock == null) flowchart.SelectedBlock == null)
{ {
return; return;
} }
int lastSelectedIndex = 0; int lastSelectedIndex = 0;
for (int i = flowchart.selectedBlock.commandList.Count - 1; i >= 0; --i) for (int i = flowchart.SelectedBlock.CommandList.Count - 1; i >= 0; --i)
{ {
Command command = flowchart.selectedBlock.commandList[i]; Command command = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (command == selectedCommand) if (command == selectedCommand)
{ {
@ -1002,8 +1002,8 @@ namespace Fungus
// Order of destruction is important here for undo to work // Order of destruction is important here for undo to work
Undo.DestroyObjectImmediate(command); Undo.DestroyObjectImmediate(command);
Undo.RecordObject(flowchart.selectedBlock, "Delete"); Undo.RecordObject(flowchart.SelectedBlock, "Delete");
flowchart.selectedBlock.commandList.RemoveAt(i); flowchart.SelectedBlock.CommandList.RemoveAt(i);
lastSelectedIndex = i; lastSelectedIndex = i;
@ -1015,9 +1015,9 @@ namespace Fungus
Undo.RecordObject(flowchart, "Delete"); Undo.RecordObject(flowchart, "Delete");
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
if (lastSelectedIndex < flowchart.selectedBlock.commandList.Count) if (lastSelectedIndex < flowchart.SelectedBlock.CommandList.Count)
{ {
Command nextCommand = flowchart.selectedBlock.commandList[lastSelectedIndex]; Command nextCommand = flowchart.SelectedBlock.CommandList[lastSelectedIndex];
block.GetFlowchart().AddSelectedCommand(nextCommand); block.GetFlowchart().AddSelectedCommand(nextCommand);
} }
@ -1028,19 +1028,19 @@ namespace Fungus
{ {
Block targetBlock = target as Block; Block targetBlock = target as Block;
Flowchart flowchart = targetBlock.GetFlowchart(); Flowchart flowchart = targetBlock.GetFlowchart();
Command command = flowchart.selectedCommands[0]; Command command = flowchart.SelectedCommands[0];
if (targetBlock.IsExecuting()) if (targetBlock.IsExecuting())
{ {
// The Block is already executing. // The Block is already executing.
// Tell the Block to stop, wait a little while so the executing command has a // Tell the Block to stop, wait a little while so the executing command has a
// chance to stop, and then start execution again from the new command. // chance to stop, and then start execution again from the new command.
targetBlock.Stop(); targetBlock.Stop();
flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.commandIndex, 0.2f)); flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.CommandIndex, 0.2f));
} }
else else
{ {
// Block isn't executing yet so can start it now. // Block isn't executing yet so can start it now.
flowchart.ExecuteBlock(targetBlock, command.commandIndex); flowchart.ExecuteBlock(targetBlock, command.CommandIndex);
} }
} }
@ -1048,11 +1048,11 @@ namespace Fungus
{ {
Block targetBlock = target as Block; Block targetBlock = target as Block;
Flowchart flowchart = targetBlock.GetFlowchart(); Flowchart flowchart = targetBlock.GetFlowchart();
Command command = flowchart.selectedCommands[0]; Command command = flowchart.SelectedCommands[0];
// Stop all active blocks then run the selected block. // Stop all active blocks then run the selected block.
flowchart.StopAllBlocks(); flowchart.StopAllBlocks();
flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.commandIndex, 0.2f)); flowchart.StartCoroutine(RunBlock(flowchart, targetBlock, command.CommandIndex, 0.2f));
} }
protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay) protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay)
@ -1066,15 +1066,15 @@ namespace Fungus
Block block = target as Block; Block block = target as Block;
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
int firstSelectedIndex = flowchart.selectedBlock.commandList.Count; int firstSelectedIndex = flowchart.SelectedBlock.CommandList.Count;
bool firstSelectedCommandFound = false; bool firstSelectedCommandFound = false;
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
for (int i = 0; i < flowchart.selectedBlock.commandList.Count; i++) for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; i++)
{ {
Command commandInBlock = flowchart.selectedBlock.commandList[i]; Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (commandInBlock == selectedCommand) if (commandInBlock == selectedCommand)
{ {
@ -1095,7 +1095,7 @@ namespace Fungus
if (firstSelectedIndex > 0) if (firstSelectedIndex > 0)
{ {
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(flowchart.selectedBlock.commandList[firstSelectedIndex-1]); flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[firstSelectedIndex-1]);
} }
Repaint(); Repaint();
@ -1107,13 +1107,13 @@ namespace Fungus
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
int lastSelectedIndex = -1; int lastSelectedIndex = -1;
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
for (int i = 0; i < flowchart.selectedBlock.commandList.Count; i++) for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; i++)
{ {
Command commandInBlock = flowchart.selectedBlock.commandList[i]; Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (commandInBlock == selectedCommand) if (commandInBlock == selectedCommand)
{ {
@ -1122,10 +1122,10 @@ namespace Fungus
} }
} }
} }
if (lastSelectedIndex < flowchart.selectedBlock.commandList.Count-1) if (lastSelectedIndex < flowchart.SelectedBlock.CommandList.Count-1)
{ {
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(flowchart.selectedBlock.commandList[lastSelectedIndex+1]); flowchart.AddSelectedCommand(flowchart.SelectedBlock.CommandList[lastSelectedIndex+1]);
} }
Repaint(); Repaint();

18
Assets/Fungus/Flowchart/Editor/BlockInspector.cs

@ -101,19 +101,19 @@ namespace Fungus
Rect blockRect = new Rect(5, topPanelHeight, width - 5, height + 10); Rect blockRect = new Rect(5, topPanelHeight, width - 5, height + 10);
GUILayout.BeginArea(blockRect); GUILayout.BeginArea(blockRect);
blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.blockViewHeight)); blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.BlockViewHeight));
activeBlockEditor.DrawBlockGUI(flowchart); activeBlockEditor.DrawBlockGUI(flowchart);
GUILayout.EndScrollView(); GUILayout.EndScrollView();
Command inspectCommand = null; Command inspectCommand = null;
if (flowchart.selectedCommands.Count == 1) if (flowchart.SelectedCommands.Count == 1)
{ {
inspectCommand = flowchart.selectedCommands[0]; inspectCommand = flowchart.SelectedCommands[0];
} }
if (Application.isPlaying && if (Application.isPlaying &&
inspectCommand != null && inspectCommand != null &&
inspectCommand.parentBlock != block) inspectCommand.ParentBlock != block)
{ {
GUILayout.EndArea(); GUILayout.EndArea();
Repaint(); Repaint();
@ -189,7 +189,7 @@ namespace Fungus
// Draw the resize bar after everything else has finished drawing // Draw the resize bar after everything else has finished drawing
// This is mainly to avoid incorrect indenting. // This is mainly to avoid incorrect indenting.
Rect resizeRect = new Rect(0, topPanelHeight + flowchart.blockViewHeight + 1, Screen.width, 4f); Rect resizeRect = new Rect(0, topPanelHeight + flowchart.BlockViewHeight + 1, Screen.width, 4f);
GUI.color = new Color(0.64f, 0.64f, 0.64f); GUI.color = new Color(0.64f, 0.64f, 0.64f);
GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture);
resizeRect.height = 1; resizeRect.height = 1;
@ -204,7 +204,7 @@ namespace Fungus
private void ResizeScrollView(Flowchart flowchart) private void ResizeScrollView(Flowchart flowchart)
{ {
Rect cursorChangeRect = new Rect(0, flowchart.blockViewHeight + 1, Screen.width, 4f); Rect cursorChangeRect = new Rect(0, flowchart.BlockViewHeight + 1, Screen.width, 4f);
EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical); EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical);
@ -216,7 +216,7 @@ namespace Fungus
if (resize) if (resize)
{ {
Undo.RecordObject(flowchart, "Resize view"); Undo.RecordObject(flowchart, "Resize view");
flowchart.blockViewHeight = Event.current.mousePosition.y; flowchart.BlockViewHeight = Event.current.mousePosition.y;
} }
ClampBlockViewHeight(flowchart); ClampBlockViewHeight(flowchart);
@ -251,10 +251,10 @@ namespace Fungus
if (clamp) if (clamp)
{ {
// Make sure block view is always clamped to visible area // Make sure block view is always clamped to visible area
float height = flowchart.blockViewHeight; float height = flowchart.BlockViewHeight;
height = Mathf.Max(200, height); height = Mathf.Max(200, height);
height = Mathf.Min(Screen.height - 200,height); height = Mathf.Min(Screen.height - 200,height);
flowchart.blockViewHeight = height; flowchart.BlockViewHeight = height;
} }
if (Event.current.type == EventType.Repaint) if (Event.current.type == EventType.Repaint)

9
Assets/Fungus/Flowchart/Editor/CommandEditor.cs

@ -1,3 +1,4 @@
/** /**
* This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). * This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
* It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) * It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
@ -57,7 +58,7 @@ namespace Fungus
if (t.enabled) if (t.enabled)
{ {
if (flowchart.colorCommands) if (flowchart.ColorCommands)
{ {
GUI.backgroundColor = t.GetButtonColor(); GUI.backgroundColor = t.GetButtonColor();
} }
@ -77,7 +78,7 @@ namespace Fungus
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(new GUIContent("(" + t.itemId + ")")); GUILayout.Label(new GUIContent("(" + t.ItemId + ")"));
GUILayout.Space(10); GUILayout.Space(10);
@ -100,11 +101,11 @@ namespace Fungus
EditorGUILayout.Separator(); EditorGUILayout.Separator();
if (t.errorMessage.Length > 0) if (t.ErrorMessage.Length > 0)
{ {
GUIStyle style = new GUIStyle(GUI.skin.label); GUIStyle style = new GUIStyle(GUI.skin.label);
style.normal.textColor = new Color(1,0,0); style.normal.textColor = new Color(1,0,0);
EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); EditorGUILayout.LabelField(new GUIContent("Error: " + t.ErrorMessage), style);
} }
GUILayout.EndVertical(); GUILayout.EndVertical();

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

@ -88,14 +88,14 @@ namespace Fungus
return null; return null;
} }
Block block = flowchart.selectedBlock; Block block = flowchart.SelectedBlock;
if (block == null) if (block == null)
{ {
return null; return null;
} }
Command newCommand = Undo.AddComponent<Comment>(block.gameObject) as Command; Command newCommand = Undo.AddComponent<Comment>(block.gameObject) as Command;
newCommand.itemId = flowchart.NextItemId(); newCommand.ItemId = flowchart.NextItemId();
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(newCommand); flowchart.AddSelectedCommand(newCommand);
@ -111,7 +111,7 @@ namespace Fungus
System.Type type = command.GetType(); System.Type type = command.GetType();
Command newCommand = Undo.AddComponent(parentBlock.gameObject, type) as Command; Command newCommand = Undo.AddComponent(parentBlock.gameObject, type) as Command;
newCommand.itemId = newCommand.GetFlowchart().NextItemId(); newCommand.ItemId = newCommand.GetFlowchart().NextItemId();
System.Reflection.FieldInfo[] fields = type.GetFields(); System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields) foreach (System.Reflection.FieldInfo field in fields)
{ {
@ -205,7 +205,7 @@ namespace Fungus
} }
bool commandIsSelected = false; bool commandIsSelected = false;
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (selectedCommand == command) if (selectedCommand == command)
{ {
@ -229,7 +229,7 @@ namespace Fungus
commandLabelStyle.padding.top -= 1; commandLabelStyle.padding.top -= 1;
float indentSize = 20; float indentSize = 20;
for (int i = 0; i < command.indentLevel; ++i) for (int i = 0; i < command.IndentLevel; ++i)
{ {
Rect indentRect = position; Rect indentRect = position;
indentRect.x += i * indentSize - 21; indentRect.x += i * indentSize - 21;
@ -241,12 +241,12 @@ namespace Fungus
} }
float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f); float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f);
float indentWidth = command.indentLevel * indentSize; float indentWidth = command.IndentLevel * indentSize;
Rect commandLabelRect = position; Rect commandLabelRect = position;
commandLabelRect.x += indentWidth - 21; commandLabelRect.x += indentWidth - 21;
commandLabelRect.y -= 2; commandLabelRect.y -= 2;
commandLabelRect.width -= (indentSize * command.indentLevel - 22); commandLabelRect.width -= (indentSize * command.IndentLevel - 22);
commandLabelRect.height += 5; commandLabelRect.height += 5;
// There's a weird incompatibility between the Reorderable list control used for the command list and // There's a weird incompatibility between the Reorderable list control used for the command list and
@ -263,14 +263,14 @@ namespace Fungus
Event.current.button == 0 && Event.current.button == 0 &&
clickRect.Contains(Event.current.mousePosition)) clickRect.Contains(Event.current.mousePosition))
{ {
if (flowchart.selectedCommands.Contains(command) && Event.current.button == 0) if (flowchart.SelectedCommands.Contains(command) && Event.current.button == 0)
{ {
// Left click on already selected command // Left click on already selected command
// Command key and shift key is not pressed // Command key and shift key is not pressed
if (!EditorGUI.actionKey && !Event.current.shift) if (!EditorGUI.actionKey && !Event.current.shift)
{ {
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add ( delegate {
flowchart.selectedCommands.Remove(command); flowchart.SelectedCommands.Remove(command);
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
}); });
} }
@ -279,7 +279,7 @@ namespace Fungus
if (EditorGUI.actionKey) if (EditorGUI.actionKey)
{ {
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add ( delegate {
flowchart.selectedCommands.Remove(command); flowchart.SelectedCommands.Remove(command);
}); });
Event.current.Use(); Event.current.Use();
} }
@ -304,14 +304,14 @@ namespace Fungus
// Find first and last selected commands // Find first and last selected commands
int firstSelectedIndex = -1; int firstSelectedIndex = -1;
int lastSelectedIndex = -1; int lastSelectedIndex = -1;
if (flowchart.selectedCommands.Count > 0) if (flowchart.SelectedCommands.Count > 0)
{ {
if ( flowchart.selectedBlock != null) if ( flowchart.SelectedBlock != null)
{ {
for (int i = 0; i < flowchart.selectedBlock.commandList.Count; i++) for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; i++)
{ {
Command commandInBlock = flowchart.selectedBlock.commandList[i]; Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (commandInBlock == selectedCommand) if (commandInBlock == selectedCommand)
{ {
@ -320,10 +320,10 @@ namespace Fungus
} }
} }
} }
for (int i = flowchart.selectedBlock.commandList.Count - 1; i >=0; i--) for (int i = flowchart.SelectedBlock.CommandList.Count - 1; i >=0; i--)
{ {
Command commandInBlock = flowchart.selectedBlock.commandList[i]; Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (commandInBlock == selectedCommand) if (commandInBlock == selectedCommand)
{ {
@ -337,7 +337,7 @@ namespace Fungus
if (shift) if (shift)
{ {
int currentIndex = command.commandIndex; int currentIndex = command.CommandIndex;
if (firstSelectedIndex == -1 || if (firstSelectedIndex == -1 ||
lastSelectedIndex == -1) lastSelectedIndex == -1)
{ {
@ -359,7 +359,7 @@ namespace Fungus
for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i) for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i)
{ {
Command selectedCommand = flowchart.selectedBlock.commandList[i]; Command selectedCommand = flowchart.SelectedBlock.CommandList[i];
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add ( delegate {
flowchart.AddSelectedCommand(selectedCommand); flowchart.AddSelectedCommand(selectedCommand);
}); });
@ -372,7 +372,7 @@ namespace Fungus
} }
Color commandLabelColor = Color.white; Color commandLabelColor = Color.white;
if (flowchart.colorCommands) if (flowchart.ColorCommands)
{ {
commandLabelColor = command.GetButtonColor(); commandLabelColor = command.GetButtonColor();
} }
@ -399,9 +399,9 @@ namespace Fungus
else else
{ {
string commandNameLabel; string commandNameLabel;
if (flowchart.showLineNumbers) if (flowchart.ShowLineNumbers)
{ {
commandNameLabel = command.commandIndex.ToString() + ": " + commandName; commandNameLabel = command.CommandIndex.ToString() + ": " + commandName;
} }
else else
{ {
@ -411,7 +411,7 @@ namespace Fungus
GUI.Label(commandLabelRect, commandNameLabel, commandLabelStyle); GUI.Label(commandLabelRect, commandNameLabel, commandLabelStyle);
} }
if (command.executingIconTimer > Time.realtimeSinceStartup) 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;
@ -420,7 +420,7 @@ namespace Fungus
Color storeColor = GUI.color; Color storeColor = GUI.color;
float alpha = (command.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; float alpha = (command.ExecutingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime;
alpha = Mathf.Clamp01(alpha); alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(1f, 1f, 1f, alpha); GUI.color = new Color(1f, 1f, 1f, alpha);

28
Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs

@ -91,8 +91,8 @@ namespace Fungus
if (GUILayout.Button(new GUIContent("Center View", "Centers the window view at the center of all blocks in the Flowchart"))) if (GUILayout.Button(new GUIContent("Center View", "Centers the window view at the center of all blocks in the Flowchart")))
{ {
// Reset the zoom so we don't have adjust the center position depending on zoom // Reset the zoom so we don't have adjust the center position depending on zoom
flowchart.scrollPos = flowchart.centerPosition; flowchart.ScrollPos = flowchart.CenterPosition;
flowchart.zoom = FlowchartWindow.maxZoomValue; flowchart.Zoom = FlowchartWindow.maxZoomValue;
} }
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
@ -106,16 +106,16 @@ namespace Fungus
Flowchart t = target as Flowchart; Flowchart t = target as Flowchart;
if (t.variables.Count == 0) if (t.Variables.Count == 0)
{ {
t.variablesExpanded = true; t.VariablesExpanded = true;
} }
if (!t.variablesExpanded) if (!t.VariablesExpanded)
{ {
if (GUILayout.Button ("Variables (" + t.variables.Count + ")", GUILayout.Height(24))) if (GUILayout.Button ("Variables (" + t.Variables.Count + ")", GUILayout.Height(24)))
{ {
t.variablesExpanded = true; t.VariablesExpanded = true;
} }
// Draw disclosure triangle // Draw disclosure triangle
@ -128,15 +128,15 @@ namespace Fungus
{ {
Rect listRect = new Rect(); Rect listRect = new Rect();
if (t.variables.Count > 0) if (t.Variables.Count > 0)
{ {
// Remove any null variables from the list // Remove any null variables from the list
// Can sometimes happen when upgrading to a new version of Fungus (if .meta GUID changes for a variable class) // Can sometimes happen when upgrading to a new version of Fungus (if .meta GUID changes for a variable class)
for (int i = t.variables.Count - 1; i >= 0; i--) for (int i = t.Variables.Count - 1; i >= 0; i--)
{ {
if (t.variables[i] == null) if (t.Variables[i] == null)
{ {
t.variables.RemoveAt(i); t.Variables.RemoveAt(i);
} }
} }
@ -170,7 +170,7 @@ namespace Fungus
if (GUI.Button (buttonRect, "Variables")) if (GUI.Button (buttonRect, "Variables"))
{ {
t.variablesExpanded = false; t.VariablesExpanded = false;
} }
// Draw disclosure triangle // Draw disclosure triangle
@ -249,8 +249,8 @@ namespace Fungus
Undo.RecordObject(flowchart, "Add Variable"); Undo.RecordObject(flowchart, "Add Variable");
Variable newVariable = flowchart.gameObject.AddComponent(variableType) as Variable; Variable newVariable = flowchart.gameObject.AddComponent(variableType) as Variable;
newVariable.key = flowchart.GetUniqueVariableKey(""); newVariable.Key = flowchart.GetUniqueVariableKey("");
flowchart.variables.Add(newVariable); flowchart.Variables.Add(newVariable);
// Because this is an async call, we need to force prefab instances to record changes // Because this is an async call, we need to force prefab instances to record changes
PrefabUtility.RecordPrefabInstancePropertyModifications(flowchart); PrefabUtility.RecordPrefabInstancePropertyModifications(flowchart);

6
Assets/Fungus/Flowchart/Editor/FlowchartMenuItems.cs

@ -23,15 +23,15 @@ namespace Fungus
Flowchart flowchart = go.GetComponent<Flowchart>(); Flowchart flowchart = go.GetComponent<Flowchart>();
if (flowchart != null) if (flowchart != null)
{ {
flowchart.version = Flowchart.CURRENT_VERSION; flowchart.Version = Flowchart.CURRENT_VERSION;
} }
// Only the first created Flowchart in the scene should have a default GameStarted block // Only the first created Flowchart in the scene should have a default GameStarted block
if (GameObject.FindObjectsOfType<Flowchart>().Length > 1) if (GameObject.FindObjectsOfType<Flowchart>().Length > 1)
{ {
Block block = go.GetComponent<Block>(); Block block = go.GetComponent<Block>();
block.eventHandler = null; block._EventHandler = null;
GameObject.DestroyImmediate(block.eventHandler); GameObject.DestroyImmediate(block._EventHandler);
} }
} }

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

@ -71,13 +71,13 @@ namespace Fungus
} }
if (Selection.activeGameObject == null && if (Selection.activeGameObject == null &&
flowchart.selectedBlock != null) flowchart.SelectedBlock != null)
{ {
if (blockInspector == null) if (blockInspector == null)
{ {
ShowBlockInspector(flowchart); ShowBlockInspector(flowchart);
} }
blockInspector.block = flowchart.selectedBlock; blockInspector.block = flowchart.SelectedBlock;
} }
forceRepaintCount--; forceRepaintCount--;
@ -103,11 +103,11 @@ namespace Fungus
Flowchart fs = Selection.activeGameObject.GetComponent<Flowchart>(); Flowchart fs = Selection.activeGameObject.GetComponent<Flowchart>();
if (fs != null) if (fs != null)
{ {
fungusState.selectedFlowchart = fs; fungusState.SelectedFlowchart = fs;
} }
} }
return fungusState.selectedFlowchart; return fungusState.SelectedFlowchart;
} }
protected virtual void OnGUI() protected virtual void OnGUI()
@ -122,9 +122,9 @@ namespace Fungus
// Delete any scheduled objects // Delete any scheduled objects
foreach (Block deleteBlock in deleteList) foreach (Block deleteBlock in deleteList)
{ {
bool isSelected = (flowchart.selectedBlock == deleteBlock); bool isSelected = (flowchart.SelectedBlock == deleteBlock);
foreach (Command command in deleteBlock.commandList) foreach (Command command in deleteBlock.CommandList)
{ {
Undo.DestroyObjectImmediate(command); Undo.DestroyObjectImmediate(command);
} }
@ -160,22 +160,22 @@ namespace Fungus
if (GUILayout.Button(new GUIContent(addTexture, "Add a new block"))) if (GUILayout.Button(new GUIContent(addTexture, "Add a new block")))
{ {
Vector2 newNodePosition = new Vector2(50 - flowchart.scrollPos.x, Vector2 newNodePosition = new Vector2(50 - flowchart.ScrollPos.x,
50 - flowchart.scrollPos.y); 50 - flowchart.ScrollPos.y);
CreateBlock(flowchart, newNodePosition); CreateBlock(flowchart, newNodePosition);
} }
GUILayout.Space(8); GUILayout.Space(8);
flowchart.zoom = GUILayout.HorizontalSlider(flowchart.zoom, minZoomValue, maxZoomValue, GUILayout.Width(100)); flowchart.Zoom = GUILayout.HorizontalSlider(flowchart.Zoom, minZoomValue, maxZoomValue, GUILayout.Width(100));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.BeginVertical(); GUILayout.BeginVertical();
GUILayout.Label(flowchart.name, EditorStyles.whiteBoldLabel); GUILayout.Label(flowchart.name, EditorStyles.whiteBoldLabel);
if (flowchart.description.Length > 0) if (flowchart.Description.Length > 0)
{ {
GUILayout.Label(flowchart.description, EditorStyles.helpBox); GUILayout.Label(flowchart.Description, EditorStyles.helpBox);
} }
GUILayout.EndVertical(); GUILayout.EndVertical();
@ -189,7 +189,7 @@ namespace Fungus
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
flowchart.variablesScrollPos = GUILayout.BeginScrollView(flowchart.variablesScrollPos, GUILayout.MaxHeight(position.height * 0.75f)); flowchart.VariablesScrollPos = GUILayout.BeginScrollView(flowchart.VariablesScrollPos, GUILayout.MaxHeight(position.height * 0.75f));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
@ -200,8 +200,8 @@ namespace Fungus
DestroyImmediate(flowchartEditor); DestroyImmediate(flowchartEditor);
Rect variableWindowRect = GUILayoutUtility.GetLastRect(); Rect variableWindowRect = GUILayoutUtility.GetLastRect();
if (flowchart.variablesExpanded && if (flowchart.VariablesExpanded &&
flowchart.variables.Count > 0) flowchart.Variables.Count > 0)
{ {
variableWindowRect.y -= 20; variableWindowRect.y -= 20;
variableWindowRect.height += 20; variableWindowRect.height += 20;
@ -226,16 +226,18 @@ namespace Fungus
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
flowchart.scrollViewRect.xMin = Mathf.Min(flowchart.scrollViewRect.xMin, block.nodeRect.xMin - 400); var newRect = new Rect();
flowchart.scrollViewRect.xMax = Mathf.Max(flowchart.scrollViewRect.xMax, block.nodeRect.xMax + 400); newRect.xMin = Mathf.Min(flowchart.ScrollViewRect.xMin, block._NodeRect.xMin - 400);
flowchart.scrollViewRect.yMin = Mathf.Min(flowchart.scrollViewRect.yMin, block.nodeRect.yMin - 400); newRect.xMax = Mathf.Max(flowchart.ScrollViewRect.xMax, block._NodeRect.xMax + 400);
flowchart.scrollViewRect.yMax = Mathf.Max(flowchart.scrollViewRect.yMax, block.nodeRect.yMax + 400); newRect.yMin = Mathf.Min(flowchart.ScrollViewRect.yMin, block._NodeRect.yMin - 400);
newRect.yMax = Mathf.Max(flowchart.ScrollViewRect.yMax, block._NodeRect.yMax + 400);
flowchart.ScrollViewRect = newRect;
} }
// Calc rect for script view // Calc rect for script view
Rect scriptViewRect = new Rect(0, 0, this.position.width / flowchart.zoom, this.position.height / flowchart.zoom); Rect scriptViewRect = new Rect(0, 0, this.position.width / flowchart.Zoom, this.position.height / flowchart.Zoom);
EditorZoomArea.Begin(flowchart.zoom, scriptViewRect); EditorZoomArea.Begin(flowchart.Zoom, scriptViewRect);
DrawGrid(flowchart); DrawGrid(flowchart);
@ -245,7 +247,7 @@ namespace Fungus
Event.current.type == EventType.MouseDown && Event.current.type == EventType.MouseDown &&
!mouseOverVariables) !mouseOverVariables)
{ {
flowchart.selectedBlock = null; flowchart.SelectedBlock = null;
if (!EditorGUI.actionKey) if (!EditorGUI.actionKey)
{ {
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
@ -277,46 +279,49 @@ namespace Fungus
{ {
Block block = blocks[i]; Block block = blocks[i];
float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.blockName)).x + 10; float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.BlockName)).x + 10;
float nodeWidthB = 0f; float nodeWidthB = 0f;
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
nodeWidthB = nodeStyle.CalcSize(new GUIContent(block.eventHandler.GetSummary())).x + 10; nodeWidthB = nodeStyle.CalcSize(new GUIContent(block._EventHandler.GetSummary())).x + 10;
} }
block.nodeRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120);
block.nodeRect.height = 40;
if (Event.current.button == 0) if (Event.current.button == 0)
{ {
Rect tempRect = block._NodeRect;
tempRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120);
tempRect.height = 40;
if (Event.current.type == EventType.MouseDrag && dragWindowId == i) if (Event.current.type == EventType.MouseDrag && dragWindowId == i)
{ {
block.nodeRect.x += Event.current.delta.x; tempRect.x += Event.current.delta.x;
block.nodeRect.y += Event.current.delta.y; tempRect.y += Event.current.delta.y;
forceRepaintCount = 6; forceRepaintCount = 6;
} }
else if (Event.current.type == EventType.MouseUp && else if (Event.current.type == EventType.MouseUp &&
dragWindowId == i) dragWindowId == i)
{ {
Vector2 newPos = new Vector2(block.nodeRect.x, block.nodeRect.y); Vector2 newPos = new Vector2(tempRect.x, tempRect.y);
block.nodeRect.x = startDragPosition.x; tempRect.x = startDragPosition.x;
block.nodeRect.y = startDragPosition.y; tempRect.y = startDragPosition.y;
Undo.RecordObject(block, "Node Position"); Undo.RecordObject(block, "Node Position");
block.nodeRect.x = newPos.x; tempRect.x = newPos.x;
block.nodeRect.y = newPos.y; tempRect.y = newPos.y;
dragWindowId = -1; dragWindowId = -1;
forceRepaintCount = 6; forceRepaintCount = 6;
} }
block._NodeRect = tempRect;
} }
Rect windowRect = new Rect(block.nodeRect); Rect windowRect = new Rect(block._NodeRect);
windowRect.x += flowchart.scrollPos.x; windowRect.x += flowchart.ScrollPos.x;
windowRect.y += flowchart.scrollPos.y; windowRect.y += flowchart.ScrollPos.y;
GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle); GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle);
@ -330,10 +335,10 @@ namespace Fungus
// Draw Event Handler labels // Draw Event Handler labels
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
string handlerLabel = ""; string handlerLabel = "";
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(block.eventHandler.GetType()); EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(block._EventHandler.GetType());
if (info != null) if (info != null)
{ {
handlerLabel = "<" + info.EventHandlerName + "> "; handlerLabel = "<" + info.EventHandlerName + "> ";
@ -345,10 +350,10 @@ namespace Fungus
handlerStyle.margin.bottom = 0; handlerStyle.margin.bottom = 0;
handlerStyle.alignment = TextAnchor.MiddleCenter; handlerStyle.alignment = TextAnchor.MiddleCenter;
Rect rect = new Rect(block.nodeRect); Rect rect = new Rect(block._NodeRect);
rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block.nodeRect.width); rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block._NodeRect.width);
rect.x += flowchart.scrollPos.x; rect.x += flowchart.ScrollPos.x;
rect.y += flowchart.scrollPos.y - rect.height; rect.y += flowchart.ScrollPos.y - rect.height;
GUI.Label(rect, handlerLabel, handlerStyle); GUI.Label(rect, handlerLabel, handlerStyle);
} }
@ -362,23 +367,23 @@ namespace Fungus
{ {
if (b.IsExecuting()) if (b.IsExecuting())
{ {
b.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; b.ExecutingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime;
b.activeCommand.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; b.ActiveCommand.ExecutingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime;
forceRepaintCount = 6; forceRepaintCount = 6;
} }
if (b.executingIconTimer > Time.realtimeSinceStartup) if (b.ExecutingIconTimer > Time.realtimeSinceStartup)
{ {
Rect rect = new Rect(b.nodeRect); Rect rect = new Rect(b._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 (!b.IsExecuting()) if (!b.IsExecuting())
{ {
float alpha = (b.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; float alpha = (b.ExecutingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime;
alpha = Mathf.Clamp01(alpha); alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(1f, 1f, 1f, alpha); GUI.color = new Color(1f, 1f, 1f, alpha);
} }
@ -408,15 +413,15 @@ namespace Fungus
return; return;
} }
Vector2 min = blocks[0].nodeRect.min; Vector2 min = blocks[0]._NodeRect.min;
Vector2 max = blocks[0].nodeRect.max; Vector2 max = blocks[0]._NodeRect.max;
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
min.x = Mathf.Min(min.x, block.nodeRect.center.x); min.x = Mathf.Min(min.x, block._NodeRect.center.x);
min.y = Mathf.Min(min.y, block.nodeRect.center.y); min.y = Mathf.Min(min.y, block._NodeRect.center.y);
max.x = Mathf.Max(max.x, block.nodeRect.center.x); max.x = Mathf.Max(max.x, block._NodeRect.center.x);
max.y = Mathf.Max(max.y, block.nodeRect.center.y); max.y = Mathf.Max(max.y, block._NodeRect.center.y);
} }
Vector2 center = (min + max) * -0.5f; Vector2 center = (min + max) * -0.5f;
@ -424,7 +429,7 @@ namespace Fungus
center.x += position.width * 0.5f; center.x += position.width * 0.5f;
center.y += position.height * 0.5f; center.y += position.height * 0.5f;
flowchart.centerPosition = center; flowchart.CenterPosition = center;
} }
protected virtual void PanAndZoom(Flowchart flowchart) protected virtual void PanAndZoom(Flowchart flowchart)
@ -454,7 +459,7 @@ namespace Fungus
if (drag) if (drag)
{ {
flowchart.scrollPos += Event.current.delta; flowchart.ScrollPos += Event.current.delta;
forceRepaintCount = 6; forceRepaintCount = 6;
} }
@ -475,16 +480,16 @@ namespace Fungus
if (zoom) if (zoom)
{ {
flowchart.zoom -= Event.current.delta.y * 0.01f; flowchart.Zoom -= Event.current.delta.y * 0.01f;
flowchart.zoom = Mathf.Clamp(flowchart.zoom, minZoomValue, maxZoomValue); flowchart.Zoom = Mathf.Clamp(flowchart.Zoom, minZoomValue, maxZoomValue);
forceRepaintCount = 6; forceRepaintCount = 6;
} }
} }
protected virtual void DrawGrid(Flowchart flowchart) protected virtual void DrawGrid(Flowchart flowchart)
{ {
float width = this.position.width / flowchart.zoom; float width = this.position.width / flowchart.Zoom;
float height = this.position.height / flowchart.zoom; float height = this.position.height / flowchart.Zoom;
// Match background color of scene view // Match background color of scene view
if (EditorGUIUtility.isProSkin) if (EditorGUIUtility.isProSkin)
@ -502,14 +507,14 @@ namespace Fungus
float gridSize = 128f; float gridSize = 128f;
float x = flowchart.scrollPos.x % gridSize; float x = flowchart.ScrollPos.x % gridSize;
while (x < width) while (x < width)
{ {
GLDraw.DrawLine(new Vector2(x, 0), new Vector2(x, height), color, 1f); GLDraw.DrawLine(new Vector2(x, 0), new Vector2(x, height), color, 1f);
x += gridSize; x += gridSize;
} }
float y = (flowchart.scrollPos.y % gridSize); float y = (flowchart.ScrollPos.y % gridSize);
while (y < height) while (y < height)
{ {
if (y >= 0) if (y >= 0)
@ -524,11 +529,11 @@ namespace Fungus
{ {
// Select the block and also select currently executing command // Select the block and also select currently executing command
ShowBlockInspector(flowchart); ShowBlockInspector(flowchart);
flowchart.selectedBlock = block; flowchart.SelectedBlock = block;
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
if (block.activeCommand != null) if (block.ActiveCommand != null)
{ {
flowchart.AddSelectedCommand(block.activeCommand); flowchart.AddSelectedCommand(block.ActiveCommand);
} }
} }
@ -537,7 +542,7 @@ namespace Fungus
Block newBlock = flowchart.CreateBlock(position); Block newBlock = flowchart.CreateBlock(position);
Undo.RegisterCreatedObjectUndo(newBlock, "New Block"); Undo.RegisterCreatedObjectUndo(newBlock, "New Block");
ShowBlockInspector(flowchart); ShowBlockInspector(flowchart);
flowchart.selectedBlock = newBlock; flowchart.SelectedBlock = newBlock;
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
return newBlock; return newBlock;
@ -545,7 +550,7 @@ namespace Fungus
protected virtual void DeleteBlock(Flowchart flowchart, Block block) protected virtual void DeleteBlock(Flowchart flowchart, Block block)
{ {
foreach (Command command in block.commandList) foreach (Command command in block.CommandList)
{ {
Undo.DestroyObjectImmediate(command); Undo.DestroyObjectImmediate(command);
} }
@ -574,8 +579,8 @@ namespace Fungus
Event.current.alt == false) Event.current.alt == false)
{ {
dragWindowId = windowId; dragWindowId = windowId;
startDragPosition.x = block.nodeRect.x; startDragPosition.x = block._NodeRect.x;
startDragPosition.y = block.nodeRect.y; startDragPosition.y = block._NodeRect.y;
} }
if (windowId < windowBlockMap.Count) if (windowId < windowBlockMap.Count)
@ -588,11 +593,11 @@ namespace Fungus
} }
} }
bool selected = (flowchart.selectedBlock == block); bool selected = (flowchart.SelectedBlock == block);
GUIStyle nodeStyleCopy = new GUIStyle(nodeStyle); GUIStyle nodeStyleCopy = new GUIStyle(nodeStyle);
if (block.eventHandler != null) if (block._EventHandler != null)
{ {
nodeStyleCopy.normal.background = selected ? FungusEditorResources.texEventNodeOn : FungusEditorResources.texEventNodeOff; nodeStyleCopy.normal.background = selected ? FungusEditorResources.texEventNodeOn : FungusEditorResources.texEventNodeOff;
} }
@ -624,17 +629,19 @@ namespace Fungus
nodeStyleCopy.normal.textColor = Color.black; nodeStyleCopy.normal.textColor = Color.black;
// Make sure node is wide enough to fit the node name text // Make sure node is wide enough to fit the node name text
float width = nodeStyleCopy.CalcSize(new GUIContent(block.blockName)).x; float width = nodeStyleCopy.CalcSize(new GUIContent(block.BlockName)).x;
block.nodeRect.width = Mathf.Max (block.nodeRect.width, width); Rect tempRect = block._NodeRect;
tempRect.width = Mathf.Max (block._NodeRect.width, width);
block._NodeRect = tempRect;
GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.white;
GUILayout.Box(block.blockName, nodeStyleCopy, GUILayout.Width(block.nodeRect.width), GUILayout.Height(block.nodeRect.height)); GUILayout.Box(block.BlockName, nodeStyleCopy, GUILayout.Width(block._NodeRect.width), GUILayout.Height(block._NodeRect.height));
if (block.description.Length > 0) if (block.Description.Length > 0)
{ {
GUIStyle descriptionStyle = new GUIStyle(EditorStyles.helpBox); GUIStyle descriptionStyle = new GUIStyle(EditorStyles.helpBox);
descriptionStyle.wordWrap = true; descriptionStyle.wordWrap = true;
GUILayout.Label(block.description, descriptionStyle); GUILayout.Label(block.Description, descriptionStyle);
} }
if (Event.current.type == EventType.ContextClick) if (Event.current.type == EventType.ContextClick)
@ -657,9 +664,9 @@ namespace Fungus
List<Block> connectedBlocks = new List<Block>(); List<Block> connectedBlocks = new List<Block>();
bool blockIsSelected = (flowchart.selectedBlock == block); bool blockIsSelected = (flowchart.SelectedBlock == block);
foreach (Command command in block.commandList) foreach (Command command in block.CommandList)
{ {
if (command == null) if (command == null)
{ {
@ -667,7 +674,7 @@ namespace Fungus
} }
bool commandIsSelected = false; bool commandIsSelected = false;
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (selectedCommand == command) if (selectedCommand == command)
{ {
@ -676,7 +683,7 @@ namespace Fungus
} }
} }
bool highlight = command.isExecuting || (blockIsSelected && commandIsSelected); bool highlight = command.IsExecuting || (blockIsSelected && commandIsSelected);
if (highlightedOnly && !highlight || if (highlightedOnly && !highlight ||
!highlightedOnly && highlight) !highlightedOnly && highlight)
@ -696,13 +703,13 @@ namespace Fungus
continue; continue;
} }
Rect startRect = new Rect(block.nodeRect); Rect startRect = new Rect(block._NodeRect);
startRect.x += flowchart.scrollPos.x; startRect.x += flowchart.ScrollPos.x;
startRect.y += flowchart.scrollPos.y; startRect.y += flowchart.ScrollPos.y;
Rect endRect = new Rect(blockB.nodeRect); Rect endRect = new Rect(blockB._NodeRect);
endRect.x += flowchart.scrollPos.x; endRect.x += flowchart.ScrollPos.x;
endRect.y += flowchart.scrollPos.y; endRect.y += flowchart.ScrollPos.y;
DrawRectConnection(startRect, endRect, highlight); DrawRectConnection(startRect, endRect, highlight);
} }
@ -769,18 +776,18 @@ namespace Fungus
Flowchart flowchart = GetFlowchart(); Flowchart flowchart = GetFlowchart();
Block block = obj as Block; Block block = obj as Block;
Vector2 newPosition = new Vector2(block.nodeRect.position.x + Vector2 newPosition = new Vector2(block._NodeRect.position.x +
block.nodeRect.width + 20, block._NodeRect.width + 20,
block.nodeRect.y); block._NodeRect.y);
Block oldBlock = block; Block oldBlock = block;
Block newBlock = FlowchartWindow.CreateBlock(flowchart, newPosition); Block newBlock = FlowchartWindow.CreateBlock(flowchart, newPosition);
newBlock.blockName = flowchart.GetUniqueBlockKey(oldBlock.blockName + " (Copy)"); newBlock.BlockName = flowchart.GetUniqueBlockKey(oldBlock.BlockName + " (Copy)");
Undo.RecordObject(newBlock, "Duplicate Block"); Undo.RecordObject(newBlock, "Duplicate Block");
foreach (Command command in oldBlock.commandList) foreach (Command command in oldBlock.CommandList)
{ {
if (ComponentUtility.CopyComponent(command)) if (ComponentUtility.CopyComponent(command))
{ {
@ -790,8 +797,8 @@ namespace Fungus
Command pastedCommand = commands.Last<Command>(); Command pastedCommand = commands.Last<Command>();
if (pastedCommand != null) if (pastedCommand != null)
{ {
pastedCommand.itemId = flowchart.NextItemId(); pastedCommand.ItemId = flowchart.NextItemId();
newBlock.commandList.Add (pastedCommand); newBlock.CommandList.Add (pastedCommand);
} }
} }
@ -800,9 +807,9 @@ namespace Fungus
} }
} }
if (oldBlock.eventHandler != null) if (oldBlock._EventHandler != null)
{ {
if (ComponentUtility.CopyComponent(oldBlock.eventHandler)) if (ComponentUtility.CopyComponent(oldBlock._EventHandler))
{ {
if (ComponentUtility.PasteComponentAsNew(flowchart.gameObject)) if (ComponentUtility.PasteComponentAsNew(flowchart.gameObject))
{ {
@ -810,8 +817,8 @@ namespace Fungus
EventHandler pastedEventHandler = eventHandlers.Last<EventHandler>(); EventHandler pastedEventHandler = eventHandlers.Last<EventHandler>();
if (pastedEventHandler != null) if (pastedEventHandler != null)
{ {
pastedEventHandler.parentBlock = newBlock; pastedEventHandler.ParentBlock = newBlock;
newBlock.eventHandler = pastedEventHandler; newBlock._EventHandler = pastedEventHandler;
} }
} }
} }

36
Assets/Fungus/Flowchart/Editor/InvokeMethodEditor.cs

@ -26,23 +26,23 @@ namespace Fungus
targetMethod = target as InvokeMethod; targetMethod = target as InvokeMethod;
if (targetMethod == null || targetMethod.targetObject == null) if (targetMethod == null || targetMethod.TargetObject == null)
return; return;
SerializedObject objSerializedTarget = new SerializedObject(targetMethod); SerializedObject objSerializedTarget = new SerializedObject(targetMethod);
string component = ShowComponents(objSerializedTarget, targetMethod.targetObject); string component = ShowComponents(objSerializedTarget, targetMethod.TargetObject);
// show component methods if selected // show component methods if selected
if (!string.IsNullOrEmpty(component)) if (!string.IsNullOrEmpty(component))
{ {
var method = ShowMethods(objSerializedTarget, targetMethod.targetObject, component); var method = ShowMethods(objSerializedTarget, targetMethod.TargetObject, component);
// show method parameters if selected // show method parameters if selected
if (method != null) if (method != null)
{ {
objSerializedTarget.ApplyModifiedProperties(); objSerializedTarget.ApplyModifiedProperties();
ShowParameters(objSerializedTarget, targetMethod.targetObject, method); ShowParameters(objSerializedTarget, targetMethod.TargetObject, method);
ShowReturnValue(objSerializedTarget, method); ShowReturnValue(objSerializedTarget, method);
} }
} }
@ -172,7 +172,7 @@ namespace Fungus
if (isDrawn) if (isDrawn)
{ {
var vars = GetFungusVariablesByType(targetMethod.GetFlowchart().variables, objParam.ParameterType); var vars = GetFungusVariablesByType(targetMethod.GetFlowchart().Variables, objParam.ParameterType);
var values = new string[] { "<Value>" }; var values = new string[] { "<Value>" };
var displayValue = values.Concat(vars).ToList(); var displayValue = values.Concat(vars).ToList();
@ -241,7 +241,7 @@ namespace Fungus
if (saveReturnValueProp.boolValue) if (saveReturnValueProp.boolValue)
{ {
var vars = GetFungusVariablesByType(targetMethod.GetFlowchart().variables, method.ReturnType).ToList(); var vars = GetFungusVariablesByType(targetMethod.GetFlowchart().Variables, method.ReturnType).ToList();
int index = vars.IndexOf(returnValueKeyProp.stringValue); int index = vars.IndexOf(returnValueKeyProp.stringValue);
index = EditorGUILayout.Popup(method.ReturnType.Name, index, vars.ToArray()); index = EditorGUILayout.Popup(method.ReturnType.Name, index, vars.ToArray());
@ -367,51 +367,51 @@ namespace Fungus
if (type == typeof(int)) if (type == typeof(int))
{ {
result = (from v in variables where v.GetType() == typeof(IntegerVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(IntegerVariable) select v.Key).ToArray();
} }
else if (type == typeof(bool)) else if (type == typeof(bool))
{ {
result = (from v in variables where v.GetType() == typeof(BooleanVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(BooleanVariable) select v.Key).ToArray();
} }
else if (type == typeof(float)) else if (type == typeof(float))
{ {
result = (from v in variables where v.GetType() == typeof(FloatVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(FloatVariable) select v.Key).ToArray();
} }
else if (type == typeof(string)) else if (type == typeof(string))
{ {
result = (from v in variables where v.GetType() == typeof(StringVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(StringVariable) select v.Key).ToArray();
} }
else if (type == typeof(Color)) else if (type == typeof(Color))
{ {
result = (from v in variables where v.GetType() == typeof(ColorVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(ColorVariable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.GameObject)) else if (type == typeof(UnityEngine.GameObject))
{ {
result = (from v in variables where v.GetType() == typeof(GameObjectVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(GameObjectVariable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.Material)) else if (type == typeof(UnityEngine.Material))
{ {
result = (from v in variables where v.GetType() == typeof(MaterialVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(MaterialVariable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.Sprite)) else if (type == typeof(UnityEngine.Sprite))
{ {
result = (from v in variables where v.GetType() == typeof(SpriteVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(SpriteVariable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.Texture)) else if (type == typeof(UnityEngine.Texture))
{ {
result = (from v in variables where v.GetType() == typeof(TextureVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(TextureVariable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.Vector2)) else if (type == typeof(UnityEngine.Vector2))
{ {
result = (from v in variables where v.GetType() == typeof(Vector2Variable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(Vector2Variable) select v.Key).ToArray();
} }
else if (type == typeof(UnityEngine.Vector3)) else if (type == typeof(UnityEngine.Vector3))
{ {
result = (from v in variables where v.GetType() == typeof(Vector3Variable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(Vector3Variable) select v.Key).ToArray();
} }
else if (type.IsSubclassOf(typeof(UnityEngine.Object))) else if (type.IsSubclassOf(typeof(UnityEngine.Object)))
{ {
result = (from v in variables where v.GetType() == typeof(ObjectVariable) select v.key).ToArray(); result = (from v in variables where v.GetType() == typeof(ObjectVariable) select v.Key).ToArray();
} }
return result; return result;

4
Assets/Fungus/Flowchart/Editor/LabelEditor.cs

@ -32,7 +32,7 @@ namespace Fungus
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
foreach (Command command in block.commandList) foreach (Command command in block.CommandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label == null) if (label == null)
@ -40,7 +40,7 @@ namespace Fungus
continue; continue;
} }
labelKeys.Add(label.key); labelKeys.Add(label.Key);
labelObjects.Add(label); labelObjects.Add(label);
index++; index++;

2
Assets/Fungus/Flowchart/Editor/SetVariableEditor.cs

@ -73,7 +73,7 @@ namespace Fungus
} }
int selectedIndex = 0; int selectedIndex = 0;
switch (t.setOperator) switch (t._SetOperator)
{ {
default: default:
case SetVariable.SetOperator.Assign: case SetVariable.SetOperator.Assign:

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

@ -50,7 +50,7 @@ namespace Fungus
variableKeys.Add(defaultText); variableKeys.Add(defaultText);
variableObjects.Add(null); variableObjects.Add(null);
List<Variable> variables = flowchart.variables; List<Variable> variables = flowchart.Variables;
int index = 0; int index = 0;
int selectedIndex = 0; int selectedIndex = 0;
@ -63,7 +63,7 @@ namespace Fungus
// occurs we just skip displaying the property for this frame. // occurs we just skip displaying the property for this frame.
if (selectedVariable != null && if (selectedVariable != null &&
selectedVariable.gameObject != flowchart.gameObject && selectedVariable.gameObject != flowchart.gameObject &&
selectedVariable.scope == VariableScope.Private) selectedVariable.Scope == VariableScope.Private)
{ {
property.objectReferenceValue = null; property.objectReferenceValue = null;
return; return;
@ -79,7 +79,7 @@ namespace Fungus
} }
} }
variableKeys.Add(v.key); variableKeys.Add(v.Key);
variableObjects.Add(v); variableObjects.Add(v);
index++; index++;
@ -109,7 +109,7 @@ namespace Fungus
} }
} }
variableKeys.Add(fs.name + " / " + v.key); variableKeys.Add(fs.name + " / " + v.Key);
variableObjects.Add(v); variableObjects.Add(v);
index++; index++;

18
Assets/Fungus/Flowchart/Editor/VariableListAdaptor.cs

@ -133,15 +133,15 @@ namespace Fungus
// Highlight if an active or selected command is referencing this variable // Highlight if an active or selected command is referencing this variable
bool highlight = false; bool highlight = false;
if (flowchart.selectedBlock != null) if (flowchart.SelectedBlock != null)
{ {
if (Application.isPlaying && flowchart.selectedBlock.IsExecuting()) if (Application.isPlaying && flowchart.SelectedBlock.IsExecuting())
{ {
highlight = flowchart.selectedBlock.activeCommand.HasReference(variable); highlight = flowchart.SelectedBlock.ActiveCommand.HasReference(variable);
} }
else if (!Application.isPlaying && flowchart.selectedCommands.Count > 0) else if (!Application.isPlaying && flowchart.SelectedCommands.Count > 0)
{ {
foreach (Command selectedCommand in flowchart.selectedCommands) foreach (Command selectedCommand in flowchart.SelectedCommands)
{ {
if (selectedCommand == null) if (selectedCommand == null)
{ {
@ -163,8 +163,8 @@ namespace Fungus
GUI.Box(position, ""); GUI.Box(position, "");
} }
string key = variable.key; string key = variable.Key;
VariableScope scope = variable.scope; VariableScope scope = variable.Scope;
// To access properties in a monobehavior, you have to new a SerializedObject // To access properties in a monobehavior, you have to new a SerializedObject
// http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html // http://answers.unity3d.com/questions/629803/findrelativeproperty-never-worked-for-me-how-does.html
@ -174,7 +174,7 @@ namespace Fungus
GUI.Label(rects[0], variableInfo.VariableType); GUI.Label(rects[0], variableInfo.VariableType);
key = EditorGUI.TextField(rects[1], variable.key); key = EditorGUI.TextField(rects[1], variable.Key);
SerializedProperty keyProp = variableObject.FindProperty("key"); SerializedProperty keyProp = variableObject.FindProperty("key");
keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable); keyProp.stringValue = flowchart.GetUniqueVariableKey(key, variable);
@ -182,7 +182,7 @@ namespace Fungus
EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent("")); EditorGUI.PropertyField(rects[2], defaultProp, new GUIContent(""));
SerializedProperty scopeProp = variableObject.FindProperty("scope"); SerializedProperty scopeProp = variableObject.FindProperty("scope");
scope = (VariableScope)EditorGUI.EnumPopup(rects[3], variable.scope); scope = (VariableScope)EditorGUI.EnumPopup(rects[3], variable.Scope);
scopeProp.enumValueIndex = (int)scope; scopeProp.enumValueIndex = (int)scope;
variableObject.ApplyModifiedProperties(); variableObject.ApplyModifiedProperties();

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

@ -22,39 +22,44 @@ namespace Fungus
Executing, Executing,
} }
[NonSerialized] protected ExecutionState executionState;
public ExecutionState executionState;
[HideInInspector] public ExecutionState State { get { return executionState; } }
public int itemId = -1; // Invalid flowchart item id
[SerializeField] protected int itemId = -1; // Invalid flowchart item id
public int ItemId { get { return itemId; } set { itemId = value; } }
[FormerlySerializedAs("sequenceName")] [FormerlySerializedAs("sequenceName")]
[Tooltip("The name of the block node as displayed in the Flowchart window")] [Tooltip("The name of the block node as displayed in the Flowchart window")]
public string blockName = "New Block"; [SerializeField] protected string blockName = "New Block";
public string BlockName { get { return blockName; } set { blockName = value; } }
[TextArea(2, 5)] [TextArea(2, 5)]
[Tooltip("Description text to display under the block node")] [Tooltip("Description text to display under the block node")]
public string description = ""; [SerializeField] protected string description = "";
public string Description { get { return description; } }
[Tooltip("An optional Event Handler which can execute the block when an event occurs")] [Tooltip("An optional Event Handler which can execute the block when an event occurs")]
public EventHandler eventHandler; [SerializeField] protected EventHandler eventHandler;
public EventHandler _EventHandler { get { return eventHandler; } set { eventHandler = value; } }
[HideInInspector] protected Command activeCommand;
[System.NonSerialized]
public Command activeCommand; public Command ActiveCommand { get { return activeCommand; } }
// Index of last command executed before the current one // Index of last command executed before the current one
// -1 indicates no previous command // -1 indicates no previous command
[HideInInspector] protected int previousActiveCommandIndex = -1;
[System.NonSerialized]
public int previousActiveCommandIndex = -1; public float ExecutingIconTimer { get; set; }
[HideInInspector] [SerializeField] protected List<Command> commandList = new List<Command>();
[System.NonSerialized]
public float executingIconTimer;
[HideInInspector] public List<Command> CommandList { get { return commandList; } }
public List<Command> commandList = new List<Command>();
protected int executionCount; protected int executionCount;
@ -66,8 +71,9 @@ namespace Fungus
/** /**
* Controls the next command to execute in the block execution coroutine. * Controls the next command to execute in the block execution coroutine.
*/ */
[NonSerialized] protected int jumpToCommandIndex = -1;
public int jumpToCommandIndex = -1;
public int JumpToCommandIndex { set { jumpToCommandIndex = value; } }
protected bool executionInfoSet = false; protected bool executionInfoSet = false;
@ -88,8 +94,8 @@ namespace Fungus
continue; continue;
} }
command.parentBlock = this; command.ParentBlock = this;
command.commandIndex = index++; command.CommandIndex = index++;
} }
// Ensure all commands are at their correct indent level // Ensure all commands are at their correct indent level
@ -114,7 +120,7 @@ namespace Fungus
continue; continue;
} }
command.commandIndex = index++; command.CommandIndex = index++;
} }
} }
#endif #endif
@ -124,19 +130,6 @@ namespace Fungus
return GetComponent<Flowchart>(); return GetComponent<Flowchart>();
} }
public virtual bool HasError()
{
foreach (Command command in commandList)
{
if (command.errorMessage.Length > 0)
{
return true;
}
}
return false;
}
public virtual bool IsExecuting() public virtual bool IsExecuting()
{ {
return (executionState == ExecutionState.Executing); return (executionState == ExecutionState.Executing);
@ -179,7 +172,7 @@ namespace Fungus
#if UNITY_EDITOR #if UNITY_EDITOR
// Select the executing block & the first command // Select the executing block & the first command
flowchart.selectedBlock = this; flowchart.SelectedBlock = this;
if (commandList.Count > 0) if (commandList.Count > 0)
{ {
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
@ -205,7 +198,7 @@ namespace Fungus
commandList[i].GetType() == typeof(Comment) || commandList[i].GetType() == typeof(Comment) ||
commandList[i].GetType() == typeof(Label))) commandList[i].GetType() == typeof(Label)))
{ {
i = commandList[i].commandIndex + 1; i = commandList[i].CommandIndex + 1;
} }
if (i >= commandList.Count) if (i >= commandList.Count)
@ -220,7 +213,7 @@ namespace Fungus
} }
else else
{ {
previousActiveCommandIndex = activeCommand.commandIndex; previousActiveCommandIndex = activeCommand.CommandIndex;
} }
Command command = commandList[i]; Command command = commandList[i];
@ -229,18 +222,18 @@ namespace Fungus
if (flowchart.gameObject.activeInHierarchy) if (flowchart.gameObject.activeInHierarchy)
{ {
// Auto select a command in some situations // Auto select a command in some situations
if ((flowchart.selectedCommands.Count == 0 && i == 0) || if ((flowchart.SelectedCommands.Count == 0 && i == 0) ||
(flowchart.selectedCommands.Count == 1 && flowchart.selectedCommands[0].commandIndex == previousActiveCommandIndex)) (flowchart.SelectedCommands.Count == 1 && flowchart.SelectedCommands[0].CommandIndex == previousActiveCommandIndex))
{ {
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(commandList[i]); flowchart.AddSelectedCommand(commandList[i]);
} }
} }
command.isExecuting = true; command.IsExecuting = true;
// This icon timer is managed by the FlowchartWindow class, but we also need to // 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. // set it here in case a command starts and finishes execution before the next window update.
command.executingIconTimer = Time.realtimeSinceStartup + executingIconFadeTime; 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()
@ -250,13 +243,13 @@ namespace Fungus
} }
#if UNITY_EDITOR #if UNITY_EDITOR
if (flowchart.stepPause > 0f) if (flowchart.StepPause > 0f)
{ {
yield return new WaitForSeconds(flowchart.stepPause); yield return new WaitForSeconds(flowchart.StepPause);
} }
#endif #endif
command.isExecuting = false; command.IsExecuting = false;
} }
executionState = ExecutionState.Idle; executionState = ExecutionState.Idle;
@ -273,7 +266,7 @@ namespace Fungus
// Tell the executing command to stop immediately // Tell the executing command to stop immediately
if (activeCommand != null) if (activeCommand != null)
{ {
activeCommand.isExecuting = false; activeCommand.IsExecuting = false;
activeCommand.OnStopExecuting(); activeCommand.OnStopExecuting();
} }
@ -323,7 +316,7 @@ namespace Fungus
// Negative indent level is not permitted // Negative indent level is not permitted
indentLevel = Math.Max(indentLevel, 0); indentLevel = Math.Max(indentLevel, 0);
command.indentLevel = indentLevel; command.IndentLevel = indentLevel;
if (command.OpenBlock()) if (command.OpenBlock())
{ {

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

@ -39,36 +39,37 @@ namespace Fungus
{ {
[FormerlySerializedAs("commandId")] [FormerlySerializedAs("commandId")]
[HideInInspector] [HideInInspector]
public int itemId = -1; // Invalid flowchart item id [SerializeField] protected int itemId = -1; // Invalid flowchart item id
[HideInInspector] public int ItemId { get { return itemId; } set { itemId = value; } }
public string errorMessage = "";
protected string errorMessage = "";
public string ErrorMessage { get { return errorMessage; } }
[HideInInspector] [HideInInspector]
public int indentLevel; [SerializeField] protected int indentLevel;
public int IndentLevel { get { return indentLevel; } set { indentLevel = value; } }
[NonSerialized] public int CommandIndex { get; set; }
public int commandIndex;
/** /**
* Set to true by the parent block while the command is executing. * Set to true by the parent block while the command is executing.
*/ */
[NonSerialized] public bool IsExecuting { get; set; }
public bool isExecuting;
/** /**
* Timer used to control appearance of executing icon in inspector. * Timer used to control appearance of executing icon in inspector.
*/ */
[NonSerialized] public float ExecutingIconTimer { get; set; }
public float executingIconTimer;
/** /**
* Reference to the Block object that this command belongs to. * Reference to the Block object that this command belongs to.
* This reference is only populated at runtime and in the editor when the * This reference is only populated at runtime and in the editor when the
* block is selected. * block is selected.
*/ */
[NonSerialized] public Block ParentBlock { get; set; }
public Block parentBlock;
public virtual Flowchart GetFlowchart() public virtual Flowchart GetFlowchart()
{ {
@ -89,27 +90,27 @@ namespace Fungus
public virtual void Continue() public virtual void Continue()
{ {
// This is a noop if the Block has already been stopped // This is a noop if the Block has already been stopped
if (isExecuting) if (IsExecuting)
{ {
Continue(commandIndex + 1); Continue(CommandIndex + 1);
} }
} }
public virtual void Continue(int nextCommandIndex) public virtual void Continue(int nextCommandIndex)
{ {
OnExit(); OnExit();
if (parentBlock != null) if (ParentBlock != null)
{ {
parentBlock.jumpToCommandIndex = nextCommandIndex; ParentBlock.JumpToCommandIndex = nextCommandIndex;
} }
} }
public virtual void StopParentBlock() public virtual void StopParentBlock()
{ {
OnExit(); OnExit();
if (parentBlock != null) if (ParentBlock != null)
{ {
parentBlock.Stop(); ParentBlock.Stop();
} }
} }
@ -215,7 +216,7 @@ namespace Fungus
return ""; return "";
} }
string localizationId = GetFlowchart().localizationId; string localizationId = GetFlowchart().LocalizationId;
if (localizationId.Length == 0) if (localizationId.Length == 0)
{ {
localizationId = flowchart.name; localizationId = flowchart.name;

16
Assets/Fungus/Flowchart/Scripts/Commands/Break.cs

@ -21,13 +21,13 @@ namespace Fungus
// Find index of previous while command // Find index of previous while command
int whileIndex = -1; int whileIndex = -1;
int whileIndentLevel = -1; int whileIndentLevel = -1;
for (int i = commandIndex - 1; i >=0; --i) for (int i = CommandIndex - 1; i >=0; --i)
{ {
While whileCommand = parentBlock.commandList[i] as While; While whileCommand = ParentBlock.CommandList[i] as While;
if (whileCommand != null) if (whileCommand != null)
{ {
whileIndex = i; whileIndex = i;
whileIndentLevel = whileCommand.indentLevel; whileIndentLevel = whileCommand.IndentLevel;
break; break;
} }
} }
@ -40,18 +40,18 @@ namespace Fungus
} }
// Find matching End statement at same indent level as While // Find matching End statement at same indent level as While
for (int i = whileIndex + 1; i < parentBlock.commandList.Count; ++i) for (int i = whileIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
End endCommand = parentBlock.commandList[i] as End; End endCommand = ParentBlock.CommandList[i] as End;
if (endCommand != null && if (endCommand != null &&
endCommand.indentLevel == whileIndentLevel) endCommand.IndentLevel == whileIndentLevel)
{ {
// Sanity check that break command is actually between the While and End commands // Sanity check that break command is actually between the While and End commands
if (commandIndex > whileIndex && commandIndex < endCommand.commandIndex) if (CommandIndex > whileIndex && CommandIndex < endCommand.CommandIndex)
{ {
// Continue at next command after End // Continue at next command after End
Continue (endCommand.commandIndex + 1); Continue (endCommand.CommandIndex + 1);
return; return;
} }
else else

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

@ -19,15 +19,15 @@ namespace Fungus
public class Call : Command public class Call : Command
{ {
[Tooltip("Flowchart which contains the block to execute. If none is specified then the current Flowchart is used.")] [Tooltip("Flowchart which contains the block to execute. If none is specified then the current Flowchart is used.")]
public Flowchart targetFlowchart; [SerializeField] protected Flowchart targetFlowchart;
[FormerlySerializedAs("targetSequence")] [FormerlySerializedAs("targetSequence")]
[Tooltip("Block to start executing")] [Tooltip("Block to start executing")]
public Block targetBlock; [SerializeField] protected Block targetBlock;
[Tooltip("Command index to start executing")] [Tooltip("Command index to start executing")]
[FormerlySerializedAs("commandIndex")] [FormerlySerializedAs("commandIndex")]
public int startIndex; [SerializeField] protected int startIndex;
public enum CallMode public enum CallMode
{ {
@ -37,7 +37,7 @@ namespace Fungus
} }
[Tooltip("Select if the calling block should stop or continue executing commands, or wait until the called block finishes.")] [Tooltip("Select if the calling block should stop or continue executing commands, or wait until the called block finishes.")]
public CallMode callMode; [SerializeField] protected CallMode callMode;
public override void OnEnter() public override void OnEnter()
{ {
@ -46,7 +46,7 @@ namespace Fungus
if (targetBlock != null) if (targetBlock != null)
{ {
// Check if calling your own parent block // Check if calling your own parent block
if (targetBlock == parentBlock) if (targetBlock == ParentBlock)
{ {
// Just ignore the callmode in this case, and jump to first command in list // Just ignore the callmode in this case, and jump to first command in list
Continue(0); Continue(0);
@ -58,7 +58,7 @@ namespace Fungus
if (callMode == CallMode.WaitUntilFinished) if (callMode == CallMode.WaitUntilFinished)
{ {
onComplete = delegate { onComplete = delegate {
flowchart.selectedBlock = parentBlock; flowchart.SelectedBlock = ParentBlock;
Continue(); Continue();
}; };
} }
@ -68,9 +68,9 @@ namespace Fungus
{ {
// If the executing block is currently selected then follow the execution // If the executing block is currently selected then follow the execution
// onto the next block in the inspector. // onto the next block in the inspector.
if (flowchart.selectedBlock == parentBlock) if (flowchart.SelectedBlock == ParentBlock)
{ {
flowchart.selectedBlock = targetBlock; flowchart.SelectedBlock = targetBlock;
} }
StartCoroutine(targetBlock.Execute(startIndex, onComplete)); StartCoroutine(targetBlock.Execute(startIndex, onComplete));
@ -110,7 +110,7 @@ namespace Fungus
} }
else else
{ {
summary = targetBlock.blockName; summary = targetBlock.BlockName;
} }
switch (callMode) switch (callMode)

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

@ -18,13 +18,13 @@ namespace Fungus
public class CallMethod : Command public class CallMethod : Command
{ {
[Tooltip("Target monobehavior which contains the method we want to call")] [Tooltip("Target monobehavior which contains the method we want to call")]
public GameObject targetObject; [SerializeField] protected GameObject targetObject;
[Tooltip("Name of the method to call")] [Tooltip("Name of the method to call")]
public string methodName = ""; [SerializeField] protected string methodName = "";
[Tooltip("Delay (in seconds) before the method will be called")] [Tooltip("Delay (in seconds) before the method will be called")]
public float delay; [SerializeField] protected float delay;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -16,11 +16,11 @@ namespace Fungus
public class Comment : Command public class Comment : Command
{ {
[Tooltip("Name of Commenter")] [Tooltip("Name of Commenter")]
public string commenterName = ""; [SerializeField] protected string commenterName = "";
[Tooltip("Text to display for this comment")] [Tooltip("Text to display for this comment")]
[TextArea(2,4)] [TextArea(2,4)]
public string commentText = ""; [SerializeField] protected string commentText = "";
public override void OnEnter() public override void OnEnter()
{ {

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

@ -23,7 +23,7 @@ namespace Fungus
public abstract class Condition : Command public abstract class Condition : Command
{ {
[Tooltip("The type of comparison to be performed")] [Tooltip("The type of comparison to be performed")]
public CompareOperator compareOperator; [SerializeField] protected CompareOperator compareOperator;
public static string GetOperatorDescription(CompareOperator compareOperator) public static string GetOperatorDescription(CompareOperator compareOperator)
{ {

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

@ -22,10 +22,10 @@ namespace Fungus
} }
[Tooltip("Display type of debug log info")] [Tooltip("Display type of debug log info")]
public DebugLogType logType; [SerializeField] protected DebugLogType logType;
[Tooltip("Text to write to the debug log. Supports variable substitution, e.g. {$Myvar}")] [Tooltip("Text to write to the debug log. Supports variable substitution, e.g. {$Myvar}")]
public StringDataMulti logMessage; [SerializeField] protected StringDataMulti logMessage;
public override void OnEnter () public override void OnEnter ()
{ {

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

@ -16,7 +16,7 @@ namespace Fungus
public class DeleteSaveKey : Command public class DeleteSaveKey : Command
{ {
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")]
public string key = ""; [SerializeField] protected string key = "";
public override void OnEnter() public override void OnEnter()
{ {

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

@ -18,7 +18,7 @@ namespace Fungus
public class Destroy : Command public class Destroy : Command
{ {
[Tooltip("Reference to game object to destroy")] [Tooltip("Reference to game object to destroy")]
public GameObjectData _targetGameObject; [SerializeField] protected GameObjectData _targetGameObject;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -17,13 +17,13 @@ namespace Fungus
{ {
public override void OnEnter() public override void OnEnter()
{ {
if (parentBlock == null) if (ParentBlock == null)
{ {
return; return;
} }
// 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)
{ {
StopParentBlock(); StopParentBlock();
return; return;
@ -31,17 +31,17 @@ namespace Fungus
// Find the next End command at the same indent level as this Else command // Find the next End command at the same indent level as this Else command
int indent = indentLevel; int indent = indentLevel;
for (int i = commandIndex + 1; i < parentBlock.commandList.Count; ++i) for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
Command command = parentBlock.commandList[i]; Command command = ParentBlock.CommandList[i];
if (command.indentLevel == indent) if (command.IndentLevel == indent)
{ {
System.Type type = command.GetType(); System.Type type = command.GetType();
if (type == typeof(End)) if (type == typeof(End))
{ {
// Execute command immediately after the EndIf command // Execute command immediately after the EndIf command
Continue(command.commandIndex + 1); Continue(command.CommandIndex + 1);
return; return;
} }
} }

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

@ -20,7 +20,7 @@ namespace Fungus
public override void OnEnter() public override void OnEnter()
{ {
System.Type previousCommandType = parentBlock.GetPreviousActiveCommandType(); System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType();
if (previousCommandType == typeof(If) || if (previousCommandType == typeof(If) ||
previousCommandType == typeof(ElseIf) ) previousCommandType == typeof(ElseIf) )
@ -34,7 +34,7 @@ namespace Fungus
// but will also jump to a following Else command. // but will also jump to a following Else command.
// 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)
{ {
StopParentBlock(); StopParentBlock();
return; return;
@ -42,17 +42,17 @@ namespace Fungus
// Find the next End command at the same indent level as this Else If command // Find the next End command at the same indent level as this Else If command
int indent = indentLevel; int indent = indentLevel;
for (int i = commandIndex + 1; i < parentBlock.commandList.Count; ++i) for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
Command command = parentBlock.commandList[i]; Command command = ParentBlock.CommandList[i];
if (command.indentLevel == indent) if (command.IndentLevel == indent)
{ {
System.Type type = command.GetType(); System.Type type = command.GetType();
if (type == typeof(End)) if (type == typeof(End))
{ {
// Execute command immediately after the Else or End command // Execute command immediately after the Else or End command
Continue(command.commandIndex + 1); Continue(command.CommandIndex + 1);
return; return;
} }
} }

9
Assets/Fungus/Flowchart/Scripts/Commands/End.cs

@ -16,16 +16,15 @@ namespace Fungus
[AddComponentMenu("")] [AddComponentMenu("")]
public class End : Command public class End : Command
{ {
[NonSerialized] public bool Loop { get; set; }
public bool loop = false;
public override void OnEnter() public override void OnEnter()
{ {
if (loop) if (Loop)
{ {
for (int i = commandIndex - 1; i >= 0; --i) for (int i = CommandIndex - 1; i >= 0; --i)
{ {
System.Type commandType = parentBlock.commandList[i].GetType(); System.Type commandType = ParentBlock.CommandList[i].GetType();
if (commandType == typeof(While)) if (commandType == typeof(While))
{ {
Continue(i); Continue(i);

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

@ -21,23 +21,23 @@ namespace Fungus
typeof(IntegerVariable), typeof(IntegerVariable),
typeof(FloatVariable), typeof(FloatVariable),
typeof(StringVariable))] typeof(StringVariable))]
public Variable variable; [SerializeField] protected Variable variable;
[Tooltip("Boolean value to compare against")] [Tooltip("Boolean value to compare against")]
public BooleanData booleanData; [SerializeField] protected BooleanData booleanData;
[Tooltip("Integer value to compare against")] [Tooltip("Integer value to compare against")]
public IntegerData integerData; [SerializeField] protected IntegerData integerData;
[Tooltip("Float value to compare against")] [Tooltip("Float value to compare against")]
public FloatData floatData; [SerializeField] protected FloatData floatData;
[Tooltip("String value to compare against")] [Tooltip("String value to compare against")]
public StringDataMulti stringData; [SerializeField] protected StringDataMulti stringData;
public override void OnEnter() public override void OnEnter()
{ {
if (parentBlock == null) if (ParentBlock == null)
{ {
return; return;
} }
@ -100,16 +100,16 @@ namespace Fungus
protected virtual void OnFalse() protected virtual void OnFalse()
{ {
// Last command in block // Last command in block
if (commandIndex >= parentBlock.commandList.Count) if (CommandIndex >= ParentBlock.CommandList.Count)
{ {
StopParentBlock(); StopParentBlock();
return; return;
} }
// Find the next Else, ElseIf or End command at the same indent level as this If command // Find the next Else, ElseIf or End command at the same indent level as this If command
for (int i = commandIndex + 1; i < parentBlock.commandList.Count; ++i) for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
Command nextCommand = parentBlock.commandList[i]; Command nextCommand = ParentBlock.CommandList[i];
if (nextCommand == null) if (nextCommand == null)
{ {
@ -121,7 +121,7 @@ namespace Fungus
if (!nextCommand.enabled || if (!nextCommand.enabled ||
nextCommand.GetType() == typeof(Comment) || nextCommand.GetType() == typeof(Comment) ||
nextCommand.GetType() == typeof(Label) || nextCommand.GetType() == typeof(Label) ||
nextCommand.indentLevel != indentLevel) nextCommand.IndentLevel != indentLevel)
{ {
continue; continue;
} }
@ -130,7 +130,7 @@ namespace Fungus
if (type == typeof(Else) || if (type == typeof(Else) ||
type == typeof(End)) type == typeof(End))
{ {
if (i >= parentBlock.commandList.Count - 1) if (i >= ParentBlock.CommandList.Count - 1)
{ {
// Last command in Block, so stop // Last command in Block, so stop
StopParentBlock(); StopParentBlock();
@ -138,7 +138,7 @@ namespace Fungus
else else
{ {
// Execute command immediately after the Else or End command // Execute command immediately after the Else or End command
Continue(nextCommand.commandIndex + 1); Continue(nextCommand.CommandIndex + 1);
return; return;
} }
} }
@ -162,7 +162,7 @@ namespace Fungus
return "Error: No variable selected"; return "Error: No variable selected";
} }
string summary = variable.key + " "; string summary = variable.Key + " ";
summary += Condition.GetOperatorDescription(compareOperator) + " "; summary += Condition.GetOperatorDescription(compareOperator) + " ";
if (variable.GetType() == typeof(BooleanVariable)) if (variable.GetType() == typeof(BooleanVariable))

30
Assets/Fungus/Flowchart/Scripts/Commands/InvokeEvent.cs

@ -35,36 +35,36 @@ namespace Fungus
} }
[Tooltip("Delay (in seconds) before the methods will be called")] [Tooltip("Delay (in seconds) before the methods will be called")]
public float delay; [SerializeField] protected float delay;
public InvokeType invokeType; [SerializeField] protected InvokeType invokeType;
[Tooltip("List of methods to call. Supports methods with no parameters or exactly one string, int, float or object parameter.")] [Tooltip("List of methods to call. Supports methods with no parameters or exactly one string, int, float or object parameter.")]
public UnityEvent staticEvent = new UnityEvent(); [SerializeField] protected UnityEvent staticEvent = new UnityEvent();
[Tooltip("Boolean parameter to pass to the invoked methods.")] [Tooltip("Boolean parameter to pass to the invoked methods.")]
public BooleanData booleanParameter; [SerializeField] protected BooleanData booleanParameter;
[Tooltip("List of methods to call. Supports methods with one boolean parameter.")] [Tooltip("List of methods to call. Supports methods with one boolean parameter.")]
public BooleanEvent booleanEvent = new BooleanEvent(); [SerializeField] protected BooleanEvent booleanEvent = new BooleanEvent();
[Tooltip("Integer parameter to pass to the invoked methods.")] [Tooltip("Integer parameter to pass to the invoked methods.")]
public IntegerData integerParameter; [SerializeField] protected IntegerData integerParameter;
[Tooltip("List of methods to call. Supports methods with one integer parameter.")] [Tooltip("List of methods to call. Supports methods with one integer parameter.")]
public IntegerEvent integerEvent = new IntegerEvent(); [SerializeField] protected IntegerEvent integerEvent = new IntegerEvent();
[Tooltip("Float parameter to pass to the invoked methods.")] [Tooltip("Float parameter to pass to the invoked methods.")]
public FloatData floatParameter; [SerializeField] protected FloatData floatParameter;
[Tooltip("List of methods to call. Supports methods with one float parameter.")] [Tooltip("List of methods to call. Supports methods with one float parameter.")]
public FloatEvent floatEvent = new FloatEvent(); [SerializeField] protected FloatEvent floatEvent = new FloatEvent();
[Tooltip("String parameter to pass to the invoked methods.")] [Tooltip("String parameter to pass to the invoked methods.")]
public StringDataMulti stringParameter; [SerializeField] protected StringDataMulti stringParameter;
[Tooltip("List of methods to call. Supports methods with one string parameter.")] [Tooltip("List of methods to call. Supports methods with one string parameter.")]
public StringEvent stringEvent = new StringEvent(); [SerializeField] protected StringEvent stringEvent = new StringEvent();
public override void OnEnter() public override void OnEnter()
{ {
@ -89,16 +89,16 @@ namespace Fungus
staticEvent.Invoke(); staticEvent.Invoke();
break; break;
case InvokeType.DynamicBoolean: case InvokeType.DynamicBoolean:
booleanEvent.Invoke(booleanParameter); booleanEvent.Invoke(booleanParameter.Value);
break; break;
case InvokeType.DynamicInteger: case InvokeType.DynamicInteger:
integerEvent.Invoke(integerParameter); integerEvent.Invoke(integerParameter.Value);
break; break;
case InvokeType.DynamicFloat: case InvokeType.DynamicFloat:
floatEvent.Invoke(floatParameter); floatEvent.Invoke(floatParameter.Value);
break; break;
case InvokeType.DynamicString: case InvokeType.DynamicString:
stringEvent.Invoke(stringParameter); stringEvent.Invoke(stringParameter.Value);
break; break;
} }
} }

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

@ -21,51 +21,53 @@ namespace Fungus
public class InvokeMethod : Command public class InvokeMethod : Command
{ {
[Tooltip("GameObject containing the component method to be invoked")] [Tooltip("GameObject containing the component method to be invoked")]
public GameObject targetObject; [SerializeField] protected GameObject targetObject;
public GameObject TargetObject { get { return targetObject; } }
[HideInInspector] [HideInInspector]
[Tooltip("Name of assembly containing the target component")] [Tooltip("Name of assembly containing the target component")]
public string targetComponentAssemblyName; [SerializeField] protected string targetComponentAssemblyName;
[HideInInspector] [HideInInspector]
[Tooltip("Full name of the target component")] [Tooltip("Full name of the target component")]
public string targetComponentFullname; [SerializeField] protected string targetComponentFullname;
[HideInInspector] [HideInInspector]
[Tooltip("Display name of the target component")] [Tooltip("Display name of the target component")]
public string targetComponentText; [SerializeField] protected string targetComponentText;
[HideInInspector] [HideInInspector]
[Tooltip("Name of target method to invoke on the target component")] [Tooltip("Name of target method to invoke on the target component")]
public string targetMethod; [SerializeField] protected string targetMethod;
[HideInInspector] [HideInInspector]
[Tooltip("Display name of target method to invoke on the target component")] [Tooltip("Display name of target method to invoke on the target component")]
public string targetMethodText; [SerializeField] protected string targetMethodText;
[HideInInspector] [HideInInspector]
[Tooltip("List of parameters to pass to the invoked method")] [Tooltip("List of parameters to pass to the invoked method")]
public InvokeMethodParameter[] methodParameters; [SerializeField] protected InvokeMethodParameter[] methodParameters;
[HideInInspector] [HideInInspector]
[Tooltip("If true, store the return value in a flowchart variable of the same type.")] [Tooltip("If true, store the return value in a flowchart variable of the same type.")]
public bool saveReturnValue; [SerializeField] protected bool saveReturnValue;
[HideInInspector] [HideInInspector]
[Tooltip("Name of Fungus variable to store the return value in")] [Tooltip("Name of Fungus variable to store the return value in")]
public string returnValueVariableKey; [SerializeField] protected string returnValueVariableKey;
[HideInInspector] [HideInInspector]
[Tooltip("The type of the return value")] [Tooltip("The type of the return value")]
public string returnValueType; [SerializeField] protected string returnValueType;
[HideInInspector] [HideInInspector]
[Tooltip("If true, list all inherited methods for the component")] [Tooltip("If true, list all inherited methods for the component")]
public bool showInherited; [SerializeField] protected bool showInherited;
[HideInInspector] [HideInInspector]
[Tooltip("The coroutine call behavior for methods that return IEnumerator")] [Tooltip("The coroutine call behavior for methods that return IEnumerator")]
public Fungus.Call.CallMode callMode; [SerializeField] protected Call.CallMode callMode;
protected Type componentType; protected Type componentType;
protected Component objComponent; protected Component objComponent;

10
Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs

@ -16,7 +16,7 @@ namespace Fungus
public class Jump : Command public class Jump : Command
{ {
[Tooltip("Name of a label in this block to jump to")] [Tooltip("Name of a label in this block to jump to")]
public StringData _targetLabel = new StringData(""); [SerializeField] protected StringData _targetLabel = new StringData("");
public override void OnEnter() public override void OnEnter()
{ {
@ -26,13 +26,13 @@ namespace Fungus
return; return;
} }
foreach (Command command in parentBlock.commandList) foreach (Command command in ParentBlock.CommandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label != null && if (label != null &&
label.key == _targetLabel.Value) label.Key == _targetLabel.Value)
{ {
Continue(label.commandIndex + 1); Continue(label.CommandIndex + 1);
return; return;
} }
} }
@ -65,7 +65,7 @@ namespace Fungus
{ {
if (targetLabelOLD != null) if (targetLabelOLD != null)
{ {
_targetLabel.Value = targetLabelOLD.key; _targetLabel.Value = targetLabelOLD.Key;
targetLabelOLD = null; targetLabelOLD = null;
} }
} }

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

@ -16,7 +16,9 @@ namespace Fungus
public class Label : Command public class Label : Command
{ {
[Tooltip("Display name for the label")] [Tooltip("Display name for the label")]
public string key = ""; [SerializeField] protected string key = "";
public string Key { get { return key; } }
public override void OnEnter() public override void OnEnter()
{ {

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

@ -21,10 +21,10 @@ namespace Fungus
public class LoadScene : Command public class LoadScene : Command
{ {
[Tooltip("Name of the scene to load. The scene must also be added to the build settings.")] [Tooltip("Name of the scene to load. The scene must also be added to the build settings.")]
public StringData _sceneName = new StringData(""); [SerializeField] protected StringData _sceneName = new StringData("");
[Tooltip("Image to display while loading the scene")] [Tooltip("Image to display while loading the scene")]
public Texture2D loadingImage; [SerializeField] protected Texture2D loadingImage;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -16,7 +16,7 @@ namespace Fungus
public class LoadVariable : Command public class LoadVariable : Command
{ {
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}\"")] [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}\"")]
public string key = ""; [SerializeField] protected string key = "";
[Tooltip("Variable to store the value in.")] [Tooltip("Variable to store the value in.")]
[VariableProperty(typeof(BooleanVariable), [VariableProperty(typeof(BooleanVariable),
@ -90,7 +90,7 @@ namespace Fungus
return "Error: No variable selected"; return "Error: No variable selected";
} }
return "'" + key + "' into " + variable.key; return "'" + key + "' into " + variable.Key;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

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

@ -16,7 +16,7 @@ namespace Fungus
public class LinkToWebsite : Command public class LinkToWebsite : Command
{ {
[Tooltip("URL to open in the browser")] [Tooltip("URL to open in the browser")]
public StringData url = new StringData(); [SerializeField] protected StringData url = new StringData();
public override void OnEnter() public override void OnEnter()
{ {

8
Assets/Fungus/Flowchart/Scripts/Commands/RandomFloat.cs

@ -16,13 +16,13 @@ namespace Fungus
{ {
[Tooltip("The variable whos value will be set")] [Tooltip("The variable whos value will be set")]
[VariableProperty(typeof(FloatVariable))] [VariableProperty(typeof(FloatVariable))]
public FloatVariable variable; [SerializeField] protected FloatVariable variable;
[Tooltip("Minimum value for random range")] [Tooltip("Minimum value for random range")]
public FloatData minValue; [SerializeField] protected FloatData minValue;
[Tooltip("Maximum value for random range")] [Tooltip("Maximum value for random range")]
public FloatData maxValue; [SerializeField] protected FloatData maxValue;
public override void OnEnter() public override void OnEnter()
{ {
@ -41,7 +41,7 @@ namespace Fungus
return "Error: Variable not selected"; return "Error: Variable not selected";
} }
return variable.key; return variable.Key;
} }
public override bool HasReference(Variable variable) public override bool HasReference(Variable variable)

8
Assets/Fungus/Flowchart/Scripts/Commands/RandomInteger.cs

@ -16,13 +16,13 @@ namespace Fungus
{ {
[Tooltip("The variable whos value will be set")] [Tooltip("The variable whos value will be set")]
[VariableProperty(typeof(IntegerVariable))] [VariableProperty(typeof(IntegerVariable))]
public IntegerVariable variable; [SerializeField] protected IntegerVariable variable;
[Tooltip("Minimum value for random range")] [Tooltip("Minimum value for random range")]
public IntegerData minValue; [SerializeField] protected IntegerData minValue;
[Tooltip("Maximum value for random range")] [Tooltip("Maximum value for random range")]
public IntegerData maxValue; [SerializeField] protected IntegerData maxValue;
public override void OnEnter() public override void OnEnter()
{ {
@ -41,7 +41,7 @@ namespace Fungus
return "Error: Variable not selected"; return "Error: Variable not selected";
} }
return variable.key; return variable.Key;
} }
public override bool HasReference(Variable variable) public override bool HasReference(Variable variable)

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

@ -16,11 +16,11 @@ namespace Fungus
public class ReadTextFile : Command public class ReadTextFile : Command
{ {
[Tooltip("Text file to read into the string variable")] [Tooltip("Text file to read into the string variable")]
public TextAsset textFile; [SerializeField] protected TextAsset textFile;
[Tooltip("String variable to store the tex file contents in")] [Tooltip("String variable to store the tex file contents in")]
[VariableProperty(typeof(StringVariable))] [VariableProperty(typeof(StringVariable))]
public StringVariable stringVariable; [SerializeField] protected StringVariable stringVariable;
public override void OnEnter() public override void OnEnter()
{ {
@ -48,7 +48,7 @@ namespace Fungus
return "Error: Text file not selected"; return "Error: Text file not selected";
} }
return stringVariable.key; return stringVariable.Key;
} }
public override bool HasReference(Variable variable) public override bool HasReference(Variable variable)

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

@ -16,10 +16,10 @@ namespace Fungus
public class Reset : Command public class Reset : Command
{ {
[Tooltip("Reset state of all commands in the script")] [Tooltip("Reset state of all commands in the script")]
public bool resetCommands = true; [SerializeField] protected bool resetCommands = true;
[Tooltip("Reset variables back to their default values")] [Tooltip("Reset variables back to their default values")]
public bool resetVariables = true; [SerializeField] protected bool resetVariables = true;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -18,7 +18,7 @@ namespace Fungus
public class SaveVariable : Command public class SaveVariable : Command
{ {
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] [Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")]
public string key = ""; [SerializeField] protected string key = "";
[Tooltip("Variable to read the value from. Only Boolean, Integer, Float and String are supported.")] [Tooltip("Variable to read the value from. Only Boolean, Integer, Float and String are supported.")]
[VariableProperty(typeof(BooleanVariable), [VariableProperty(typeof(BooleanVariable),
@ -92,7 +92,7 @@ namespace Fungus
return "Error: No variable selected"; return "Error: No variable selected";
} }
return variable.key + " into '" + key + "'"; return variable.Key + " into '" + key + "'";
} }
public override Color GetButtonColor() public override Color GetButtonColor()

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

@ -23,10 +23,10 @@ namespace Fungus
} }
[Tooltip("Target flowchart(s) to send the message to")] [Tooltip("Target flowchart(s) to send the message to")]
public MessageTarget messageTarget; [SerializeField] protected MessageTarget messageTarget;
[Tooltip("Name of the message to send")] [Tooltip("Name of the message to send")]
public StringData _message = new StringData(""); [SerializeField] protected StringData _message = new StringData("");
public override void OnEnter() public override void OnEnter()
{ {

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

@ -18,10 +18,10 @@ namespace Fungus
public class SetActive : Command public class SetActive : Command
{ {
[Tooltip("Reference to game object to enable / disable")] [Tooltip("Reference to game object to enable / disable")]
public GameObjectData _targetGameObject; [SerializeField] protected GameObjectData _targetGameObject;
[Tooltip("Set to true to enable the game object")] [Tooltip("Set to true to enable the game object")]
public BooleanData activeState; [SerializeField] protected BooleanData activeState;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -21,7 +21,7 @@ namespace Fungus
public static string saveProfile = ""; public static string saveProfile = "";
[Tooltip("Name of save profile to make active.")] [Tooltip("Name of save profile to make active.")]
public string saveProfileName = ""; [SerializeField] protected string saveProfileName = "";
public override void OnEnter() public override void OnEnter()
{ {

16
Assets/Fungus/Flowchart/Scripts/Commands/SetVariable.cs

@ -29,22 +29,24 @@ namespace Fungus
typeof(IntegerVariable), typeof(IntegerVariable),
typeof(FloatVariable), typeof(FloatVariable),
typeof(StringVariable))] typeof(StringVariable))]
public Variable variable; [SerializeField] protected Variable variable;
[Tooltip("The type of math operation to be performed")] [Tooltip("The type of math operation to be performed")]
public SetOperator setOperator; [SerializeField] protected SetOperator setOperator;
public SetOperator _SetOperator { get { return setOperator; } }
[Tooltip("Boolean value to set with")] [Tooltip("Boolean value to set with")]
public BooleanData booleanData; [SerializeField] protected BooleanData booleanData;
[Tooltip("Integer value to set with")] [Tooltip("Integer value to set with")]
public IntegerData integerData; [SerializeField] protected IntegerData integerData;
[Tooltip("Float value to set with")] [Tooltip("Float value to set with")]
public FloatData floatData; [SerializeField] protected FloatData floatData;
[Tooltip("String value to set with")] [Tooltip("String value to set with")]
public StringDataMulti stringData; [SerializeField] protected StringDataMulti stringData;
public override void OnEnter() public override void OnEnter()
{ {
@ -60,7 +62,7 @@ namespace Fungus
return "Error: Variable not selected"; return "Error: Variable not selected";
} }
string description = variable.key; string description = variable.Key;
switch (setOperator) switch (setOperator)
{ {

8
Assets/Fungus/Flowchart/Scripts/Commands/SpawnObject.cs

@ -20,16 +20,16 @@ namespace Fungus
public class SpawnObject : Command public class SpawnObject : Command
{ {
[Tooltip("Game object to copy when spawning. Can be a scene object or a prefab.")] [Tooltip("Game object to copy when spawning. Can be a scene object or a prefab.")]
public GameObjectData _sourceObject; [SerializeField] protected GameObjectData _sourceObject;
[Tooltip("Transform to use for position of newly spawned object.")] [Tooltip("Transform to use for position of newly spawned object.")]
public TransformData _parentTransform; [SerializeField] protected TransformData _parentTransform;
[Tooltip("Local position of newly spawned object.")] [Tooltip("Local position of newly spawned object.")]
public Vector3Data _spawnPosition; [SerializeField] protected Vector3Data _spawnPosition;
[Tooltip("Local rotation of newly spawned object.")] [Tooltip("Local rotation of newly spawned object.")]
public Vector3Data _spawnRotation; [SerializeField] protected Vector3Data _spawnRotation;
public override void OnEnter() public override void OnEnter()
{ {

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

@ -15,10 +15,10 @@ namespace Fungus
public class StopBlock : Command public class StopBlock : Command
{ {
[Tooltip("Flowchart containing the Block. If none is specified, the parent Flowchart is used.")] [Tooltip("Flowchart containing the Block. If none is specified, the parent Flowchart is used.")]
public Flowchart flowchart; [SerializeField] protected Flowchart flowchart;
[Tooltip("Name of the Block to stop")] [Tooltip("Name of the Block to stop")]
public StringData blockName = new StringData(""); [SerializeField] protected StringData blockName = new StringData("");
public override void OnEnter() public override void OnEnter()
{ {

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

@ -16,10 +16,10 @@ namespace Fungus
public class StopFlowchart : Command public class StopFlowchart : Command
{ {
[Tooltip("Stop all executing Blocks in the Flowchart that contains this command")] [Tooltip("Stop all executing Blocks in the Flowchart that contains this command")]
public bool stopParentFlowchart; [SerializeField] protected bool stopParentFlowchart;
[Tooltip("Stop all executing Blocks in a list of target Flowcharts")] [Tooltip("Stop all executing Blocks in a list of target Flowcharts")]
public List<Flowchart> targetFlowcharts = new List<Flowchart>(); [SerializeField] protected List<Flowchart> targetFlowcharts = new List<Flowchart>();
public override void OnEnter() public override void OnEnter()
{ {

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

@ -18,7 +18,7 @@ namespace Fungus
public class Wait : Command public class Wait : Command
{ {
[Tooltip("Duration to wait for")] [Tooltip("Duration to wait for")]
public FloatData _duration = new FloatData(1); [SerializeField] protected FloatData _duration = new FloatData(1);
public override void OnEnter() public override void OnEnter()
{ {

10
Assets/Fungus/Flowchart/Scripts/Commands/While.cs

@ -26,12 +26,12 @@ namespace Fungus
// Find next End statement at same indent level // Find next End statement at same indent level
End endCommand = null; End endCommand = null;
for (int i = commandIndex + 1; i < parentBlock.commandList.Count; ++i) for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
{ {
End command = parentBlock.commandList[i] as End; End command = ParentBlock.CommandList[i] as End;
if (command != null && if (command != null &&
command.indentLevel == indentLevel) command.IndentLevel == indentLevel)
{ {
endCommand = command; endCommand = command;
break; break;
@ -41,13 +41,13 @@ namespace Fungus
if (execute) if (execute)
{ {
// Tell the following end command to loop back // Tell the following end command to loop back
endCommand.loop = true; endCommand.Loop = true;
Continue(); Continue();
} }
else else
{ {
// Continue at next command after End // Continue at next command after End
Continue (endCommand.commandIndex + 1); Continue (endCommand.CommandIndex + 1);
} }
} }

10
Assets/Fungus/Flowchart/Scripts/EventHandler.cs

@ -41,7 +41,9 @@ namespace Fungus
{ {
[HideInInspector] [HideInInspector]
[FormerlySerializedAs("parentSequence")] [FormerlySerializedAs("parentSequence")]
public Block parentBlock; [SerializeField] protected Block parentBlock;
public Block ParentBlock { get { return parentBlock; } set { parentBlock = value; } }
/** /**
* The Event Handler should call this method when the event is detected. * The Event Handler should call this method when the event is detected.
@ -53,7 +55,7 @@ namespace Fungus
return false; return false;
} }
if (parentBlock.eventHandler != this) if (parentBlock._EventHandler != this)
{ {
return false; return false;
} }
@ -61,9 +63,9 @@ namespace Fungus
Flowchart flowchart = parentBlock.GetFlowchart(); Flowchart flowchart = parentBlock.GetFlowchart();
// Auto-follow the executing block if none is currently selected // Auto-follow the executing block if none is currently selected
if (flowchart.selectedBlock == null) if (flowchart.SelectedBlock == null)
{ {
flowchart.selectedBlock = parentBlock; flowchart.SelectedBlock = parentBlock;
} }
return flowchart.ExecuteBlock(parentBlock); return flowchart.ExecuteBlock(parentBlock);

4
Assets/Fungus/Flowchart/Scripts/EventHandlers/KeyPressed.cs

@ -22,10 +22,10 @@ namespace Fungus
} }
[Tooltip("The type of keypress to activate on")] [Tooltip("The type of keypress to activate on")]
public KeyPressType keyPressType; [SerializeField] protected KeyPressType keyPressType;
[Tooltip("Keycode of the key to activate on")] [Tooltip("Keycode of the key to activate on")]
public KeyCode keyCode; [SerializeField] protected KeyCode keyCode;
protected virtual void Update() protected virtual void Update()
{ {

2
Assets/Fungus/Flowchart/Scripts/EventHandlers/MessageReceived.cs

@ -15,7 +15,7 @@ namespace Fungus
public class MessageReceived : EventHandler public class MessageReceived : EventHandler
{ {
[Tooltip("Fungus message to listen for")] [Tooltip("Fungus message to listen for")]
public string message = ""; [SerializeField] protected string message = "";
public void OnSendFungusMessage(string message) public void OnSendFungusMessage(string message)
{ {

146
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -45,126 +45,161 @@ namespace Fungus
* Variable to track flowchart's version so components can update to new versions. * Variable to track flowchart's version so components can update to new versions.
*/ */
[HideInInspector] [HideInInspector]
public int version = 0; // Default to 0 to always trigger an update for older versions of Fungus. [SerializeField] protected int version = 0; // Default to 0 to always trigger an update for older versions of Fungus.
public int Version { set { version = value; } }
/** /**
* Scroll position of Flowchart editor window. * Scroll position of Flowchart editor window.
*/ */
[HideInInspector] [HideInInspector]
public Vector2 scrollPos; [SerializeField] protected Vector2 scrollPos;
public Vector2 ScrollPos { get { return scrollPos; } set { scrollPos = value; } }
/** /**
* Scroll position of Flowchart variables window. * Scroll position of Flowchart variables window.
*/ */
[HideInInspector] [HideInInspector]
public Vector2 variablesScrollPos; [SerializeField] protected Vector2 variablesScrollPos;
public Vector2 VariablesScrollPos { get { return variablesScrollPos; } set { variablesScrollPos = value; } }
/** /**
* Show the variables pane. * Show the variables pane.
*/ */
[HideInInspector] [HideInInspector]
public bool variablesExpanded = true; [SerializeField] protected bool variablesExpanded = true;
public bool VariablesExpanded { get { return variablesExpanded; } set { variablesExpanded = value; } }
/** /**
* Height of command block view in inspector. * Height of command block view in inspector.
*/ */
[HideInInspector] [HideInInspector]
public float blockViewHeight = 400; [SerializeField] protected float blockViewHeight = 400;
public float BlockViewHeight { get { return blockViewHeight; } set { blockViewHeight = value; } }
/** /**
* Zoom level of Flowchart editor window * Zoom level of Flowchart editor window
*/ */
[HideInInspector] [HideInInspector]
public float zoom = 1f; [SerializeField] protected float zoom = 1f;
public float Zoom { get { return zoom; } set { zoom = value; } }
/** /**
* Scrollable area for Flowchart editor window. * Scrollable area for Flowchart editor window.
*/ */
[HideInInspector] [HideInInspector]
public Rect scrollViewRect; [SerializeField] protected Rect scrollViewRect;
public Rect ScrollViewRect { get { return scrollViewRect; } set { scrollViewRect = value; } }
/** /**
* Currently selected block in the Flowchart editor. * Currently selected block in the Flowchart editor.
*/ */
[HideInInspector] [HideInInspector]
[FormerlySerializedAs("selectedSequence")] [FormerlySerializedAs("selectedSequence")]
public Block selectedBlock; [SerializeField] protected Block selectedBlock;
public Block SelectedBlock { get { return selectedBlock; } set { selectedBlock = value; } }
/** /**
* Currently selected command in the Flowchart editor. * Currently selected command in the Flowchart editor.
*/ */
[HideInInspector] [HideInInspector]
public List<Command> selectedCommands = new List<Command>(); [SerializeField] protected List<Command> selectedCommands = new List<Command>();
public List<Command> SelectedCommands { get { return selectedCommands; } }
/** /**
* The list of variables that can be accessed by the Flowchart. * The list of variables that can be accessed by the Flowchart.
*/ */
[HideInInspector] [HideInInspector]
public List<Variable> variables = new List<Variable>(); [SerializeField] protected List<Variable> variables = new List<Variable>();
public List<Variable> Variables { get { return variables; } }
[TextArea(3, 5)] [TextArea(3, 5)]
[Tooltip("Description text displayed in the Flowchart editor window")] [Tooltip("Description text displayed in the Flowchart editor window")]
public string description = ""; [SerializeField] protected string description = "";
public string Description { get { return description; } }
/** /**
* Slow down execution in the editor to make it easier to visualise program flow. * Slow down execution in the editor to make it easier to visualise program flow.
*/ */
[Range(0f, 5f)] [Range(0f, 5f)]
[Tooltip("Adds a pause after each execution step to make it easier to visualise program flow. Editor only, has no effect in platform builds.")] [Tooltip("Adds a pause after each execution step to make it easier to visualise program flow. Editor only, has no effect in platform builds.")]
public float stepPause = 0f; [SerializeField] protected float stepPause = 0f;
public float StepPause { get { return stepPause; } }
/** /**
* Use command color when displaying the command list in the inspector. * Use command color when displaying the command list in the inspector.
*/ */
[Tooltip("Use command color when displaying the command list in the Fungus Editor window")] [Tooltip("Use command color when displaying the command list in the Fungus Editor window")]
public bool colorCommands = true; [SerializeField] protected bool colorCommands = true;
public bool ColorCommands { get { return colorCommands; } }
/** /**
* Hides the Flowchart block and command components in the inspector. * Hides the Flowchart block and command components in the inspector.
* Deselect to inspect the block and command components that make up the Flowchart. * Deselect to inspect the block and command components that make up the Flowchart.
*/ */
[Tooltip("Hides the Flowchart block and command components in the inspector")] [Tooltip("Hides the Flowchart block and command components in the inspector")]
public bool hideComponents = true; [SerializeField] protected bool hideComponents = true;
/** /**
* Saves the selected block and commands when saving the scene. * Saves the selected block and commands when saving the scene.
* Helps avoid version control conflicts if you've only changed the active selection. * Helps avoid version control conflicts if you've only changed the active selection.
*/ */
[Tooltip("Saves the selected block and commands when saving the scene.")] [Tooltip("Saves the selected block and commands when saving the scene.")]
public bool saveSelection = true; [SerializeField] protected bool saveSelection = true;
public bool SaveSelection { get { return saveSelection; } }
/** /**
* Unique identifier for identifying this flowchart in localized string keys. * Unique identifier for identifying this flowchart in localized string keys.
*/ */
[Tooltip("Unique identifier for this flowchart in localized string keys. If no id is specified then the name of the Flowchart object will be used.")] [Tooltip("Unique identifier for this flowchart in localized string keys. If no id is specified then the name of the Flowchart object will be used.")]
public string localizationId = ""; [SerializeField] protected string localizationId = "";
public string LocalizationId { get { return localizationId; } }
/** /**
* Display line numbers in the command list in the Block inspector. * Display line numbers in the command list in the Block inspector.
*/ */
[Tooltip("Display line numbers in the command list in the Block inspector.")] [Tooltip("Display line numbers in the command list in the Block inspector.")]
public bool showLineNumbers = false; [SerializeField] protected bool showLineNumbers = false;
public bool ShowLineNumbers { get { return showLineNumbers; } }
/** /**
* List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart. * List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.
*/ */
[Tooltip("List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.")] [Tooltip("List of commands to hide in the Add Command menu. Use this to restrict the set of commands available when editing a Flowchart.")]
public List<string> hideCommands = new List<string>(); [SerializeField] protected List<string> hideCommands = new List<string>();
[Tooltip("Lua Environment to be used by default for all Execute Lua commands in this Flowchart")] [Tooltip("Lua Environment to be used by default for all Execute Lua commands in this Flowchart")]
public LuaEnvironment luaEnvironment; [SerializeField] protected LuaEnvironment luaEnvironment;
public LuaEnvironment _LuaEnvironment { get { return luaEnvironment; } }
/** /**
* The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing. * The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.
*/ */
[Tooltip("The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.")] [Tooltip("The ExecuteLua command adds a global Lua variable with this name bound to the flowchart prior to executing.")]
public string luaBindingName = "flowchart"; [SerializeField] protected string luaBindingName = "flowchart";
public string LuaBindingName { get { return luaBindingName; } }
/** /**
* Position in the center of all blocks in the flowchart. * Position in the center of all blocks in the flowchart.
*/ */
[NonSerialized] public Vector2 CenterPosition { set; get; }
public Vector2 centerPosition = Vector2.zero;
/** /**
* Cached list of flowchart objects in the scene for fast lookup * Cached list of flowchart objects in the scene for fast lookup
@ -186,13 +221,13 @@ namespace Fungus
Block[] blocks = GetComponents<Block>(); Block[] blocks = GetComponents<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
maxId = Math.Max(maxId, block.itemId); maxId = Math.Max(maxId, block.ItemId);
} }
Command[] commands = GetComponents<Command>(); Command[] commands = GetComponents<Command>();
foreach (Command command in commands) foreach (Command command in commands)
{ {
maxId = Math.Max(maxId, command.itemId); maxId = Math.Max(maxId, command.ItemId);
} }
return maxId + 1; return maxId + 1;
} }
@ -292,23 +327,23 @@ namespace Fungus
Block[] blocks = GetComponents<Block>(); Block[] blocks = GetComponents<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.itemId == -1 || if (block.ItemId == -1 ||
usedIds.Contains(block.itemId)) usedIds.Contains(block.ItemId))
{ {
block.itemId = NextItemId(); block.ItemId = NextItemId();
} }
usedIds.Add(block.itemId); usedIds.Add(block.ItemId);
} }
Command[] commands = GetComponents<Command>(); Command[] commands = GetComponents<Command>();
foreach (Command command in commands) foreach (Command command in commands)
{ {
if (command.itemId == -1 || if (command.ItemId == -1 ||
usedIds.Contains(command.itemId)) usedIds.Contains(command.ItemId))
{ {
command.itemId = NextItemId(); command.ItemId = NextItemId();
} }
usedIds.Add(command.itemId); usedIds.Add(command.ItemId);
} }
} }
@ -337,7 +372,7 @@ namespace Fungus
bool found = false; bool found = false;
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.commandList.Contains(command)) if (block.CommandList.Contains(command))
{ {
found = true; found = true;
break; break;
@ -355,7 +390,7 @@ namespace Fungus
bool found = false; bool found = false;
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.eventHandler == eventHandler) if (block._EventHandler == eventHandler)
{ {
found = true; found = true;
break; break;
@ -381,10 +416,9 @@ namespace Fungus
public virtual Block CreateBlock(Vector2 position) public virtual Block CreateBlock(Vector2 position)
{ {
Block b = CreateBlockComponent(gameObject); Block b = CreateBlockComponent(gameObject);
b.nodeRect.x = position.x; b._NodeRect = new Rect(position.x, position.y, 0, 0);
b.nodeRect.y = position.y; b.BlockName = GetUniqueBlockKey(b.BlockName, b);
b.blockName = GetUniqueBlockKey(b.blockName, b); b.ItemId = NextItemId();
b.itemId = NextItemId();
return b; return b;
} }
@ -397,7 +431,7 @@ namespace Fungus
Block [] blocks = GetComponents<Block>(); Block [] blocks = GetComponents<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
if (block.blockName == blockName) if (block.BlockName == blockName)
{ {
return block; return block;
} }
@ -416,7 +450,7 @@ namespace Fungus
Block block = null; Block block = null;
foreach (Block b in GetComponents<Block>()) foreach (Block b in GetComponents<Block>())
{ {
if (b.blockName == blockName) if (b.BlockName == blockName)
{ {
block = b; block = b;
break; break;
@ -537,12 +571,12 @@ namespace Fungus
{ {
if (variable == null || if (variable == null ||
variable == ignoreVariable || variable == ignoreVariable ||
variable.key == null) variable.Key == null)
{ {
continue; continue;
} }
if (variable.key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (variable.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
suffix++; suffix++;
@ -580,12 +614,12 @@ namespace Fungus
foreach(Block block in blocks) foreach(Block block in blocks)
{ {
if (block == ignoreBlock || if (block == ignoreBlock ||
block.blockName == null) block.BlockName == null)
{ {
continue; continue;
} }
if (block.blockName.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
suffix++; suffix++;
@ -614,13 +648,13 @@ namespace Fungus
baseKey = "New Label"; baseKey = "New Label";
} }
Block block = ignoreLabel.parentBlock; Block block = ignoreLabel.ParentBlock;
string key = baseKey; string key = baseKey;
while (true) while (true)
{ {
bool collision = false; bool collision = false;
foreach(Command command in block.commandList) foreach(Command command in block.CommandList)
{ {
Label label = command as Label; Label label = command as Label;
if (label == null || if (label == null ||
@ -629,7 +663,7 @@ namespace Fungus
continue; continue;
} }
if (label.key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{ {
collision = true; collision = true;
suffix++; suffix++;
@ -655,7 +689,7 @@ namespace Fungus
{ {
foreach (Variable variable in variables) foreach (Variable variable in variables)
{ {
if (variable != null && variable.key == key) if (variable != null && variable.Key == key)
{ {
return variable; return variable;
} }
@ -674,7 +708,7 @@ namespace Fungus
{ {
foreach (Variable variable in variables) foreach (Variable variable in variables)
{ {
if (variable != null && variable.key == key) if (variable != null && variable.Key == key)
{ {
return variable as T; return variable as T;
} }
@ -692,7 +726,7 @@ namespace Fungus
{ {
foreach (Variable v in variables) foreach (Variable v in variables)
{ {
if (v != null && v.key == key) if (v != null && v.Key == key)
{ {
T variable = v as T; T variable = v as T;
if (variable != null) if (variable != null)
@ -714,7 +748,7 @@ namespace Fungus
List<Variable> publicVariables = new List<Variable>(); List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables) foreach (Variable v in variables)
{ {
if (v != null && v.scope == VariableScope.Public) if (v != null && v.Scope == VariableScope.Public)
{ {
publicVariables.Add(v); publicVariables.Add(v);
} }
@ -1004,8 +1038,8 @@ namespace Fungus
if (variable == null) if (variable == null)
continue; continue;
if (variable.scope == VariableScope.Public && if (variable.Scope == VariableScope.Public &&
variable.key == key) variable.Key == key)
{ {
string value = variable.ToString(); string value = variable.ToString();
input.Replace(match.Value, value); input.Replace(match.Value, value);
@ -1032,7 +1066,7 @@ namespace Fungus
} }
// Use the string builder from StringSubstituter for efficiency. // Use the string builder from StringSubstituter for efficiency.
StringBuilder sb = stringSubstituer.stringBuilder; StringBuilder sb = stringSubstituer._StringBuilder;
sb.Length = 0; sb.Length = 0;
sb.Append(input); sb.Append(input);
@ -1053,8 +1087,8 @@ namespace Fungus
if (variable == null) if (variable == null)
continue; continue;
if (variable.scope == VariableScope.Private && if (variable.Scope == VariableScope.Private &&
variable.key == key) variable.Key == key)
{ {
string value = variable.ToString(); string value = variable.ToString();
sb.Replace(match.Value, value); sb.Replace(match.Value, value);

4
Assets/Fungus/Flowchart/Scripts/FungusState.cs

@ -14,7 +14,9 @@ namespace Fungus
[AddComponentMenu("")] [AddComponentMenu("")]
public class FungusState : MonoBehaviour public class FungusState : MonoBehaviour
{ {
public Flowchart selectedFlowchart; [SerializeField] protected Flowchart selectedFlowchart;
public Flowchart SelectedFlowchart { get { return selectedFlowchart; } set { selectedFlowchart = value; } }
} }
} }

4
Assets/Fungus/Flowchart/Scripts/Node.cs

@ -12,7 +12,9 @@ namespace Fungus
[AddComponentMenu("")] [AddComponentMenu("")]
public class Node : MonoBehaviour public class Node : MonoBehaviour
{ {
public Rect nodeRect = new Rect(0, 0, 120, 30); [SerializeField] protected Rect nodeRect = new Rect(0, 0, 120, 30);
public Rect _NodeRect { get { return nodeRect; } set { nodeRect = value; } }
} }
} }

8
Assets/Fungus/Flowchart/Scripts/Variable.cs

@ -51,9 +51,13 @@ namespace Fungus
[RequireComponent(typeof(Flowchart))] [RequireComponent(typeof(Flowchart))]
public abstract class Variable : MonoBehaviour public abstract class Variable : MonoBehaviour
{ {
public VariableScope scope; [SerializeField] protected VariableScope scope;
public string key = ""; public VariableScope Scope { get { return scope; } }
[SerializeField] protected string key = "";
public string Key { get { return key; } set { key = value; } }
public abstract void OnReset(); public abstract void OnReset();
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/AnimatorVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return animatorRef.key; return animatorRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/AudioSourceVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return audioSourceRef.key; return audioSourceRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/BooleanVariable.cs

@ -73,7 +73,7 @@ namespace Fungus
} }
else else
{ {
return booleanRef.key; return booleanRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/ColorVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return colorRef.key; return colorRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/FloatVariable.cs

@ -81,7 +81,7 @@ namespace Fungus
} }
else else
{ {
return floatRef.key; return floatRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/GameObjectVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return gameObjectRef.key; return gameObjectRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/IntegerVariable.cs

@ -81,7 +81,7 @@ namespace Fungus
} }
else else
{ {
return integerRef.key; return integerRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/MaterialVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return materialRef.key; return materialRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/ObjectVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return objectRef.key; return objectRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/SpriteVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return spriteRef.key; return spriteRef.Key;
} }
} }
} }

4
Assets/Fungus/Flowchart/Scripts/VariableTypes/StringVariable.cs

@ -80,7 +80,7 @@ namespace Fungus
} }
else else
{ {
return stringRef.key; return stringRef.Key;
} }
} }
} }
@ -130,7 +130,7 @@ namespace Fungus
} }
else else
{ {
return stringRef.key; return stringRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/TextureVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return textureRef.key; return textureRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/TransformVariable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return transformRef.key; return transformRef.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/Vector2Variable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return vector2Ref.key; return vector2Ref.Key;
} }
} }
} }

2
Assets/Fungus/Flowchart/Scripts/VariableTypes/Vector3Variable.cs

@ -49,7 +49,7 @@ namespace Fungus
} }
else else
{ {
return vector3Ref.key; return vector3Ref.Key;
} }
} }
} }

8
Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs

@ -59,14 +59,14 @@ namespace Fungus
} }
// Cache a descriptive name to use in Lua error messages // Cache a descriptive name to use in Lua error messages
friendlyName = gameObject.name + "." + parentBlock.blockName + "." + "ExecuteLua #" + commandIndex.ToString(); friendlyName = gameObject.name + "." + ParentBlock.BlockName + "." + "ExecuteLua #" + CommandIndex.ToString();
Flowchart flowchart = GetFlowchart(); Flowchart flowchart = GetFlowchart();
// See if a Lua Environment has been assigned to this Flowchart // See if a Lua Environment has been assigned to this Flowchart
if (luaEnvironment == null) if (luaEnvironment == null)
{ {
luaEnvironment = flowchart.luaEnvironment; luaEnvironment = flowchart._LuaEnvironment;
} }
// No Lua Environment specified so just use any available or create one. // No Lua Environment specified so just use any available or create one.
@ -79,12 +79,12 @@ namespace Fungus
luaFunction = luaEnvironment.LoadLuaString(s, friendlyName); luaFunction = luaEnvironment.LoadLuaString(s, friendlyName);
// Add a binding to the parent flowchart // Add a binding to the parent flowchart
if (flowchart.luaBindingName != "") if (flowchart.LuaBindingName != "")
{ {
Table globals = luaEnvironment.Interpreter.Globals; Table globals = luaEnvironment.Interpreter.Globals;
if (globals != null) if (globals != null)
{ {
globals[flowchart.luaBindingName] = flowchart; globals[flowchart.LuaBindingName] = flowchart;
} }
} }

2
Assets/Fungus/Narrative/Scripts/Commands/Menu.cs

@ -83,7 +83,7 @@ namespace Fungus
return "Error: No button text selected"; return "Error: No button text selected";
} }
return text + " : " + targetBlock.blockName; return text + " : " + targetBlock.BlockName;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

2
Assets/Fungus/Narrative/Scripts/Commands/MenuTimer.cs

@ -54,7 +54,7 @@ namespace Fungus
return "Error: No target block selected"; return "Error: No target block selected";
} }
return targetBlock.blockName; return targetBlock.BlockName;
} }
public override Color GetButtonColor() public override Color GetButtonColor()

2
Assets/Fungus/Narrative/Scripts/Localization.cs

@ -232,7 +232,7 @@ namespace Fungus
Block[] blocks = flowchart.GetComponents<Block>(); Block[] blocks = flowchart.GetComponents<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
foreach (Command command in block.commandList) foreach (Command command in block.CommandList)
{ {
ILocalizable localizable = command as ILocalizable; ILocalizable localizable = command as ILocalizable;
if (localizable != null) if (localizable != null)

2
Assets/Fungus/Narrative/Scripts/MenuDialog.cs

@ -142,7 +142,7 @@ namespace Fungus
#if UNITY_EDITOR #if UNITY_EDITOR
// Select the new target block in the Flowchart window // Select the new target block in the Flowchart window
Flowchart flowchart = block.GetFlowchart(); Flowchart flowchart = block.GetFlowchart();
flowchart.selectedBlock = block; flowchart.SelectedBlock = block;
#endif #endif
gameObject.SetActive(false); gameObject.SetActive(false);

8
Assets/Fungus/Sprite/Scripts/Clickable2D.cs

@ -16,13 +16,15 @@ namespace Fungus
public class Clickable2D : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler public class Clickable2D : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{ {
[Tooltip("Is object clicking enabled")] [Tooltip("Is object clicking enabled")]
public bool clickEnabled = true; [SerializeField] protected bool clickEnabled = true;
public bool ClickEnabled { set { clickEnabled = value; } }
[Tooltip("Mouse texture to use when hovering mouse over object")] [Tooltip("Mouse texture to use when hovering mouse over object")]
public Texture2D hoverCursor; [SerializeField] protected Texture2D hoverCursor;
[Tooltip("Use the UI Event System to check for clicks. Clicks that hit an overlapping UI object will be ignored. Camera must have a PhysicsRaycaster component, or a Physics2DRaycaster for 2D colliders.")] [Tooltip("Use the UI Event System to check for clicks. Clicks that hit an overlapping UI object will be ignored. Camera must have a PhysicsRaycaster component, or a Physics2DRaycaster for 2D colliders.")]
public bool useEventSystem; [SerializeField] protected bool useEventSystem;
#region Legacy OnMouseX methods #region Legacy OnMouseX methods
protected virtual void OnMouseDown() protected virtual void OnMouseDown()

8
Assets/Fungus/Sprite/Scripts/Commands/FadeSprite.cs

@ -37,17 +37,9 @@ namespace Fungus
return; return;
} }
CameraController cameraController = CameraController.GetInstance();
if (waitUntilFinished)
{
cameraController.waiting = true;
}
SpriteFader.FadeSprite(spriteRenderer, _targetColor.Value, _duration.Value, Vector2.zero, delegate { SpriteFader.FadeSprite(spriteRenderer, _targetColor.Value, _duration.Value, Vector2.zero, delegate {
if (waitUntilFinished) if (waitUntilFinished)
{ {
cameraController.waiting = false;
Continue(); Continue();
} }
}); });

6
Assets/Fungus/Sprite/Scripts/Commands/SetClickable2D.cs

@ -16,16 +16,16 @@ namespace Fungus
public class SetClickable2D : Command public class SetClickable2D : Command
{ {
[Tooltip("Reference to Clickable2D component on a gameobject")] [Tooltip("Reference to Clickable2D component on a gameobject")]
public Clickable2D targetClickable2D; [SerializeField] protected Clickable2D targetClickable2D;
[Tooltip("Set to true to enable the component")] [Tooltip("Set to true to enable the component")]
public BooleanData activeState; [SerializeField] protected BooleanData activeState;
public override void OnEnter() public override void OnEnter()
{ {
if (targetClickable2D != null) if (targetClickable2D != null)
{ {
targetClickable2D.clickEnabled = activeState.Value; targetClickable2D.ClickEnabled = activeState.Value;
} }
Continue(); Continue();

6
Assets/Fungus/Sprite/Scripts/Commands/SetCollider.cs

@ -16,13 +16,13 @@ namespace Fungus
public class SetCollider : Command public class SetCollider : Command
{ {
[Tooltip("A list of gameobjects containing collider components to be set active / inactive")] [Tooltip("A list of gameobjects containing collider components to be set active / inactive")]
public List<GameObject> targetObjects = new List<GameObject>(); [SerializeField] protected List<GameObject> targetObjects = new List<GameObject>();
[Tooltip("All objects with this tag will have their collider set active / inactive")] [Tooltip("All objects with this tag will have their collider set active / inactive")]
public string targetTag = ""; [SerializeField] protected string targetTag = "";
[Tooltip("Set to true to enable the collider components")] [Tooltip("Set to true to enable the collider components")]
public BooleanData activeState; [SerializeField] protected BooleanData activeState;
public override void OnEnter() public override void OnEnter()
{ {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save