Browse Source

Merge pull request #542 from snozbot/remove-foreach

Replace foreach with for loops (avoid allocation for iterator)
master
Chris Gregan 8 years ago committed by GitHub
parent
commit
6b44df0971
  1. 50
      Assets/Fungus/Docs/CHANGELOG.txt
  2. 9
      Assets/Fungus/Scripts/Commands/ControlAudio.cs
  3. 8
      Assets/Fungus/Scripts/Commands/ControlStage.cs
  4. 96
      Assets/Fungus/Scripts/Commands/FadeUI.cs
  5. 7
      Assets/Fungus/Scripts/Commands/Jump.cs
  6. 4
      Assets/Fungus/Scripts/Commands/Say.cs
  7. 3
      Assets/Fungus/Scripts/Commands/SendMessage.cs
  8. 14
      Assets/Fungus/Scripts/Commands/SetCollider.cs
  9. 17
      Assets/Fungus/Scripts/Commands/SetInteractable.cs
  10. 5
      Assets/Fungus/Scripts/Commands/SetLayerOrder.cs
  11. 8
      Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs
  12. 5
      Assets/Fungus/Scripts/Commands/ShowSprite.cs
  13. 4
      Assets/Fungus/Scripts/Commands/StopFlowchart.cs
  14. 14
      Assets/Fungus/Scripts/Commands/TweenUI.cs
  15. 6
      Assets/Fungus/Scripts/Commands/iTweenCommand.cs
  16. 21
      Assets/Fungus/Scripts/Components/Block.cs
  17. 4
      Assets/Fungus/Scripts/Components/CameraManager.cs
  18. 5
      Assets/Fungus/Scripts/Components/Clickable2D.cs
  19. 4
      Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs
  20. 21
      Assets/Fungus/Scripts/Components/DialogInput.cs
  21. 30
      Assets/Fungus/Scripts/Components/Draggable2D.cs
  22. 164
      Assets/Fungus/Scripts/Components/Flowchart.cs
  23. 45
      Assets/Fungus/Scripts/Components/Localization.cs
  24. 53
      Assets/Fungus/Scripts/Components/MenuDialog.cs
  25. 14
      Assets/Fungus/Scripts/Components/SayDialog.cs
  26. 10
      Assets/Fungus/Scripts/Components/SpriteFader.cs
  27. 26
      Assets/Fungus/Scripts/Components/Writer.cs
  28. 2
      Assets/Fungus/Scripts/Editor/EventHandlerEditor.cs
  29. 4
      Assets/Fungus/Scripts/Editor/FlowchartEditor.cs
  30. 25
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  31. 3
      Assets/Fungus/Scripts/Editor/LabelEditor.cs
  32. 3
      Assets/Fungus/Scripts/Editor/ViewEditor.cs
  33. 13
      Assets/Fungus/Scripts/Utils/TextTagParser.cs

50
Assets/Fungus/Docs/CHANGELOG.txt

@ -1,3 +1,53 @@
Fungus 3.3.0
============
# Known Issues
- FungusLua does not work in WebGL builds due to issues in MoonSharp 1.8.0.0
Forum thread: http://fungusgames.com/forum/#!/general:fungus-lua-and-web-gl-uni
# Added
- Added test for StopTweens does not stop a Tween with loop enabled #529
- Added signals (pub-sub system) for Writer and Block events #539
- All interfaces now have their own source files.
- Added monodevelop project for editing docs files.
- Added Flip option (<<< and >>>) to conversation system #527
# Changed
- Tidied up Fungus folder structure to organize scripts more logically
- Migrated documentation to use Doxygen for help and API docs
- Lots of misc improvements to documentation
- Updated to MoonSharp 1.8.0.0
- Documented using string facing parameter in stage.show() Lua function.
- Documented <<< and >>> tags for conversation system.
- Documented all public members for API docs.
- All serialized fields are now protected, exposed via public properties as needed.
- Moved all enums to namespace scope.
- Moved global constants to FungusConstants static class.
- Moved editor resources to the main resources folder
- Fungus editor code moved to Fungus.EditorUtils namespace
- Convert singletons to use a single FungusManager singleton #540
- Renamed CameraController to CameraManager and MusicController to MusicManager
- Changed float constant comparisons to use Mathf.Approximately
- Added #region Public members to all non-editor classes
- StringFormatter, TextTagParser and FungusPrefs classes are now static
- Merged MenuDialog extension methods (used for Lua) with main MenuDialog class.
- Change all public methods to use virtual
- Removed all unnecessary using statements.
- All class and member comments use standard c# xml comment style
# Fixed
- Fixed Setting facing in lua only works if portraits are set to “FRONT” #528
- Fixed Say command completes instantly after menu choice #533
- Fixed broken mouse pointer in WebGL build of Drag and Drop
- Fixed ObjectField nulls reference if object is disabled #536
- Updated Unity Test Tools to v1.5.9
- Fixed missing Process class error in Unity5.5b3
- Fixed Spine.Unity namespace problem in integration scripts
- Fix Regex for character names with "." & "'" #531 (thanks to Sercan Altun)
Old Regex expression did not capture Character names with "." and "'". As a result characters with names like "Mr. Jones" or "Ab'ar" were not registering correctly.
- Fixed Lua setlanguage() function
Fungus 3.2.0
============

9
Assets/Fungus/Scripts/Commands/ControlAudio.cs

@ -65,12 +65,13 @@ namespace Fungus
return;
}
AudioSource[] audioSources = GameObject.FindObjectsOfType<AudioSource>();
foreach (AudioSource a in audioSources)
var audioSources = GameObject.FindObjectsOfType<AudioSource>();
for (int i = 0; i < audioSources.Length; i++)
{
if ((a.GetComponent<AudioSource>() != _audioSource.Value) && (a.tag == _audioSource.Value.tag))
var a = audioSources[i];
if (a != _audioSource.Value && a.tag == _audioSource.Value.tag)
{
StopLoop(a.GetComponent<AudioSource>());
StopLoop(a);
}
}
}

8
Assets/Fungus/Scripts/Commands/ControlStage.cs

@ -72,8 +72,10 @@ namespace Fungus
protected virtual void MoveToFront(Stage stage)
{
foreach (Stage s in Stage.ActiveStages)
var activeStages = Stage.ActiveStages;
for (int i = 0; i < activeStages.Count; i++)
{
var s = activeStages[i];
if (s == stage)
{
s.PortraitCanvas.sortingOrder = 1;
@ -88,8 +90,10 @@ namespace Fungus
protected virtual void UndimAllPortraits(Stage stage)
{
stage.DimPortraits = false;
foreach (Character character in stage.CharactersOnStage)
var charactersOnStage = stage.CharactersOnStage;
for (int i = 0; i < charactersOnStage.Count; i++)
{
var character = charactersOnStage[i];
stage.SetDimmed(character, false);
}
}

96
Assets/Fungus/Scripts/Commands/FadeUI.cs

@ -33,92 +33,98 @@ namespace Fungus
protected override void ApplyTween(GameObject go)
{
foreach (Image image in go.GetComponentsInChildren<Image>())
var images = go.GetComponentsInChildren<Image>();
for (int i = 0; i < images.Length; i++)
{
var image = images[i];
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = image.color;
tempColor.a = targetAlpha;
image.color = tempColor;
break;
case FadeMode.Color:
image.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = image.color;
tempColor.a = targetAlpha;
image.color = tempColor;
break;
case FadeMode.Color:
image.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.alpha(image.rectTransform, targetAlpha, duration).setEase(tweenType).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(image.rectTransform, targetColor, duration).setEase(tweenType).setEase(tweenType);
break;
}
}
}
foreach (Text text in go.GetComponentsInChildren<Text>())
var texts = go.GetComponentsInChildren<Text>();
for (int i = 0; i < texts.Length; i++)
{
var text = texts[i];
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = text.color;
tempColor.a = targetAlpha;
text.color = tempColor;
break;
case FadeMode.Color:
text.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = text.color;
tempColor.a = targetAlpha;
text.color = tempColor;
break;
case FadeMode.Color:
text.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.textAlpha(text.rectTransform, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.textColor(text.rectTransform, targetColor, duration).setEase(tweenType);
break;
}
}
}
foreach (TextMesh textMesh in go.GetComponentsInChildren<TextMesh>())
var textMeshes = go.GetComponentsInChildren<TextMesh>();
for (int i = 0; i < textMeshes.Length; i++)
{
var textMesh = textMeshes[i];
if (Mathf.Approximately(duration, 0f))
{
switch (fadeMode)
{
case FadeMode.Alpha:
Color tempColor = textMesh.color;
tempColor.a = targetAlpha;
textMesh.color = tempColor;
break;
case FadeMode.Color:
textMesh.color = targetColor;
break;
case FadeMode.Alpha:
Color tempColor = textMesh.color;
tempColor.a = targetAlpha;
textMesh.color = tempColor;
break;
case FadeMode.Color:
textMesh.color = targetColor;
break;
}
}
else
{
switch (fadeMode)
{
case FadeMode.Alpha:
LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(go, targetColor, duration).setEase(tweenType);
break;
case FadeMode.Alpha:
LeanTween.alpha(go, targetAlpha, duration).setEase(tweenType);
break;
case FadeMode.Color:
LeanTween.color(go, targetColor, duration).setEase(tweenType);
break;
}
}
}

7
Assets/Fungus/Scripts/Commands/Jump.cs

@ -29,11 +29,12 @@ namespace Fungus
return;
}
foreach (var command in ParentBlock.CommandList)
var commandList = ParentBlock.CommandList;
for (int i = 0; i < commandList.Count; i++)
{
var command = commandList[i];
Label label = command as Label;
if (label != null &&
label.Key == _targetLabel.Value)
if (label != null && label.Key == _targetLabel.Value)
{
Continue(label.CommandIndex + 1);
return;

4
Assets/Fungus/Scripts/Commands/Say.cs

@ -107,8 +107,10 @@ namespace Fungus
string displayText = storyText;
foreach (CustomTag ct in CustomTag.activeCustomTags)
var activeCustomTags = CustomTag.activeCustomTags;
for (int i = 0; i < activeCustomTags.Count; i++)
{
var ct = activeCustomTags[i];
displayText = displayText.Replace(ct.TagStartSymbol, ct.ReplaceTagStartWith);
if (ct.TagEndSymbol != "" && ct.ReplaceTagEndWith != "")
{

3
Assets/Fungus/Scripts/Commands/SendMessage.cs

@ -59,8 +59,9 @@ namespace Fungus
if (receivers != null)
{
foreach (MessageReceived receiver in receivers)
for (int i = 0; i < receivers.Length; i++)
{
var receiver = receivers[i];
receiver.OnSendFungusMessage(_message.Value);
}
}

14
Assets/Fungus/Scripts/Commands/SetCollider.cs

@ -29,14 +29,18 @@ namespace Fungus
if (go != null)
{
// 3D objects
foreach (Collider c in go.GetComponentsInChildren<Collider>())
var colliders = go.GetComponentsInChildren<Collider>();
for (int i = 0; i < colliders.Length; i++)
{
var c = colliders[i];
c.enabled = activeState.Value;
}
// 2D objects
foreach (Collider2D c in go.GetComponentsInChildren<Collider2D>())
var collider2Ds = go.GetComponentsInChildren<Collider2D>();
for (int i = 0; i < collider2Ds.Length; i++)
{
var c = collider2Ds[i];
c.enabled = activeState.Value;
}
}
@ -46,8 +50,9 @@ namespace Fungus
public override void OnEnter()
{
foreach (GameObject go in targetObjects)
for (int i = 0; i < targetObjects.Count; i++)
{
var go = targetObjects[i];
SetColliderActive(go);
}
@ -63,8 +68,9 @@ namespace Fungus
if (taggedObjects != null)
{
foreach (GameObject go in taggedObjects)
for (int i = 0; i < taggedObjects.Length; i++)
{
var go = taggedObjects[i];
SetColliderActive(go);
}
}

17
Assets/Fungus/Scripts/Commands/SetInteractable.cs

@ -31,10 +31,13 @@ namespace Fungus
return;
}
foreach (GameObject targetObject in targetObjects)
for (int i = 0; i < targetObjects.Count; i++)
{
foreach (Selectable selectable in targetObject.GetComponents<Selectable>())
var targetObject = targetObjects[i];
var selectables = targetObject.GetComponents<Selectable>();
for (int j = 0; j < selectables.Length; j++)
{
var selectable = selectables[j];
selectable.interactable = interactableState.Value;
}
}
@ -58,20 +61,20 @@ namespace Fungus
}
string objectList = "";
foreach (GameObject gameObject in targetObjects)
for (int i = 0; i < targetObjects.Count; i++)
{
if (gameObject == null)
var go = targetObjects[i];
if (go == null)
{
continue;
}
if (objectList == "")
{
objectList += gameObject.name;
objectList += go.name;
}
else
{
objectList += ", " + gameObject.name;
objectList += ", " + go.name;
}
}

5
Assets/Fungus/Scripts/Commands/SetLayerOrder.cs

@ -22,14 +22,15 @@ namespace Fungus
protected void ApplySortingLayer(Transform target, string layerName)
{
Renderer renderer = target.gameObject.GetComponent<Renderer>();
var renderer = target.gameObject.GetComponent<Renderer>();
if (renderer)
{
renderer.sortingLayerName = layerName;
Debug.Log(target.name);
}
foreach (Transform child in target.transform)
var targetTransform = target.transform;
foreach (Transform child in targetTransform)
{
ApplySortingLayer(child, layerName);
}

8
Assets/Fungus/Scripts/Commands/SetSpriteOrder.cs

@ -25,8 +25,9 @@ namespace Fungus
public override void OnEnter()
{
foreach (SpriteRenderer spriteRenderer in targetSprites)
for (int i = 0; i < targetSprites.Count; i++)
{
var spriteRenderer = targetSprites[i];
spriteRenderer.sortingOrder = orderInLayer;
}
@ -36,18 +37,17 @@ namespace Fungus
public override string GetSummary()
{
string summary = "";
foreach (SpriteRenderer spriteRenderer in targetSprites)
for (int i = 0; i < targetSprites.Count; i++)
{
var spriteRenderer = targetSprites[i];
if (spriteRenderer == null)
{
continue;
}
if (summary.Length > 0)
{
summary += ", ";
}
summary += spriteRenderer.name;
}

5
Assets/Fungus/Scripts/Commands/ShowSprite.cs

@ -40,9 +40,10 @@ namespace Fungus
{
if (affectChildren)
{
SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer sr in children)
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
for (int i = 0; i < spriteRenderers.Length; i++)
{
var sr = spriteRenderers[i];
SetSpriteAlpha(sr, _visible.Value);
}
}

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

@ -32,14 +32,14 @@ namespace Fungus
flowchart.StopAllBlocks();
}
foreach (var f in targetFlowcharts)
for (int i = 0; i < targetFlowcharts.Count; i++)
{
var f = targetFlowcharts[i];
if (f == flowchart)
{
// Flowchart has already been stopped
continue;
}
f.StopAllBlocks();
}
}

14
Assets/Fungus/Scripts/Commands/TweenUI.cs

@ -26,13 +26,13 @@ namespace Fungus
protected virtual void ApplyTween()
{
foreach (GameObject targetObject in targetObjects)
for (int i = 0; i < targetObjects.Count; i++)
{
var targetObject = targetObjects[i];
if (targetObject == null)
{
continue;
}
ApplyTween(targetObject);
}
@ -97,20 +97,20 @@ namespace Fungus
}
string objectList = "";
foreach (GameObject gameObject in targetObjects)
for (int i = 0; i < targetObjects.Count; i++)
{
if (gameObject == null)
var go = targetObjects[i];
if (go == null)
{
continue;
}
if (objectList == "")
{
objectList += gameObject.name;
objectList += go.name;
}
else
{
objectList += ", " + gameObject.name;
objectList += ", " + go.name;
}
}

6
Assets/Fungus/Scripts/Commands/iTweenCommand.cs

@ -73,8 +73,10 @@ namespace Fungus
if (stopPreviousTweens)
{
// Force any existing iTweens on this target object to complete immediately
iTween[] tweens = _targetObject.Value.GetComponents<iTween>();
foreach (iTween tween in tweens) {
var tweens = _targetObject.Value.GetComponents<iTween>();
for (int i = 0; i < tweens.Length; i++)
{
var tween = tweens[i];
tween.time = 0;
tween.SendMessage("Update");
}

21
Assets/Fungus/Scripts/Components/Block.cs

@ -72,13 +72,13 @@ namespace Fungus
// Give each child command a reference back to its parent block
// and tell each command its index in the list.
int index = 0;
foreach (var command in commandList)
for (int i = 0; i < commandList.Count; i++)
{
var command = commandList[i];
if (command == null)
{
continue;
}
command.ParentBlock = this;
command.CommandIndex = index++;
}
@ -98,13 +98,14 @@ namespace Fungus
protected virtual void Update()
{
int index = 0;
foreach (var command in commandList)
for (int i = 0; i < commandList.Count; i++)
{
if (command == null) // Null entry will be deleted automatically later
var command = commandList[i];
if (command == null)// Null entry will be deleted automatically later
{
continue;
}
command.CommandIndex = index++;
}
}
@ -328,8 +329,9 @@ namespace Fungus
public virtual List<Block> GetConnectedBlocks()
{
var connectedBlocks = new List<Block>();
foreach (var command in commandList)
for (int i = 0; i < commandList.Count; i++)
{
var command = commandList[i];
if (command != null)
{
command.GetConnectedBlocks(ref connectedBlocks);
@ -359,23 +361,20 @@ namespace Fungus
public virtual void UpdateIndentLevels()
{
int indentLevel = 0;
foreach (var command in commandList)
for (int i = 0; i < commandList.Count; i++)
{
var command = commandList[i];
if (command == null)
{
continue;
}
if (command.CloseBlock())
{
indentLevel--;
}
// Negative indent level is not permitted
indentLevel = Math.Max(indentLevel, 0);
command.IndentLevel = indentLevel;
if (command.OpenBlock())
{
indentLevel++;

4
Assets/Fungus/Scripts/Components/CameraManager.cs

@ -155,10 +155,10 @@ namespace Fungus
camera.orthographicSize = Mathf.Lerp(startSize, endSize, Mathf.SmoothStep(0f, 1f, t));
camera.transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t));
camera.transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0f, 1f, t));
SetCameraZ(camera);
}
SetCameraZ(camera);
if (arrived &&
arriveAction != null)
{

5
Assets/Fungus/Scripts/Components/Clickable2D.cs

@ -40,9 +40,10 @@ namespace Fungus
}
// TODO: Cache these objects for faster lookup
ObjectClicked[] handlers = GameObject.FindObjectsOfType<ObjectClicked>();
foreach (ObjectClicked handler in handlers)
var handlers = GameObject.FindObjectsOfType<ObjectClicked>();
for (int i = 0; i < handlers.Length; i++)
{
var handler = handlers[i];
handler.OnObjectClicked(this);
}
}

4
Assets/Fungus/Scripts/Components/CommandCopyBuffer.cs

@ -62,8 +62,10 @@ namespace Fungus
public virtual void Clear()
{
foreach (Command command in GetCommands())
var commands = GetCommands();
for (int i = 0; i < commands.Length; i++)
{
var command = commands[i];
DestroyImmediate(command);
}
}

21
Assets/Fungus/Scripts/Components/DialogInput.cs

@ -46,6 +46,13 @@ namespace Fungus
protected StandaloneInputModule currentStandaloneInputModule;
protected Writer writer;
protected virtual void Awake()
{
writer = GetComponent<Writer>();
}
protected virtual void Update()
{
if (EventSystem.current == null)
@ -69,10 +76,13 @@ namespace Fungus
currentStandaloneInputModule = EventSystem.current.GetComponent<StandaloneInputModule>();
}
if (Input.GetButtonDown(currentStandaloneInputModule.submitButton) ||
(cancelEnabled && Input.GetButton(currentStandaloneInputModule.cancelButton)))
if (writer != null && writer.IsWriting)
{
SetNextLineFlag();
if (Input.GetButtonDown(currentStandaloneInputModule.submitButton) ||
(cancelEnabled && Input.GetButton(currentStandaloneInputModule.cancelButton)))
{
SetNextLineFlag();
}
}
switch (clickMode)
@ -114,9 +124,10 @@ namespace Fungus
// Tell any listeners to move to the next line
if (nextLineInputFlag)
{
IDialogInputListener[] inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>();
foreach (IDialogInputListener inputListener in inputListeners)
var inputListeners = gameObject.GetComponentsInChildren<IDialogInputListener>();
for (int i = 0; i < inputListeners.Length; i++)
{
var inputListener = inputListeners[i];
inputListener.OnNextLineEvent();
}
nextLineInputFlag = false;

30
Assets/Fungus/Scripts/Components/Draggable2D.cs

@ -58,13 +58,17 @@ namespace Fungus
return;
}
foreach (DragEntered handler in GetHandlers<DragEntered>())
var dragEnteredHandlers = GetHandlers<DragEntered>();
for (int i = 0; i < dragEnteredHandlers.Length; i++)
{
var handler = dragEnteredHandlers[i];
handler.OnDragEntered(this, other);
}
foreach (DragCompleted handler in GetHandlers<DragCompleted>())
var dragCompletedHandlers = GetHandlers<DragCompleted>();
for (int i = 0; i < dragCompletedHandlers.Length; i++)
{
var handler = dragCompletedHandlers[i];
handler.OnDragEntered(this, other);
}
}
@ -76,13 +80,17 @@ namespace Fungus
return;
}
foreach (DragExited handler in GetHandlers<DragExited>())
var dragExitedHandlers = GetHandlers<DragExited>();
for (int i = 0; i < dragExitedHandlers.Length; i++)
{
var handler = dragExitedHandlers[i];
handler.OnDragExited(this, other);
}
foreach (DragCompleted handler in GetHandlers<DragCompleted>())
var dragCompletedHandlers = GetHandlers<DragCompleted>();
for (int i = 0; i < dragCompletedHandlers.Length; i++)
{
var handler = dragCompletedHandlers[i];
handler.OnDragExited(this, other);
}
}
@ -103,8 +111,10 @@ namespace Fungus
startingPosition = transform.position;
foreach (DragStarted handler in GetHandlers<DragStarted>())
var dragStartedHandlers = GetHandlers<DragStarted>();
for (int i = 0; i < dragStartedHandlers.Length; i++)
{
var handler = dragStartedHandlers[i];
handler.OnDragStarted(this);
}
}
@ -134,16 +144,16 @@ namespace Fungus
bool dragCompleted = false;
DragCompleted[] handlers = GetHandlers<DragCompleted>();
foreach (DragCompleted handler in handlers)
var handlers = GetHandlers<DragCompleted>();
for (int i = 0; i < handlers.Length; i++)
{
var handler = handlers[i];
if (handler.DraggableObject == this)
{
if (handler.IsOverTarget())
{
handler.OnDragCompleted(this);
dragCompleted = true;
if (returnOnCompleted)
{
LeanTween.move(gameObject, startingPosition, returnDuration).setEase(LeanTweenType.easeOutExpo);
@ -154,8 +164,10 @@ namespace Fungus
if (!dragCompleted)
{
foreach (DragCancelled handler in GetHandlers<DragCancelled>())
var dragCancelledHandlers = GetHandlers<DragCancelled>();
for (int i = 0; i < dragCancelledHandlers.Length; i++)
{
var handler = dragCancelledHandlers[i];
handler.OnDragCancelled(this);
}

164
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -158,8 +158,10 @@ namespace Fungus
}
// Tell all components that implement IUpdateable to update to the new version
foreach (Component component in GetComponents<Component>())
var components = GetComponents<Component>();
for (int i = 0; i < components.Length; i++)
{
var component = components[i];
IUpdateable u = component as IUpdateable;
if (u != null)
{
@ -181,10 +183,10 @@ namespace Fungus
// This should always be the case, but some legacy Flowcharts may have issues.
List<int> usedIds = new List<int>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
if (block.ItemId == -1 ||
usedIds.Contains(block.ItemId))
var block = blocks[i];
if (block.ItemId == -1 || usedIds.Contains(block.ItemId))
{
block.ItemId = NextItemId();
}
@ -192,10 +194,10 @@ namespace Fungus
}
var commands = GetComponents<Command>();
foreach (var command in commands)
for (int i = 0; i < commands.Length; i++)
{
if (command.ItemId == -1 ||
usedIds.Contains(command.ItemId))
var command = commands[i];
if (command.ItemId == -1 || usedIds.Contains(command.ItemId))
{
command.ItemId = NextItemId();
}
@ -213,8 +215,10 @@ namespace Fungus
// It shouldn't happen but it seemed to occur for a user on the forum
variables.RemoveAll(item => item == null);
foreach (Variable variable in GetComponents<Variable>())
var allVariables = GetComponents<Variable>();
for (int i = 0; i < allVariables.Length; i++)
{
var variable = allVariables[i];
if (!variables.Contains(variable))
{
DestroyImmediate(variable);
@ -222,37 +226,40 @@ namespace Fungus
}
var blocks = GetComponents<Block>();
foreach (var command in GetComponents<Command>())
var commands = GetComponents<Command>();
for (int i = 0; i < commands.Length; i++)
{
var command = commands[i];
bool found = false;
foreach (var block in blocks)
for (int j = 0; j < blocks.Length; j++)
{
var block = blocks[j];
if (block.CommandList.Contains(command))
{
found = true;
break;
}
}
if (!found)
{
DestroyImmediate(command);
}
}
foreach (EventHandler eventHandler in GetComponents<EventHandler>())
var eventHandlers = GetComponents<EventHandler>();
for (int i = 0; i < eventHandlers.Length; i++)
{
var eventHandler = eventHandlers[i];
bool found = false;
foreach (var block in blocks)
for (int j = 0; j < blocks.Length; j++)
{
var block = blocks[j];
if (block._EventHandler == eventHandler)
{
found = true;
break;
}
}
if (!found)
{
DestroyImmediate(eventHandler);
@ -279,9 +286,10 @@ namespace Fungus
/// </summary>
public static void BroadcastFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
var eventHandlers = UnityEngine.Object.FindObjectsOfType<MessageReceived>();
for (int i = 0; i < eventHandlers.Length; i++)
{
var eventHandler = eventHandlers[i];
eventHandler.OnSendFungusMessage(messageName);
}
}
@ -406,14 +414,16 @@ namespace Fungus
{
int maxId = -1;
var blocks = GetComponents<Block>();
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
maxId = Math.Max(maxId, block.ItemId);
}
var commands = GetComponents<Command>();
foreach (var command in commands)
for (int i = 0; i < commands.Length; i++)
{
var command = commands[i];
maxId = Math.Max(maxId, command.ItemId);
}
return maxId + 1;
@ -438,8 +448,9 @@ namespace Fungus
public virtual Block FindBlock(string blockName)
{
var blocks = GetComponents<Block>();
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
if (block.BlockName == blockName)
{
return block;
@ -506,8 +517,9 @@ namespace Fungus
public virtual void StopAllBlocks()
{
var blocks = GetComponents<Block>();
foreach (Block block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
if (block.IsExecuting())
{
block.Stop();
@ -521,9 +533,10 @@ namespace Fungus
/// </summary>
public virtual void SendFungusMessage(string messageName)
{
MessageReceived[] eventHandlers = GetComponents<MessageReceived>();
foreach (MessageReceived eventHandler in eventHandlers)
var eventHandlers = GetComponents<MessageReceived>();
for (int i = 0; i < eventHandlers.Length; i++)
{
var eventHandler = eventHandlers[i];
eventHandler.OnSendFungusMessage(messageName);
}
}
@ -553,15 +566,13 @@ namespace Fungus
while (true)
{
bool collision = false;
foreach(Variable variable in variables)
for (int i = 0; i < variables.Count; i++)
{
if (variable == null ||
variable == ignoreVariable ||
variable.Key == null)
var variable = variables[i];
if (variable == null || variable == ignoreVariable || variable.Key == null)
{
continue;
}
if (variable.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{
collision = true;
@ -597,14 +608,13 @@ namespace Fungus
while (true)
{
bool collision = false;
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
if (block == ignoreBlock ||
block.BlockName == null)
var block = blocks[i];
if (block == ignoreBlock || block.BlockName == null)
{
continue;
}
if (block.BlockName.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{
collision = true;
@ -640,15 +650,15 @@ namespace Fungus
while (true)
{
bool collision = false;
foreach (var command in block.CommandList)
var commandList = block.CommandList;
for (int i = 0; i < commandList.Count; i++)
{
var command = commandList[i];
Label label = command as Label;
if (label == null ||
label == ignoreLabel)
if (label == null || label == ignoreLabel)
{
continue;
}
if (label.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase))
{
collision = true;
@ -673,8 +683,9 @@ namespace Fungus
/// </summary>
public Variable GetVariable(string key)
{
foreach (Variable variable in variables)
for (int i = 0; i < variables.Count; i++)
{
var variable = variables[i];
if (variable != null && variable.Key == key)
{
return variable;
@ -692,8 +703,9 @@ namespace Fungus
/// </summary>
public T GetVariable<T>(string key) where T : Variable
{
foreach (Variable variable in variables)
for (int i = 0; i < variables.Count; i++)
{
var variable = variables[i];
if (variable != null && variable.Key == key)
{
return variable as T;
@ -710,8 +722,9 @@ namespace Fungus
/// </summary>
public void SetVariable<T>(string key, T newvariable) where T : Variable
{
foreach (Variable v in variables)
for (int i = 0; i < variables.Count; i++)
{
var v = variables[i];
if (v != null && v.Key == key)
{
T variable = v as T;
@ -731,9 +744,10 @@ namespace Fungus
/// </summary>
public virtual List<Variable> GetPublicVariables()
{
List<Variable> publicVariables = new List<Variable>();
foreach (Variable v in variables)
var publicVariables = new List<Variable>();
for (int i = 0; i < variables.Count; i++)
{
var v = variables[i];
if (v != null && v.Scope == VariableScope.Public)
{
publicVariables.Add(v);
@ -874,9 +888,10 @@ namespace Fungus
{
if (hideComponents)
{
Block[] blocks = GetComponents<Block>();
foreach (Block block in blocks)
var blocks = GetComponents<Block>();
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
block.hideFlags = HideFlags.HideInInspector;
if (block.gameObject != gameObject)
{
@ -884,28 +899,30 @@ namespace Fungus
}
}
Command[] commands = GetComponents<Command>();
foreach (var command in commands)
var commands = GetComponents<Command>();
for (int i = 0; i < commands.Length; i++)
{
var command = commands[i];
command.hideFlags = HideFlags.HideInInspector;
}
EventHandler[] eventHandlers = GetComponents<EventHandler>();
foreach (var eventHandler in eventHandlers)
var eventHandlers = GetComponents<EventHandler>();
for (int i = 0; i < eventHandlers.Length; i++)
{
var eventHandler = eventHandlers[i];
eventHandler.hideFlags = HideFlags.HideInInspector;
}
}
else
{
MonoBehaviour[] monoBehaviours = GetComponents<MonoBehaviour>();
foreach (MonoBehaviour monoBehaviour in monoBehaviours)
var monoBehaviours = GetComponents<MonoBehaviour>();
for (int i = 0; i < monoBehaviours.Length; i++)
{
var monoBehaviour = monoBehaviours[i];
if (monoBehaviour == null)
{
continue;
}
monoBehaviour.hideFlags = HideFlags.None;
monoBehaviour.gameObject.hideFlags = HideFlags.None;
}
@ -939,16 +956,18 @@ namespace Fungus
if (resetCommands)
{
var commands = GetComponents<Command>();
foreach (var command in commands)
for (int i = 0; i < commands.Length; i++)
{
var command = commands[i];
command.OnReset();
}
}
if (resetVariables)
{
foreach (Variable variable in variables)
for (int i = 0; i < variables.Count; i++)
{
var variable = variables[i];
variable.OnReset();
}
}
@ -959,11 +978,11 @@ namespace Fungus
/// </summary>
public virtual bool IsCommandSupported(CommandInfoAttribute commandInfo)
{
foreach (string key in hideCommands)
for (int i = 0; i < hideCommands.Count; i++)
{
// Match on category or command name (case insensitive)
if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 ||
String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0)
var key = hideCommands[i];
if (String.Compare(commandInfo.Category, key, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(commandInfo.CommandName, key, StringComparison.OrdinalIgnoreCase) == 0)
{
return false;
}
@ -978,8 +997,9 @@ namespace Fungus
public virtual bool HasExecutingBlocks()
{
var blocks = GetComponents<Block>();
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
if (block.IsExecuting())
{
return true;
@ -995,8 +1015,9 @@ namespace Fungus
{
var executingBlocks = new List<Block>();
var blocks = GetComponents<Block>();
foreach (var block in blocks)
for (int i = 0; i < blocks.Length; i++)
{
var block = blocks[i];
if (block.IsExecuting())
{
executingBlocks.Add(block);
@ -1032,19 +1053,18 @@ namespace Fungus
// Match the regular expression pattern against a text string.
var results = r.Matches(input);
foreach (Match match in results)
for (int i = 0; i < results.Count; i++)
{
Match match = results[i];
string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching private variables in this Flowchart first
foreach (Variable variable in variables)
for (int j = 0; j < variables.Count; j++)
{
var variable = variables[j];
if (variable == null)
continue;
if (variable.Scope == VariableScope.Private &&
variable.Key == key)
{
if (variable.Scope == VariableScope.Private && variable.Key == key)
{
string value = variable.ToString();
sb.Replace(match.Value, value);
changed = true;
@ -1084,22 +1104,22 @@ namespace Fungus
// Match the regular expression pattern against a text string.
var results = r.Matches(input.ToString());
foreach (Match match in results)
for (int i = 0; i < results.Count; i++)
{
Match match = results[i];
string key = match.Value.Substring(2, match.Value.Length - 3);
// Look for any matching public variables in this Flowchart
foreach (Variable variable in variables)
for (int j = 0; j < variables.Count; j++)
{
var variable = variables[j];
if (variable == null)
{
continue;
if (variable.Scope == VariableScope.Public &&
variable.Key == key)
{
}
if (variable.Scope == VariableScope.Public && variable.Key == key)
{
string value = variable.ToString();
input.Replace(match.Value, value);
modified = true;
}
}

45
Assets/Fungus/Scripts/Components/Localization.cs

@ -96,8 +96,9 @@ namespace Fungus
protected virtual void CacheLocalizeableObjects()
{
UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (UnityEngine.Object o in objects)
for (int i = 0; i < objects.Length; i++)
{
var o = objects[i];
ILocalizable localizable = o as ILocalizable;
if (localizable != null)
{
@ -116,13 +117,18 @@ namespace Fungus
// Add localizable commands in same order as command list to make it
// easier to localise / edit standard text.
var flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (var flowchart in flowcharts)
for (int i = 0; i < flowcharts.Length; i++)
{
var flowchart = flowcharts[i];
var blocks = flowchart.GetComponents<Block>();
foreach (var block in blocks)
for (int j = 0; j < blocks.Length; j++)
{
foreach (var command in block.CommandList)
var block = blocks[j];
var commandList = block.CommandList;
for (int k = 0; k < commandList.Count; k++)
{
var command = commandList[k];
ILocalizable localizable = command as ILocalizable;
if (localizable != null)
{
@ -137,8 +143,9 @@ namespace Fungus
// Add everything else that's localizable (including inactive objects)
UnityEngine.Object[] objects = Resources.FindObjectsOfTypeAll(typeof(Component));
foreach (UnityEngine.Object o in objects)
for (int i = 0; i < objects.Length; i++)
{
var o = objects[i];
ILocalizable localizable = o as ILocalizable;
if (localizable != null)
{
@ -148,7 +155,6 @@ namespace Fungus
// Already added
continue;
}
TextItem textItem = new TextItem();
textItem.standardText = localizable.GetStandardText();
textItem.description = localizable.GetDescription();
@ -288,8 +294,9 @@ namespace Fungus
// Build CSV header row and a list of the language codes currently in use
string csvHeader = "Key,Description,Standard";
List<string> languageCodes = new List<string>();
foreach (TextItem textItem in textItems.Values)
var languageCodes = new List<string>();
var values = textItems.Values;
foreach (var textItem in values)
{
foreach (string languageCode in textItem.localizedStrings.Keys)
{
@ -304,7 +311,8 @@ namespace Fungus
// Build the CSV file using collected text items
int rowCount = 0;
string csvData = csvHeader + "\n";
foreach (string stringId in textItems.Keys)
var keys = textItems.Keys;
foreach (var stringId in keys)
{
TextItem textItem = textItems[stringId];
@ -312,15 +320,17 @@ namespace Fungus
row += "," + CSVSupport.Escape(textItem.description);
row += "," + CSVSupport.Escape(textItem.standardText);
foreach (string languageCode in languageCodes)
for (int i = 0; i < languageCodes.Count; i++)
{
var languageCode = languageCodes[i];
if (textItem.localizedStrings.ContainsKey(languageCode))
{
row += "," + CSVSupport.Escape(textItem.localizedStrings[languageCode]);
}
else
{
row += ","; // Empty field
row += ",";
// Empty field
}
}
@ -462,7 +472,8 @@ namespace Fungus
string textData = "";
int rowCount = 0;
foreach (string stringId in textItems.Keys)
var keys = textItems.Keys;
foreach (var stringId in keys)
{
TextItem languageItem = textItems[stringId];
@ -481,15 +492,16 @@ namespace Fungus
/// </summary>
public virtual void SetStandardText(string textData)
{
string[] lines = textData.Split('\n');
var lines = textData.Split('\n');
int updatedCount = 0;
string stringId = "";
string buffer = "";
foreach (string line in lines)
for (int i = 0; i < lines.Length; i++)
{
// Check for string id line
var line = lines[i];
if (line.StartsWith("#"))
{
if (stringId.Length > 0)
@ -500,7 +512,6 @@ namespace Fungus
updatedCount++;
}
}
// Set the string id for the follow text lines
stringId = line.Substring(1, line.Length - 1);
buffer = "";
@ -540,10 +551,10 @@ namespace Fungus
// Match the regular expression pattern against a text string.
var results = r.Matches(input.ToString());
foreach (Match match in results)
for (int i = 0; i < results.Count; i++)
{
Match match = results[i];
string key = match.Value.Substring(2, match.Value.Length - 3);
// Next look for matching localized string
string localizedString = Localization.GetLocalizedString(key);
if (localizedString != null)

53
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -154,14 +154,16 @@ namespace Fungus
{
StopAllCoroutines();
Button[] optionButtons = GetComponentsInChildren<Button>();
foreach (UnityEngine.UI.Button button in optionButtons)
var optionButtons = GetComponentsInChildren<Button>();
for (int i = 0; i < optionButtons.Length; i++)
{
var button = optionButtons[i];
button.onClick.RemoveAllListeners();
}
foreach (UnityEngine.UI.Button button in optionButtons)
for (int i = 0; i < optionButtons.Length; i++)
{
var button = optionButtons[i];
if (button != null)
{
button.gameObject.SetActive(false);
@ -198,53 +200,43 @@ namespace Fungus
public virtual bool AddOption(string text, bool interactable, Block targetBlock)
{
bool addedOption = false;
foreach (Button button in cachedButtons)
for (int i = 0; i < cachedButtons.Length; i++)
{
var button = cachedButtons[i];
if (!button.gameObject.activeSelf)
{
button.gameObject.SetActive(true);
button.interactable = interactable;
if (interactable && autoSelectFirstButton && !cachedButtons.Select((x) => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject))
{
EventSystem.current.SetSelectedGameObject(button.gameObject);
}
Text textComponent = button.GetComponentInChildren<Text>();
if (textComponent != null)
{
textComponent.text = text;
}
var block = targetBlock;
button.onClick.AddListener(delegate {
button.onClick.AddListener(delegate
{
EventSystem.current.SetSelectedGameObject(null);
StopAllCoroutines(); // Stop timeout
StopAllCoroutines();
// Stop timeout
Clear();
HideSayDialog();
if (block != null)
{
var flowchart = block.GetFlowchart();
#if UNITY_EDITOR
// Select the new target block in the Flowchart window
flowchart.SelectedBlock = block;
#endif
gameObject.SetActive(false);
// Use a coroutine to call the block on the next frame
// Have to use the Flowchart gameobject as the MenuDialog is now inactive
flowchart.StartCoroutine(CallBlock(block));
}
});
addedOption = true;
break;
}
@ -266,15 +258,14 @@ namespace Fungus
}
bool addedOption = false;
foreach (Button button in CachedButtons)
for (int i = 0; i < CachedButtons.Length; i++)
{
var button = CachedButtons[i];
if (!button.gameObject.activeSelf)
{
button.gameObject.SetActive(true);
button.interactable = interactable;
Text textComponent = button.GetComponentInChildren<Text>();
var textComponent = button.GetComponentInChildren<Text>();
if (textComponent != null)
{
textComponent.text = text;
@ -283,17 +274,16 @@ namespace Fungus
// Copy to local variables
LuaEnvironment env = luaEnv;
Closure call = callBack;
button.onClick.AddListener(delegate {
StopAllCoroutines(); // Stop timeout
button.onClick.AddListener(delegate
{
StopAllCoroutines();
// Stop timeout
Clear();
HideSayDialog();
// Use a coroutine to call the callback on the next frame
StartCoroutine(CallLuaClosure(env, call));
});
addedOption = true;
break;
}
@ -373,8 +363,9 @@ namespace Fungus
{
get {
int count = 0;
foreach (Button button in cachedButtons)
for (int i = 0; i < cachedButtons.Length; i++)
{
var button = cachedButtons[i];
if (button.gameObject.activeSelf)
{
count++;

14
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -226,14 +226,15 @@ namespace Fungus
public static void StopPortraitTweens()
{
// Stop all tweening portraits
foreach( Character c in Character.ActiveCharacters )
var activeCharacters = Character.ActiveCharacters;
for (int i = 0; i < activeCharacters.Count; i++)
{
var c = activeCharacters[i];
if (c.State.portraitImage != null)
{
if (LeanTween.isTweening(c.State.portraitImage.gameObject))
{
LeanTween.cancel(c.State.portraitImage.gameObject, true);
PortraitController.SetRectTransform(c.State.portraitImage.rectTransform, c.State.position);
if (c.State.dimmed == true)
{
@ -281,13 +282,16 @@ namespace Fungus
speakingCharacter = character;
// Dim portraits of non-speaking characters
foreach (Stage stage in Stage.ActiveStages)
var activeStages = Stage.ActiveStages;
for (int i = 0; i < activeStages.Count; i++)
{
var stage = activeStages[i];
if (stage.DimPortraits)
{
foreach (var c in stage.CharactersOnStage)
var charactersOnStage = stage.CharactersOnStage;
for (int j = 0; j < charactersOnStage.Count; j++)
{
var c = charactersOnStage[j];
if (prevSpeakingCharacter != speakingCharacter)
{
if (c != null && !c.Equals(speakingCharacter))

10
Assets/Fungus/Scripts/Components/SpriteFader.cs

@ -77,15 +77,15 @@ namespace Fungus
}
// Fade child sprite renderers
SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer child in children)
var spriteRenderers = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
for (int i = 0; i < spriteRenderers.Length; i++)
{
if (child == spriteRenderer)
var sr = spriteRenderers[i];
if (sr == spriteRenderer)
{
continue;
}
FadeSprite(child, targetColor, duration, slideOffset);
FadeSprite(sr, targetColor, duration, slideOffset);
}
// Destroy any existing fader component

26
Assets/Fungus/Scripts/Components/Writer.cs

@ -106,8 +106,10 @@ namespace Fungus
// Try to find any component with a text property
if (textUI == null && inputField == null && textMesh == null)
{
foreach (Component c in go.GetComponents<Component>())
var allcomponents = go.GetComponents<Component>();
for (int i = 0; i < allcomponents.Length; i++)
{
var c = allcomponents[i];
textProperty = c.GetType().GetProperty("text");
if (textProperty != null)
{
@ -118,8 +120,10 @@ namespace Fungus
}
// Cache the list of child writer listeners
foreach (Component component in GetComponentsInChildren<Component>())
var allComponents = GetComponentsInChildren<Component>();
for (int i = 0; i < allComponents.Length; i++)
{
var component = allComponents[i];
IWriterListener writerListener = component as IWriterListener;
if (writerListener != null)
{
@ -688,8 +692,9 @@ namespace Fungus
{
WriterSignals.DoWriterInput(this);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnInput();
}
}
@ -698,8 +703,9 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Start);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnStart(audioClip);
}
}
@ -708,8 +714,9 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Pause);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnPause();
}
}
@ -718,8 +725,9 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.Resume);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnResume();
}
}
@ -728,8 +736,9 @@ namespace Fungus
{
WriterSignals.DoWriterState(this, WriterState.End);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnEnd(stopAudio);
}
}
@ -738,8 +747,9 @@ namespace Fungus
{
WriterSignals.DoWriterGlyph(this);
foreach (IWriterListener writerListener in writerListeners)
for (int i = 0; i < writerListeners.Count; i++)
{
var writerListener = writerListeners[i];
writerListener.OnGlyph();
}
}

2
Assets/Fungus/Scripts/Editor/EventHandlerEditor.cs

@ -15,7 +15,7 @@ namespace Fungus.EditorUtils
public static EventHandlerInfoAttribute GetEventHandlerInfo(System.Type eventHandlerType)
{
object[] attributes = eventHandlerType.GetCustomAttributes(typeof(EventHandlerInfoAttribute), false);
foreach (object obj in attributes)
foreach (var obj in attributes)
{
EventHandlerInfoAttribute eventHandlerInfoAttr = obj as EventHandlerInfoAttribute;
if (eventHandlerInfoAttr != null)

4
Assets/Fungus/Scripts/Editor/FlowchartEditor.cs

@ -188,7 +188,7 @@ namespace Fungus.EditorUtils
List<System.Type> types = FindAllDerivedTypes<Variable>();
// Add variable types without a category
foreach (System.Type type in types)
foreach (var type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||
@ -207,7 +207,7 @@ namespace Fungus.EditorUtils
}
// Add types with a category
foreach (System.Type type in types)
foreach (var type in types)
{
VariableInfoAttribute variableInfo = VariableEditor.GetVariableInfo(type);
if (variableInfo == null ||

25
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -121,7 +121,8 @@ namespace Fungus.EditorUtils
{
bool isSelected = (flowchart.SelectedBlock == deleteBlock);
foreach (Command command in deleteBlock.CommandList)
var commandList = deleteBlock.CommandList;
foreach (var command in commandList)
{
Undo.DestroyObjectImmediate(command);
}
@ -552,7 +553,8 @@ namespace Fungus.EditorUtils
protected virtual void DeleteBlock(Flowchart flowchart, Block block)
{
foreach (var command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
Undo.DestroyObjectImmediate(command);
}
@ -614,7 +616,7 @@ namespace Fungus.EditorUtils
// Count the number of unique connections (excluding self references)
var uniqueList = new List<Block>();
var connectedBlocks = block.GetConnectedBlocks();
foreach (Block connectedBlock in connectedBlocks)
foreach (var connectedBlock in connectedBlocks)
{
if (connectedBlock == block ||
uniqueList.Contains(connectedBlock))
@ -675,7 +677,8 @@ namespace Fungus.EditorUtils
bool blockIsSelected = (flowchart.SelectedBlock != block);
foreach (Command command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
if (command == null)
{
@ -683,7 +686,8 @@ namespace Fungus.EditorUtils
}
bool commandIsSelected = false;
foreach (Command selectedCommand in flowchart.SelectedCommands)
var selectedCommands = flowchart.SelectedCommands;
foreach (var selectedCommand in selectedCommands)
{
if (selectedCommand == command)
{
@ -703,7 +707,7 @@ namespace Fungus.EditorUtils
connectedBlocks.Clear();
command.GetConnectedBlocks(ref connectedBlocks);
foreach (Block blockB in connectedBlocks)
foreach (var blockB in connectedBlocks)
{
if (blockB == null ||
block == blockB ||
@ -745,9 +749,9 @@ namespace Fungus.EditorUtils
Vector2 pointB = Vector2.zero;
float minDist = float.MaxValue;
foreach (Vector2 a in pointsA)
foreach (var a in pointsA)
{
foreach (Vector2 b in pointsB)
foreach (var b in pointsB)
{
float d = Vector2.Distance(a, b);
if (d < minDist)
@ -796,7 +800,8 @@ namespace Fungus.EditorUtils
Undo.RecordObject(newBlock, "Duplicate Block");
foreach (Command command in oldBlock.CommandList)
var commandList = oldBlock.CommandList;
foreach (var command in commandList)
{
if (ComponentUtility.CopyComponent(command))
{
@ -807,7 +812,7 @@ namespace Fungus.EditorUtils
if (pastedCommand != null)
{
pastedCommand.ItemId = flowchart.NextItemId();
newBlock.CommandList.Add (pastedCommand);
newBlock.CommandList.Add(pastedCommand);
}
}

3
Assets/Fungus/Scripts/Editor/LabelEditor.cs

@ -26,7 +26,8 @@ namespace Fungus.EditorUtils
int index = 0;
int selectedIndex = 0;
foreach (Command command in block.CommandList)
var commandList = block.CommandList;
foreach (var command in commandList)
{
Label label = command as Label;
if (label == null)

3
Assets/Fungus/Scripts/Editor/ViewEditor.cs

@ -171,7 +171,8 @@ namespace Fungus.EditorUtils
var flowchart = FlowchartWindow.GetFlowchart();
if (flowchart != null)
{
foreach (Command command in flowchart.SelectedCommands)
var selectedCommands = flowchart.SelectedCommands;
foreach (var command in selectedCommands)
{
MoveToView moveToViewCommand = command as MoveToView;
if (moveToViewCommand != null &&

13
Assets/Fungus/Scripts/Utils/TextTagParser.cs

@ -180,8 +180,9 @@ namespace Fungus
string paramsStr = input.Substring(index + 1);
var splits = paramsStr.Split(',');
foreach (var p in splits)
for (int i = 0; i < splits.Length; i++)
{
var p = splits[i];
paramsList.Add(p.Trim());
}
return paramsList;
@ -264,16 +265,14 @@ namespace Fungus
// These characters are usually added for legibility when editing, but are not
// desireable when viewing the text in game.
bool trimLeading = false;
foreach (TextTagToken token in tokens)
for (int i = 0; i < tokens.Count; i++)
{
if (trimLeading &&
token.type == TokenType.Words)
var token = tokens[i];
if (trimLeading && token.type == TokenType.Words)
{
token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n');
}
if (token.type == TokenType.Clear ||
token.type == TokenType.WaitForInputAndClear)
if (token.type == TokenType.Clear || token.type == TokenType.WaitForInputAndClear)
{
trimLeading = true;
}

Loading…
Cancel
Save